From d5efbc5304defaf4fbb0a510f4f422b429a0cb9e Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Fri, 4 Apr 2025 09:31:11 +0000 Subject: [PATCH] Updating based on 58329c4db --- .../advisor/2025-01-01/advisorscore/README.md | 53 + .../advisor/2025-01-01/advisorscore/client.go | 26 + .../2025-01-01/advisorscore/constants.go | 54 + .../advisorscore/id_advisorscore.go | 121 ++ .../advisorscore/id_advisorscore_test.go | 237 +++ .../2025-01-01/advisorscore/method_get.go | 53 + .../2025-01-01/advisorscore/method_list.go | 55 + .../advisorscore/model_advisorscoreentity.go | 16 + .../model_advisorscoreentityproperties.go | 9 + .../model_advisorscoreresponse.go | 8 + .../advisorscore/model_scoreentity.go | 13 + ...model_timeseriesentitytimeseriesinlined.go | 9 + .../2025-01-01/advisorscore/version.go | 10 + resource-manager/advisor/2025-01-01/client.go | 82 + .../2025-01-01/configurations/README.md | 97 ++ .../2025-01-01/configurations/client.go | 26 + .../2025-01-01/configurations/constants.go | 201 +++ .../method_createinresourcegroup.go | 59 + .../method_createinsubscription.go | 59 + .../method_listbyresourcegroup.go | 106 ++ .../method_listbysubscription.go | 106 ++ .../configurations/model_configdata.go | 16 + .../model_configdataproperties.go | 11 + .../configurations/model_digestconfig.go | 13 + .../2025-01-01/configurations/predicates.go | 27 + .../2025-01-01/configurations/version.go | 10 + .../generaterecommendations/client.go | 26 + .../id_generaterecommendation.go | 121 ++ .../id_generaterecommendation_test.go | 237 +++ .../method_recommendationsgenerate.go | 48 + ...method_recommendationsgetgeneratestatus.go | 47 + .../generaterecommendations/version.go | 10 + .../2025-01-01/getrecommendations/README.md | 54 + .../2025-01-01/getrecommendations/client.go | 26 + .../getrecommendations/constants.go | 210 +++ .../id_scopedrecommendation.go | 120 ++ .../id_scopedrecommendation_test.go | 222 +++ .../method_recommendationsget.go | 53 + .../method_recommendationslist.go | 139 ++ .../model_recommendationproperties.go | 45 + .../model_resourcemetadata.go | 12 + .../model_resourcerecommendationbase.go | 16 + .../model_shortdescription.go | 9 + .../getrecommendations/predicates.go | 27 + .../2025-01-01/getrecommendations/version.go | 10 + .../advisor/2025-01-01/metadata/README.md | 53 + .../advisor/2025-01-01/metadata/client.go | 26 + .../advisor/2025-01-01/metadata/constants.go | 48 + .../2025-01-01/metadata/id_metadata.go | 112 ++ .../2025-01-01/metadata/id_metadata_test.go | 192 +++ .../method_recommendationmetadataget.go | 53 + .../method_recommendationmetadatalist.go | 134 ++ .../metadata/model_metadataentity.go | 11 + .../model_metadataentityproperties.go | 11 + .../model_metadatasupportedvaluedetail.go | 9 + .../advisor/2025-01-01/metadata/predicates.go | 27 + .../advisor/2025-01-01/metadata/version.go | 10 + .../advisor/2025-01-01/prediction/README.md | 42 + .../advisor/2025-01-01/prediction/client.go | 26 + .../2025-01-01/prediction/constants.go | 142 ++ .../2025-01-01/prediction/method_predict.go | 59 + .../prediction/model_predictionrequest.go | 8 + .../model_predictionrequestproperties.go | 9 + .../prediction/model_predictionresponse.go | 8 + .../model_predictionresponseproperties.go | 32 + .../prediction/model_shortdescription.go | 9 + .../advisor/2025-01-01/prediction/version.go | 10 + .../advisor/2025-01-01/suppressions/README.md | 91 + .../advisor/2025-01-01/suppressions/client.go | 26 + .../suppressions/id_scopedsuppression.go | 129 ++ .../suppressions/id_scopedsuppression_test.go | 267 +++ .../2025-01-01/suppressions/method_create.go | 57 + .../2025-01-01/suppressions/method_delete.go | 46 + .../2025-01-01/suppressions/method_get.go | 53 + .../2025-01-01/suppressions/method_list.go | 135 ++ .../suppressions/model_suppressioncontract.go | 16 + .../model_suppressionproperties.go | 28 + .../2025-01-01/suppressions/predicates.go | 27 + .../2025-01-01/suppressions/version.go | 10 + .../availableworkloadprofiles/README.md | 37 + .../availableworkloadprofiles/client.go | 26 + .../availableworkloadprofiles/constants.go | 51 + .../availableworkloadprofiles/id_location.go | 121 ++ .../id_location_test.go | 237 +++ .../availableworkloadprofiles/method_get.go | 105 ++ .../model_availableworkloadprofile.go | 17 + ...odel_availableworkloadprofileproperties.go | 13 + .../availableworkloadprofiles/predicates.go | 32 + .../availableworkloadprofiles/version.go | 10 + .../2025-01-01/billingmeters/README.md | 36 + .../2025-01-01/billingmeters/client.go | 26 + .../2025-01-01/billingmeters/id_location.go | 121 ++ .../billingmeters/id_location_test.go | 237 +++ .../2025-01-01/billingmeters/method_get.go | 54 + .../billingmeters/model_billingmeter.go | 17 + .../model_billingmetercollection.go | 8 + .../model_billingmeterproperties.go | 10 + .../2025-01-01/billingmeters/version.go | 10 + .../2025-01-01/certificates/README.md | 202 +++ .../2025-01-01/certificates/client.go | 26 + .../2025-01-01/certificates/constants.go | 60 + .../2025-01-01/certificates/id_certificate.go | 139 ++ .../certificates/id_certificate_test.go | 327 ++++ .../certificates/id_connectedenvironment.go | 130 ++ .../id_connectedenvironment_test.go | 282 ++++ .../id_connectedenvironmentcertificate.go | 139 ++ ...id_connectedenvironmentcertificate_test.go | 327 ++++ .../certificates/id_managedenvironment.go | 130 ++ .../id_managedenvironment_test.go | 282 ++++ ...denvironmentscertificatescreateorupdate.go | 57 + ...connectedenvironmentscertificatesdelete.go | 47 + ...od_connectedenvironmentscertificatesget.go | 53 + ...d_connectedenvironmentscertificateslist.go | 105 ++ ...connectedenvironmentscertificatesupdate.go | 57 + .../certificates/method_createorupdate.go | 57 + .../2025-01-01/certificates/method_delete.go | 47 + .../2025-01-01/certificates/method_get.go | 53 + .../2025-01-01/certificates/method_list.go | 105 ++ .../2025-01-01/certificates/method_update.go | 57 + .../certificates/model_certificate.go | 18 + .../model_certificatekeyvaultproperties.go | 9 + .../certificates/model_certificatepatch.go | 8 + .../model_certificateproperties.go | 49 + .../2025-01-01/certificates/predicates.go | 32 + .../2025-01-01/certificates/version.go | 10 + .../containerapps/2025-01-01/client.go | 199 +++ .../connectedenvironments/README.md | 228 +++ .../connectedenvironments/client.go | 26 + .../connectedenvironments/constants.go | 198 +++ .../id_connectedenvironment.go | 130 ++ .../id_connectedenvironment_test.go | 282 ++++ .../id_connectedenvironmentcertificate.go | 139 ++ ...id_connectedenvironmentcertificate_test.go | 327 ++++ .../method_certificatescreateorupdate.go | 57 + .../method_certificatesdelete.go | 47 + .../method_certificatesget.go | 53 + .../method_certificateslist.go | 105 ++ .../method_certificatesupdate.go | 57 + .../method_checknameavailability.go | 58 + .../method_createorupdate.go | 75 + .../connectedenvironments/method_delete.go | 71 + .../connectedenvironments/method_get.go | 53 + .../method_listbyresourcegroup.go | 106 ++ .../method_listbysubscription.go | 106 ++ .../connectedenvironments/method_update.go | 53 + .../model_certificate.go | 18 + .../model_certificatekeyvaultproperties.go | 9 + .../model_certificatepatch.go | 8 + .../model_certificateproperties.go | 49 + .../model_checknameavailabilityrequest.go | 9 + .../model_checknameavailabilityresponse.go | 10 + .../model_connectedenvironment.go | 19 + .../model_connectedenvironmentproperties.go | 13 + .../model_customdomainconfiguration.go | 33 + .../model_extendedlocation.go | 9 + .../connectedenvironments/predicates.go | 60 + .../connectedenvironments/version.go | 10 + .../connectedenvironmentsstorages/README.md | 89 + .../connectedenvironmentsstorages/client.go | 26 + .../constants.go | 51 + .../id_connectedenvironment.go | 130 ++ .../id_connectedenvironment_test.go | 282 ++++ .../id_connectedenvironmentstorage.go | 139 ++ .../id_connectedenvironmentstorage_test.go | 327 ++++ .../method_createorupdate.go | 57 + .../method_delete.go | 47 + .../method_get.go | 53 + .../method_list.go | 54 + .../model_azurefileproperties.go | 11 + .../model_connectedenvironmentstorage.go | 16 + ...l_connectedenvironmentstorageproperties.go | 8 + ..._connectedenvironmentstoragescollection.go | 8 + .../connectedenvironmentsstorages/version.go | 10 + .../2025-01-01/containerapps/README.md | 271 +++ .../2025-01-01/containerapps/client.go | 26 + .../2025-01-01/containerapps/constants.go | 861 ++++++++++ .../containerapps/id_containerapp.go | 130 ++ .../containerapps/id_containerapp_test.go | 282 ++++ .../containerapps/id_containerappdetector.go | 139 ++ .../id_containerappdetector_test.go | 327 ++++ .../containerapps/id_revisionsapirevision.go | 141 ++ .../id_revisionsapirevision_test.go | 357 ++++ .../containerapps/method_createorupdate.go | 75 + .../2025-01-01/containerapps/method_delete.go | 71 + .../method_diagnosticsgetdetector.go | 53 + .../method_diagnosticsgetrevision.go | 53 + .../method_diagnosticsgetroot.go | 54 + .../method_diagnosticslistdetectors.go | 105 ++ .../method_diagnosticslistrevisions.go | 134 ++ .../2025-01-01/containerapps/method_get.go | 53 + .../containerapps/method_getauthtoken.go | 54 + .../method_listbyresourcegroup.go | 106 ++ .../method_listbysubscription.go | 106 ++ .../method_listcustomhostnameanalysis.go | 83 + .../containerapps/method_listsecrets.go | 54 + .../2025-01-01/containerapps/method_start.go | 71 + .../2025-01-01/containerapps/method_stop.go | 71 + .../2025-01-01/containerapps/method_update.go | 75 + .../containerapps/model_basecontainer.go | 14 + .../containerapps/model_configuration.go | 16 + .../containerapps/model_container.go | 15 + .../containerapps/model_containerapp.go | 22 + .../model_containerappauthtoken.go | 18 + .../model_containerappauthtokenproperties.go | 27 + .../containerapps/model_containerappprobe.go | 16 + .../model_containerappprobehttpget.go | 12 + ...tainerappprobehttpgethttpheadersinlined.go | 9 + .../model_containerappprobetcpsocket.go | 9 + .../model_containerappproperties.go | 20 + .../containerapps/model_containerappsecret.go | 11 + .../containerapps/model_containerresources.go | 10 + .../containerapps/model_corspolicy.go | 13 + .../containerapps/model_customdomain.go | 10 + .../model_customhostnameanalysisresult.go | 19 + ...sultcustomdomainverificationfailureinfo.go | 11 + ...inverificationfailureinfodetailsinlined.go | 10 + .../containerapps/model_customscalerule.go | 11 + .../2025-01-01/containerapps/model_dapr.go | 15 + .../model_diagnosticdataprovidermetadata.go | 9 + ...cdataprovidermetadatapropertybaginlined.go | 9 + ...model_diagnosticdatatableresponsecolumn.go | 10 + ...model_diagnosticdatatableresponseobject.go | 10 + .../model_diagnosticrendering.go | 11 + .../containerapps/model_diagnostics.go | 16 + .../model_diagnosticsdataapiresponse.go | 9 + .../model_diagnosticsdefinition.go | 16 + .../model_diagnosticsproperties.go | 11 + .../containerapps/model_diagnosticsstatus.go | 9 + .../model_diagnosticsupporttopic.go | 9 + .../containerapps/model_environmentvar.go | 10 + .../containerapps/model_extendedlocation.go | 9 + .../containerapps/model_httpscalerule.go | 10 + .../containerapps/model_identitysettings.go | 9 + .../2025-01-01/containerapps/model_ingress.go | 20 + .../containerapps/model_ingressportmapping.go | 10 + .../model_ingressstickysessions.go | 8 + .../model_ipsecurityrestrictionrule.go | 11 + .../containerapps/model_queuescalerule.go | 12 + .../model_registrycredentials.go | 11 + .../containerapps/model_revision.go | 16 + .../containerapps/model_revisionproperties.go | 48 + .../2025-01-01/containerapps/model_runtime.go | 8 + .../containerapps/model_runtimejava.go | 8 + .../2025-01-01/containerapps/model_scale.go | 12 + .../containerapps/model_scalerule.go | 12 + .../containerapps/model_scaleruleauth.go | 9 + .../2025-01-01/containerapps/model_secret.go | 11 + .../containerapps/model_secretscollection.go | 8 + .../containerapps/model_secretvolumeitem.go | 9 + .../2025-01-01/containerapps/model_service.go | 8 + .../containerapps/model_servicebind.go | 9 + .../containerapps/model_tcpscalerule.go | 10 + .../containerapps/model_template.go | 14 + .../containerapps/model_trafficweight.go | 11 + .../2025-01-01/containerapps/model_volume.go | 12 + .../containerapps/model_volumemount.go | 10 + .../2025-01-01/containerapps/predicates.go | 83 + .../2025-01-01/containerapps/version.go | 10 + .../containerappsauthconfigs/README.md | 90 + .../containerappsauthconfigs/client.go | 26 + .../containerappsauthconfigs/constants.go | 180 ++ .../containerappsauthconfigs/id_authconfig.go | 139 ++ .../id_authconfig_test.go | 327 ++++ .../id_containerapp.go | 130 ++ .../id_containerapp_test.go | 282 ++++ .../method_createorupdate.go | 57 + .../containerappsauthconfigs/method_delete.go | 47 + .../containerappsauthconfigs/method_get.go | 53 + .../method_listbycontainerapp.go | 105 ++ .../model_allowedaudiencesvalidation.go | 8 + .../model_allowedprincipals.go | 9 + .../containerappsauthconfigs/model_apple.go | 10 + .../model_appleregistration.go | 9 + .../model_appregistration.go | 9 + .../model_authconfig.go | 16 + .../model_authconfigproperties.go | 13 + .../model_authplatform.go | 9 + .../model_azureactivedirectory.go | 12 + .../model_azureactivedirectorylogin.go | 9 + .../model_azureactivedirectoryregistration.go | 13 + .../model_azureactivedirectoryvalidation.go | 10 + .../model_azurestaticwebapps.go | 9 + .../model_azurestaticwebappsregistration.go | 8 + .../model_blobstoragetokenstore.go | 8 + .../model_clientregistration.go | 9 + .../model_cookieexpiration.go | 9 + .../model_customopenidconnectprovider.go | 10 + .../model_defaultauthorizationpolicy.go | 9 + .../model_encryptionsettings.go | 9 + .../model_facebook.go | 11 + .../model_forwardproxy.go | 10 + .../containerappsauthconfigs/model_github.go | 10 + .../model_globalvalidation.go | 10 + .../containerappsauthconfigs/model_google.go | 11 + .../model_httpsettings.go | 10 + .../model_httpsettingsroutes.go | 8 + .../model_identityproviders.go | 15 + .../model_jwtclaimchecks.go | 9 + .../containerappsauthconfigs/model_login.go | 13 + .../model_loginroutes.go | 8 + .../model_loginscopes.go | 8 + .../containerappsauthconfigs/model_nonce.go | 9 + .../model_openidconnectclientcredential.go | 9 + .../model_openidconnectconfig.go | 12 + .../model_openidconnectlogin.go | 9 + .../model_openidconnectregistration.go | 10 + .../model_tokenstore.go | 10 + .../containerappsauthconfigs/model_twitter.go | 9 + .../model_twitterregistration.go | 9 + .../containerappsauthconfigs/predicates.go | 27 + .../containerappsauthconfigs/version.go | 10 + .../containerappsrevisionreplicas/README.md | 52 + .../containerappsrevisionreplicas/client.go | 26 + .../constants.go | 98 ++ .../id_replica.go | 148 ++ .../id_replica_test.go | 372 +++++ .../id_revision.go | 139 ++ .../id_revision_test.go | 327 ++++ .../method_getreplica.go | 53 + .../method_listreplicas.go | 54 + .../model_replica.go | 16 + .../model_replicacollection.go | 8 + .../model_replicacontainer.go | 16 + .../model_replicaproperties.go | 30 + .../containerappsrevisionreplicas/version.go | 10 + .../containerappsrevisions/README.md | 101 ++ .../containerappsrevisions/client.go | 26 + .../containerappsrevisions/constants.go | 289 ++++ .../containerappsrevisions/id_containerapp.go | 130 ++ .../id_containerapp_test.go | 282 ++++ .../containerappsrevisions/id_revision.go | 139 ++ .../id_revision_test.go | 327 ++++ .../method_activaterevision.go | 47 + .../method_deactivaterevision.go | 47 + .../method_getrevision.go | 53 + .../method_listrevisions.go | 134 ++ .../method_restartrevision.go | 47 + .../model_basecontainer.go | 14 + .../containerappsrevisions/model_container.go | 15 + .../model_containerappprobe.go | 16 + .../model_containerappprobehttpget.go | 12 + ...tainerappprobehttpgethttpheadersinlined.go | 9 + .../model_containerappprobetcpsocket.go | 9 + .../model_containerresources.go | 10 + .../model_customscalerule.go | 11 + .../model_environmentvar.go | 10 + .../model_httpscalerule.go | 10 + .../model_queuescalerule.go | 12 + .../containerappsrevisions/model_revision.go | 16 + .../model_revisionproperties.go | 48 + .../containerappsrevisions/model_scale.go | 12 + .../containerappsrevisions/model_scalerule.go | 12 + .../model_scaleruleauth.go | 9 + .../model_secretvolumeitem.go | 9 + .../model_servicebind.go | 9 + .../model_tcpscalerule.go | 10 + .../containerappsrevisions/model_template.go | 14 + .../containerappsrevisions/model_volume.go | 12 + .../model_volumemount.go | 10 + .../containerappsrevisions/predicates.go | 27 + .../containerappsrevisions/version.go | 10 + .../containerappssessionpools/README.md | 117 ++ .../containerappssessionpools/client.go | 26 + .../containerappssessionpools/constants.go | 265 +++ .../id_sessionpool.go | 130 ++ .../id_sessionpool_test.go | 282 ++++ .../method_createorupdate.go | 75 + .../method_delete.go | 70 + .../containerappssessionpools/method_get.go | 53 + .../method_listbyresourcegroup.go | 106 ++ .../method_listbysubscription.go | 106 ++ .../method_update.go | 75 + .../model_customcontainertemplate.go | 10 + .../model_dynamicpoolconfiguration.go | 8 + .../model_environmentvar.go | 10 + .../model_lifecycleconfiguration.go | 10 + .../model_managedidentitysetting.go | 9 + .../model_scaleconfiguration.go | 9 + .../model_sessioncontainer.go | 13 + .../model_sessioncontainerresources.go | 9 + .../model_sessioningress.go | 8 + .../model_sessionnetworkconfiguration.go | 8 + .../model_sessionpool.go | 20 + .../model_sessionpoolproperties.go | 19 + .../model_sessionpoolsecret.go | 9 + .../model_sessionpoolupdatableproperties.go | 14 + ...essionpoolupdatablepropertiesproperties.go | 12 + .../model_sessionregistrycredentials.go | 11 + .../containerappssessionpools/predicates.go | 32 + .../containerappssessionpools/version.go | 10 + .../containerappssourcecontrols/README.md | 82 + .../containerappssourcecontrols/client.go | 26 + .../containerappssourcecontrols/constants.go | 57 + .../id_containerapp.go | 130 ++ .../id_containerapp_test.go | 282 ++++ .../id_sourcecontrol.go | 139 ++ .../id_sourcecontrol_test.go | 327 ++++ .../method_createorupdate.go | 75 + .../method_delete.go | 71 + .../containerappssourcecontrols/method_get.go | 53 + .../method_listbycontainerapp.go | 105 ++ .../model_azurecredentials.go | 12 + .../model_githubactionconfiguration.go | 16 + .../model_registryinfo.go | 10 + .../model_sourcecontrol.go | 16 + .../model_sourcecontrolproperties.go | 11 + .../containerappssourcecontrols/predicates.go | 27 + .../containerappssourcecontrols/version.go | 10 + .../2025-01-01/daprcomponents/README.md | 192 +++ .../2025-01-01/daprcomponents/client.go | 26 + .../daprcomponents/id_connectedenvironment.go | 130 ++ .../id_connectedenvironment_test.go | 282 ++++ .../id_connectedenvironmentdaprcomponent.go | 139 ++ ..._connectedenvironmentdaprcomponent_test.go | 327 ++++ .../daprcomponents/id_daprcomponent.go | 139 ++ .../daprcomponents/id_daprcomponent_test.go | 327 ++++ .../daprcomponents/id_managedenvironment.go | 130 ++ .../id_managedenvironment_test.go | 282 ++++ ...nvironmentsdaprcomponentscreateorupdate.go | 57 + ...nnectedenvironmentsdaprcomponentsdelete.go | 47 + ..._connectedenvironmentsdaprcomponentsget.go | 53 + ...connectedenvironmentsdaprcomponentslist.go | 105 ++ ...edenvironmentsdaprcomponentslistsecrets.go | 54 + .../daprcomponents/method_createorupdate.go | 57 + .../daprcomponents/method_delete.go | 47 + .../2025-01-01/daprcomponents/method_get.go | 53 + .../2025-01-01/daprcomponents/method_list.go | 105 ++ .../daprcomponents/method_listsecrets.go | 54 + .../daprcomponents/model_daprcomponent.go | 16 + .../model_daprcomponentproperties.go | 15 + .../daprcomponents/model_daprmetadata.go | 10 + .../daprcomponents/model_daprsecret.go | 9 + .../model_daprsecretscollection.go | 8 + .../2025-01-01/daprcomponents/model_secret.go | 11 + .../2025-01-01/daprcomponents/predicates.go | 27 + .../2025-01-01/daprcomponents/version.go | 10 + .../2025-01-01/diagnostics/README.md | 200 +++ .../2025-01-01/diagnostics/client.go | 26 + .../2025-01-01/diagnostics/constants.go | 976 +++++++++++ .../2025-01-01/diagnostics/id_containerapp.go | 130 ++ .../diagnostics/id_containerapp_test.go | 282 ++++ .../diagnostics/id_containerappdetector.go | 139 ++ .../id_containerappdetector_test.go | 327 ++++ .../2025-01-01/diagnostics/id_detector.go | 139 ++ .../diagnostics/id_detector_test.go | 327 ++++ .../diagnostics/id_detectorproperty.go | 139 ++ .../diagnostics/id_detectorproperty_test.go | 327 ++++ .../2025-01-01/diagnostics/id_job.go | 130 ++ .../2025-01-01/diagnostics/id_job_test.go | 282 ++++ .../diagnostics/id_managedenvironment.go | 130 ++ .../diagnostics/id_managedenvironment_test.go | 282 ++++ .../id_managedenvironmentdetector.go | 139 ++ .../id_managedenvironmentdetector_test.go | 327 ++++ .../diagnostics/id_revisionsapirevision.go | 141 ++ .../id_revisionsapirevision_test.go | 357 ++++ ...hod_containerappsdiagnosticsgetdetector.go | 53 + ...hod_containerappsdiagnosticsgetrevision.go | 53 + .../method_containerappsdiagnosticsgetroot.go | 54 + ...d_containerappsdiagnosticslistdetectors.go | 105 ++ ...d_containerappsdiagnosticslistrevisions.go | 134 ++ .../diagnostics/method_jobsgetdetector.go | 53 + .../diagnostics/method_jobslistdetectors.go | 105 ++ .../diagnostics/method_jobsproxyget.go | 53 + ...anagedenvironmentdiagnosticsgetdetector.go | 53 + ...agedenvironmentdiagnosticslistdetectors.go | 105 ++ ...d_managedenvironmentsdiagnosticsgetroot.go | 54 + .../diagnostics/model_applogsconfiguration.go | 9 + .../diagnostics/model_basecontainer.go | 14 + .../model_certificatekeyvaultproperties.go | 9 + .../diagnostics/model_configuration.go | 16 + .../2025-01-01/diagnostics/model_container.go | 15 + .../diagnostics/model_containerapp.go | 22 + .../diagnostics/model_containerappprobe.go | 16 + .../model_containerappprobehttpget.go | 12 + ...tainerappprobehttpgethttpheadersinlined.go | 9 + .../model_containerappprobetcpsocket.go | 9 + .../model_containerappproperties.go | 20 + .../diagnostics/model_containerresources.go | 10 + .../diagnostics/model_corspolicy.go | 13 + .../diagnostics/model_customdomain.go | 10 + .../model_customdomainconfiguration.go | 33 + .../diagnostics/model_customscalerule.go | 11 + .../2025-01-01/diagnostics/model_dapr.go | 15 + .../diagnostics/model_daprconfiguration.go | 8 + .../model_diagnosticdataprovidermetadata.go | 9 + ...cdataprovidermetadatapropertybaginlined.go | 9 + ...model_diagnosticdatatableresponsecolumn.go | 10 + ...model_diagnosticdatatableresponseobject.go | 10 + .../diagnostics/model_diagnosticrendering.go | 11 + .../diagnostics/model_diagnostics.go | 16 + .../model_diagnosticsdataapiresponse.go | 9 + .../model_diagnosticsdefinition.go | 16 + .../model_diagnosticsproperties.go | 11 + .../diagnostics/model_diagnosticsstatus.go | 9 + .../model_diagnosticsupporttopic.go | 9 + .../diagnostics/model_environmentvar.go | 10 + .../diagnostics/model_extendedlocation.go | 9 + .../diagnostics/model_httpscalerule.go | 10 + .../diagnostics/model_identitysettings.go | 9 + .../2025-01-01/diagnostics/model_ingress.go | 20 + .../diagnostics/model_ingressportmapping.go | 10 + .../model_ingressstickysessions.go | 8 + .../model_ipsecurityrestrictionrule.go | 11 + .../2025-01-01/diagnostics/model_job.go | 20 + .../diagnostics/model_jobconfiguration.go | 16 + ...odel_jobconfigurationeventtriggerconfig.go | 10 + ...del_jobconfigurationmanualtriggerconfig.go | 9 + ...l_jobconfigurationscheduletriggerconfig.go | 10 + .../diagnostics/model_jobproperties.go | 14 + .../2025-01-01/diagnostics/model_jobscale.go | 11 + .../diagnostics/model_jobscalerule.go | 12 + .../diagnostics/model_jobtemplate.go | 10 + .../diagnostics/model_kedaconfiguration.go | 8 + .../model_loganalyticsconfiguration.go | 9 + .../diagnostics/model_managedenvironment.go | 21 + .../model_managedenvironmentproperties.go | 24 + ...environmentpropertiespeerauthentication.go | 8 + ...nmentpropertiespeertrafficconfiguration.go | 8 + ...rtiespeertrafficconfigurationencryption.go | 8 + .../2025-01-01/diagnostics/model_mtls.go | 8 + .../diagnostics/model_queuescalerule.go | 12 + .../diagnostics/model_registrycredentials.go | 11 + .../2025-01-01/diagnostics/model_revision.go | 16 + .../diagnostics/model_revisionproperties.go | 48 + .../2025-01-01/diagnostics/model_runtime.go | 8 + .../diagnostics/model_runtimejava.go | 8 + .../2025-01-01/diagnostics/model_scale.go | 12 + .../2025-01-01/diagnostics/model_scalerule.go | 12 + .../diagnostics/model_scaleruleauth.go | 9 + .../2025-01-01/diagnostics/model_secret.go | 11 + .../diagnostics/model_secretvolumeitem.go | 9 + .../2025-01-01/diagnostics/model_service.go | 8 + .../diagnostics/model_servicebind.go | 9 + .../diagnostics/model_tcpscalerule.go | 10 + .../2025-01-01/diagnostics/model_template.go | 14 + .../diagnostics/model_trafficweight.go | 11 + .../diagnostics/model_vnetconfiguration.go | 12 + .../2025-01-01/diagnostics/model_volume.go | 12 + .../diagnostics/model_volumemount.go | 10 + .../diagnostics/model_workloadprofile.go | 11 + .../2025-01-01/diagnostics/predicates.go | 50 + .../2025-01-01/diagnostics/version.go | 10 + .../2025-01-01/javacomponents/README.md | 99 ++ .../2025-01-01/javacomponents/client.go | 26 + .../2025-01-01/javacomponents/constants.go | 104 ++ .../javacomponents/id_javacomponent.go | 139 ++ .../javacomponents/id_javacomponent_test.go | 327 ++++ .../javacomponents/id_managedenvironment.go | 130 ++ .../id_managedenvironment_test.go | 282 ++++ .../javacomponents/method_createorupdate.go | 75 + .../javacomponents/method_delete.go | 70 + .../2025-01-01/javacomponents/method_get.go | 53 + .../2025-01-01/javacomponents/method_list.go | 105 ++ .../javacomponents/method_update.go | 75 + .../javacomponents/model_javacomponent.go | 53 + ...odel_javacomponentconfigurationproperty.go | 9 + .../model_javacomponentingress.go | 8 + .../model_javacomponentproperties.go | 95 ++ .../model_javacomponentpropertiesscale.go | 9 + .../model_javacomponentservicebind.go | 9 + .../model_springbootadmincomponent.go | 58 + .../model_springcloudconfigcomponent.go | 57 + .../model_springcloudeurekacomponent.go | 58 + .../2025-01-01/javacomponents/predicates.go | 27 + .../2025-01-01/javacomponents/version.go | 10 + .../containerapps/2025-01-01/jobs/README.md | 261 +++ .../containerapps/2025-01-01/jobs/client.go | 26 + .../2025-01-01/jobs/constants.go | 339 ++++ .../2025-01-01/jobs/id_detector.go | 139 ++ .../2025-01-01/jobs/id_detector_test.go | 327 ++++ .../2025-01-01/jobs/id_detectorproperty.go | 139 ++ .../jobs/id_detectorproperty_test.go | 327 ++++ .../2025-01-01/jobs/id_execution.go | 139 ++ .../2025-01-01/jobs/id_execution_test.go | 327 ++++ .../containerapps/2025-01-01/jobs/id_job.go | 130 ++ .../2025-01-01/jobs/id_job_test.go | 282 ++++ .../2025-01-01/jobs/method_createorupdate.go | 75 + .../2025-01-01/jobs/method_delete.go | 71 + .../2025-01-01/jobs/method_executionslist.go | 134 ++ .../2025-01-01/jobs/method_get.go | 53 + .../2025-01-01/jobs/method_getdetector.go | 53 + .../2025-01-01/jobs/method_jobexecution.go | 53 + .../jobs/method_listbyresourcegroup.go | 106 ++ .../jobs/method_listbysubscription.go | 106 ++ .../2025-01-01/jobs/method_listdetectors.go | 105 ++ .../2025-01-01/jobs/method_listsecrets.go | 54 + .../2025-01-01/jobs/method_proxyget.go | 53 + .../2025-01-01/jobs/method_start.go | 75 + .../2025-01-01/jobs/method_stopexecution.go | 70 + .../jobs/method_stopmultipleexecutions.go | 89 + .../2025-01-01/jobs/method_update.go | 75 + .../2025-01-01/jobs/model_basecontainer.go | 14 + .../2025-01-01/jobs/model_container.go | 15 + .../jobs/model_containerappprobe.go | 16 + .../jobs/model_containerappprobehttpget.go | 12 + ...tainerappprobehttpgethttpheadersinlined.go | 9 + .../jobs/model_containerappprobetcpsocket.go | 9 + .../jobs/model_containerresources.go | 10 + .../model_diagnosticdataprovidermetadata.go | 9 + ...cdataprovidermetadatapropertybaginlined.go | 9 + ...model_diagnosticdatatableresponsecolumn.go | 10 + ...model_diagnosticdatatableresponseobject.go | 10 + .../jobs/model_diagnosticrendering.go | 11 + .../2025-01-01/jobs/model_diagnostics.go | 16 + .../jobs/model_diagnosticsdataapiresponse.go | 9 + .../jobs/model_diagnosticsdefinition.go | 16 + .../jobs/model_diagnosticsproperties.go | 11 + .../jobs/model_diagnosticsstatus.go | 9 + .../jobs/model_diagnosticsupporttopic.go | 9 + .../2025-01-01/jobs/model_environmentvar.go | 10 + .../2025-01-01/jobs/model_identitysettings.go | 9 + .../2025-01-01/jobs/model_job.go | 20 + .../2025-01-01/jobs/model_jobconfiguration.go | 16 + ...odel_jobconfigurationeventtriggerconfig.go | 10 + ...del_jobconfigurationmanualtriggerconfig.go | 9 + ...l_jobconfigurationscheduletriggerconfig.go | 10 + .../2025-01-01/jobs/model_jobexecution.go | 11 + .../2025-01-01/jobs/model_jobexecutionbase.go | 9 + .../jobs/model_jobexecutioncontainer.go | 13 + .../jobs/model_jobexecutionproperties.go | 41 + .../jobs/model_jobexecutiontemplate.go | 9 + .../jobs/model_jobpatchproperties.go | 14 + .../model_jobpatchpropertiesproperties.go | 12 + .../2025-01-01/jobs/model_jobproperties.go | 14 + .../2025-01-01/jobs/model_jobscale.go | 11 + .../2025-01-01/jobs/model_jobscalerule.go | 12 + .../jobs/model_jobsecretscollection.go | 8 + .../2025-01-01/jobs/model_jobtemplate.go | 10 + .../jobs/model_registrycredentials.go | 11 + .../2025-01-01/jobs/model_scaleruleauth.go | 9 + .../2025-01-01/jobs/model_secret.go | 11 + .../2025-01-01/jobs/model_secretvolumeitem.go | 9 + .../2025-01-01/jobs/model_volume.go | 12 + .../2025-01-01/jobs/model_volumemount.go | 10 + .../2025-01-01/jobs/predicates.go | 78 + .../containerapps/2025-01-01/jobs/version.go | 10 + .../2025-01-01/managedcertificates/README.md | 107 ++ .../2025-01-01/managedcertificates/client.go | 26 + .../managedcertificates/constants.go | 104 ++ .../id_managedcertificate.go | 139 ++ .../id_managedcertificate_test.go | 327 ++++ .../id_managedenvironment.go | 130 ++ .../id_managedenvironment_test.go | 282 ++++ .../method_createorupdate.go | 75 + .../managedcertificates/method_delete.go | 47 + .../managedcertificates/method_get.go | 53 + .../managedcertificates/method_list.go | 105 ++ .../managedcertificates/method_update.go | 57 + .../model_managedcertificate.go | 18 + .../model_managedcertificatepatch.go | 8 + .../model_managedcertificateproperties.go | 12 + .../managedcertificates/predicates.go | 32 + .../2025-01-01/managedcertificates/version.go | 10 + .../2025-01-01/managedenvironments/README.md | 398 +++++ .../2025-01-01/managedenvironments/client.go | 26 + .../managedenvironments/constants.go | 210 +++ .../managedenvironments/id_certificate.go | 139 ++ .../id_certificate_test.go | 327 ++++ .../id_managedcertificate.go | 139 ++ .../id_managedcertificate_test.go | 327 ++++ .../id_managedenvironment.go | 130 ++ .../id_managedenvironment_test.go | 282 ++++ .../id_managedenvironmentdetector.go | 139 ++ .../id_managedenvironmentdetector_test.go | 327 ++++ .../method_certificatescreateorupdate.go | 57 + .../method_certificatesdelete.go | 47 + .../method_certificatesget.go | 53 + .../method_certificateslist.go | 105 ++ .../method_certificatesupdate.go | 57 + .../method_createorupdate.go | 75 + .../managedenvironments/method_delete.go | 71 + .../method_diagnosticsgetroot.go | 54 + .../managedenvironments/method_get.go | 53 + .../method_getauthtoken.go | 54 + .../method_listbyresourcegroup.go | 106 ++ .../method_listbysubscription.go | 106 ++ .../method_listworkloadprofilestates.go | 105 ++ ...ethod_managedcertificatescreateorupdate.go | 75 + .../method_managedcertificatesdelete.go | 47 + .../method_managedcertificatesget.go | 53 + .../method_managedcertificateslist.go | 105 ++ .../method_managedcertificatesupdate.go | 57 + ...anagedenvironmentdiagnosticsgetdetector.go | 53 + ...agedenvironmentdiagnosticslistdetectors.go | 105 ++ .../method_namespaceschecknameavailability.go | 58 + .../managedenvironments/method_update.go | 75 + .../model_applogsconfiguration.go | 9 + .../managedenvironments/model_certificate.go | 18 + .../model_certificatekeyvaultproperties.go | 9 + .../model_certificatepatch.go | 8 + .../model_certificateproperties.go | 49 + .../model_checknameavailabilityrequest.go | 9 + .../model_checknameavailabilityresponse.go | 10 + .../model_customdomainconfiguration.go | 33 + .../model_daprconfiguration.go | 8 + .../model_diagnosticdataprovidermetadata.go | 9 + ...cdataprovidermetadatapropertybaginlined.go | 9 + ...model_diagnosticdatatableresponsecolumn.go | 10 + ...model_diagnosticdatatableresponseobject.go | 10 + .../model_diagnosticrendering.go | 11 + .../managedenvironments/model_diagnostics.go | 16 + .../model_diagnosticsdataapiresponse.go | 9 + .../model_diagnosticsdefinition.go | 16 + .../model_diagnosticsproperties.go | 11 + .../model_diagnosticsstatus.go | 9 + .../model_diagnosticsupporttopic.go | 9 + .../model_environmentauthtoken.go | 18 + .../model_environmentauthtokenproperties.go | 27 + .../model_kedaconfiguration.go | 8 + .../model_loganalyticsconfiguration.go | 9 + .../model_managedcertificate.go | 18 + .../model_managedcertificatepatch.go | 8 + .../model_managedcertificateproperties.go | 12 + .../model_managedenvironment.go | 21 + .../model_managedenvironmentproperties.go | 24 + ...environmentpropertiespeerauthentication.go | 8 + ...nmentpropertiespeertrafficconfiguration.go | 8 + ...rtiespeertrafficconfigurationencryption.go | 8 + .../managedenvironments/model_mtls.go | 8 + .../model_vnetconfiguration.go | 12 + .../model_workloadprofile.go | 11 + .../model_workloadprofilestates.go | 16 + .../model_workloadprofilestatesproperties.go | 10 + .../managedenvironments/predicates.go | 139 ++ .../2025-01-01/managedenvironments/version.go | 10 + .../managedenvironmentsstorages/README.md | 89 + .../managedenvironmentsstorages/client.go | 26 + .../managedenvironmentsstorages/constants.go | 51 + .../id_managedenvironment.go | 130 ++ .../id_managedenvironment_test.go | 282 ++++ .../managedenvironmentsstorages/id_storage.go | 139 ++ .../id_storage_test.go | 327 ++++ .../method_createorupdate.go | 57 + .../method_delete.go | 47 + .../managedenvironmentsstorages/method_get.go | 53 + .../method_list.go | 54 + .../model_azurefileproperties.go | 11 + .../model_managedenvironmentstorage.go | 16 + ...del_managedenvironmentstorageproperties.go | 9 + ...el_managedenvironmentstoragescollection.go | 8 + .../model_nfsazurefileproperties.go | 10 + .../managedenvironmentsstorages/version.go | 10 + .../2025-01-01/subscriptions/client.go | 26 + .../method_getcustomdomainverificationid.go | 55 + .../2025-01-01/subscriptions/version.go | 10 + .../containerapps/2025-01-01/usages/README.md | 54 + .../containerapps/2025-01-01/usages/client.go | 26 + .../2025-01-01/usages/constants.go | 48 + .../2025-01-01/usages/id_location.go | 121 ++ .../2025-01-01/usages/id_location_test.go | 237 +++ .../usages/id_managedenvironment.go | 130 ++ .../usages/id_managedenvironment_test.go | 282 ++++ .../2025-01-01/usages/method_list.go | 105 ++ .../method_managedenvironmentusageslist.go | 105 ++ .../2025-01-01/usages/model_usage.go | 11 + .../2025-01-01/usages/model_usagename.go | 9 + .../2025-01-01/usages/predicates.go | 22 + .../2025-01-01/usages/version.go | 10 + .../2025-02-01/azurebackupjob/README.md | 64 + .../2025-02-01/azurebackupjob/client.go | 26 + .../2025-02-01/azurebackupjob/id_backupjob.go | 139 ++ .../azurebackupjob/id_backupjob_test.go | 327 ++++ .../azurebackupjob/id_backupvault.go | 130 ++ .../azurebackupjob/id_backupvault_test.go | 282 ++++ .../azurebackupjob/id_operationid.go | 140 ++ .../azurebackupjob/id_operationid_test.go | 342 ++++ .../method_exportjobsoperationresultget.go | 54 + .../method_exportjobstrigger.go | 70 + .../azurebackupjob/method_jobsget.go | 53 + .../azurebackupjob/model_azurebackupjob.go | 65 + .../model_azurebackupjobresource.go | 16 + .../azurebackupjob/model_exportjobsresult.go | 11 + .../azurebackupjob/model_innererror.go | 10 + .../azurebackupjob/model_jobextendedinfo.go | 15 + .../azurebackupjob/model_jobsubtask.go | 12 + .../model_restorejobrecoverypointdetails.go | 27 + .../azurebackupjob/model_userfacingerror.go | 16 + .../model_userfacingwarningdetail.go | 9 + .../2025-02-01/azurebackupjob/version.go | 10 + .../2025-02-01/azurebackupjobs/README.md | 37 + .../2025-02-01/azurebackupjobs/client.go | 26 + .../azurebackupjobs/id_backupvault.go | 130 ++ .../azurebackupjobs/id_backupvault_test.go | 282 ++++ .../azurebackupjobs/method_jobslist.go | 105 ++ .../azurebackupjobs/model_azurebackupjob.go | 65 + .../model_azurebackupjobresource.go | 16 + .../azurebackupjobs/model_innererror.go | 10 + .../azurebackupjobs/model_jobextendedinfo.go | 15 + .../azurebackupjobs/model_jobsubtask.go | 12 + .../model_restorejobrecoverypointdetails.go | 27 + .../azurebackupjobs/model_userfacingerror.go | 16 + .../model_userfacingwarningdetail.go | 9 + .../2025-02-01/azurebackupjobs/predicates.go | 27 + .../2025-02-01/azurebackupjobs/version.go | 10 + .../2025-02-01/backupinstances/README.md | 293 ++++ .../2025-02-01/backupinstances/client.go | 26 + .../2025-02-01/backupinstances/constants.go | 635 +++++++ .../backupinstances/id_backupinstance.go | 139 ++ .../backupinstances/id_backupinstance_test.go | 327 ++++ .../backupinstances/id_backupvault.go | 130 ++ .../backupinstances/id_backupvault_test.go | 282 ++++ .../backupinstances/id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../backupinstances/method_adhocbackup.go | 75 + .../backupinstances/method_createorupdate.go | 105 ++ .../backupinstances/method_delete.go | 100 ++ .../2025-02-01/backupinstances/method_get.go | 53 + .../2025-02-01/backupinstances/method_list.go | 105 ++ .../backupinstances/method_resumebackups.go | 70 + .../method_resumeprotection.go | 70 + .../backupinstances/method_stopprotection.go | 103 ++ .../backupinstances/method_suspendbackups.go | 103 ++ .../method_syncbackupinstance.go | 74 + .../method_triggercrossregionrestore.go | 75 + .../method_triggerrehydrate.go | 74 + .../backupinstances/method_triggerrestore.go | 104 ++ .../method_validatecrossregionrestore.go | 75 + .../method_validateforbackup.go | 75 + .../method_validateformodifybackup.go | 73 + .../method_validateforrestore.go | 75 + .../model_adhocbackupruleoptions.go | 9 + .../model_adhocbackuptriggeroption.go | 8 + ...odel_adlsblobbackupdatasourceparameters.go | 50 + .../backupinstances/model_authcredentials.go | 75 + ...ebackuprecoverypointbasedrestorerequest.go | 98 ++ ...rebackuprecoverytimebasedrestorerequest.go | 98 ++ .../model_azurebackuprehydrationrequest.go | 10 + .../model_azurebackuprestorerequest.go | 132 ++ ...zurebackuprestorewithrehydrationrequest.go | 104 ++ .../model_azureoperationalstoreparameters.go | 52 + .../model_backupdatasourceparameters.go | 91 + .../backupinstances/model_backupinstance.go | 75 + .../model_backupinstanceresource.go | 17 + .../model_baseresourceproperties.go | 75 + .../model_blobbackupdatasourceparameters.go | 50 + .../model_crossregionrestoredetails.go | 9 + .../model_crossregionrestorerequestobject.go | 42 + .../backupinstances/model_datasource.go | 60 + .../backupinstances/model_datasourceset.go | 60 + .../model_datastoreparameters.go | 76 + .../model_defaultresourceproperties.go | 49 + .../backupinstances/model_identitydetails.go | 9 + .../backupinstances/model_innererror.go | 10 + .../model_itemlevelrestorecriteria.go | 115 ++ .../model_itemlevelrestoretargetinfo.go | 110 ++ .../model_itempathbasedrestorecriteria.go | 52 + ...rnetesclusterbackupdatasourceparameters.go | 58 + .../model_kubernetesclusterrestorecriteria.go | 60 + ...bernetesclustervaulttierrestorecriteria.go | 62 + .../model_kubernetespvrestorecriteria.go | 51 + ...l_kubernetesstorageclassrestorecriteria.go | 51 + .../model_namespacednameresource.go | 9 + .../model_operationextendedinfo.go | 75 + .../model_operationjobextendedinfo.go | 50 + .../backupinstances/model_policyinfo.go | 10 + .../backupinstances/model_policyparameters.go | 60 + .../model_protectionstatusdetails.go | 9 + ...odel_rangebaseditemlevelrestorecriteria.go | 51 + .../model_restorefilestargetinfo.go | 54 + .../model_restoretargetinfo.go | 92 ++ .../model_restoretargetinfobase.go | 93 ++ .../model_secretstorebasedauthcredentials.go | 50 + .../model_secretstoreresource.go | 10 + .../model_stopprotectionrequest.go | 8 + .../model_suspendbackuprequest.go | 8 + .../model_syncbackupinstancerequest.go | 8 + .../backupinstances/model_targetdetails.go | 11 + .../model_triggerbackuprequest.go | 8 + .../backupinstances/model_userfacingerror.go | 16 + ...validatecrossregionrestorerequestobject.go | 42 + .../model_validateforbackuprequest.go | 8 + .../model_validateformodifybackuprequest.go | 8 + .../model_validaterestorerequestobject.go | 33 + .../2025-02-01/backupinstances/predicates.go | 27 + .../2025-02-01/backupinstances/version.go | 10 + .../backupinstancesextensionrouting/README.md | 38 + .../backupinstancesextensionrouting/client.go | 26 + .../constants.go | 339 ++++ .../method_list.go | 106 ++ ...odel_adlsblobbackupdatasourceparameters.go | 50 + .../model_authcredentials.go | 75 + .../model_azureoperationalstoreparameters.go | 52 + .../model_backupdatasourceparameters.go | 91 + .../model_backupinstance.go | 75 + .../model_backupinstanceresource.go | 17 + .../model_baseresourceproperties.go | 75 + .../model_blobbackupdatasourceparameters.go | 50 + .../model_datasource.go | 60 + .../model_datasourceset.go | 60 + .../model_datastoreparameters.go | 76 + .../model_defaultresourceproperties.go | 49 + .../model_identitydetails.go | 9 + .../model_innererror.go | 10 + ...rnetesclusterbackupdatasourceparameters.go | 58 + .../model_namespacednameresource.go | 9 + .../model_policyinfo.go | 10 + .../model_policyparameters.go | 60 + .../model_protectionstatusdetails.go | 9 + .../model_secretstorebasedauthcredentials.go | 50 + .../model_secretstoreresource.go | 10 + .../model_userfacingerror.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../2025-02-01/backuppolicies/README.md | 90 + .../2025-02-01/backuppolicies/client.go | 26 + .../2025-02-01/backuppolicies/constants.go | 281 ++++ .../backuppolicies/id_backuppolicy.go | 139 ++ .../backuppolicies/id_backuppolicy_test.go | 327 ++++ .../backuppolicies/id_backupvault.go | 130 ++ .../backuppolicies/id_backupvault_test.go | 282 ++++ .../backuppolicies/method_createorupdate.go | 57 + .../backuppolicies/method_delete.go | 47 + .../2025-02-01/backuppolicies/method_get.go | 53 + .../2025-02-01/backuppolicies/method_list.go | 105 ++ .../model_absolutedeleteoption.go | 51 + .../model_adhocbasedtaggingcriteria.go | 8 + .../model_adhocbasedtriggercontext.go | 50 + .../backuppolicies/model_azurebackupparams.go | 50 + .../backuppolicies/model_azurebackuprule.go | 94 ++ .../model_azureretentionrule.go | 53 + .../backuppolicies/model_backupcriteria.go | 75 + .../backuppolicies/model_backupparameters.go | 75 + .../backuppolicies/model_backuppolicy.go | 91 + .../backuppolicies/model_backupschedule.go | 9 + .../backuppolicies/model_basebackuppolicy.go | 76 + .../model_basebackuppolicyresource.go | 53 + .../backuppolicies/model_basepolicyrule.go | 84 + .../model_copyonexpiryoption.go | 49 + .../backuppolicies/model_copyoption.go | 91 + .../backuppolicies/model_customcopyoption.go | 50 + .../backuppolicies/model_datastoreinfobase.go | 9 + .../2025-02-01/backuppolicies/model_day.go | 9 + .../backuppolicies/model_deleteoption.go | 76 + .../model_immediatecopyoption.go | 49 + .../backuppolicies/model_retentiontag.go | 10 + .../model_schedulebasedbackupcriteria.go | 55 + .../model_schedulebasedtriggercontext.go | 51 + .../backuppolicies/model_sourcelifecycle.go | 45 + .../backuppolicies/model_taggingcriteria.go | 57 + .../backuppolicies/model_targetcopysetting.go | 42 + .../backuppolicies/model_triggercontext.go | 83 + .../2025-02-01/backuppolicies/predicates.go | 27 + .../2025-02-01/backuppolicies/version.go | 10 + .../2025-02-01/backupvaults/README.md | 138 ++ .../2025-02-01/backupvaults/client.go | 26 + .../2025-02-01/backupvaults/constants.go | 653 ++++++++ .../2025-02-01/backupvaults/id_backupvault.go | 130 ++ .../backupvaults/id_backupvault_test.go | 282 ++++ .../backupvaults/id_providerlocation.go | 130 ++ .../backupvaults/id_providerlocation_test.go | 282 ++++ .../method_checknameavailability.go | 58 + .../backupvaults/method_createorupdate.go | 104 ++ .../2025-02-01/backupvaults/method_delete.go | 71 + .../2025-02-01/backupvaults/method_get.go | 53 + .../backupvaults/method_getinresourcegroup.go | 106 ++ .../backupvaults/method_getinsubscription.go | 106 ++ .../2025-02-01/backupvaults/method_update.go | 104 ++ .../model_azuremonitoralertsettings.go | 8 + .../backupvaults/model_backupvault.go | 19 + .../backupvaults/model_backupvaultresource.go | 20 + .../model_checknameavailabilityrequest.go | 9 + .../model_checknameavailabilityresult.go | 10 + .../backupvaults/model_cmkkekidentity.go | 9 + .../model_cmkkeyvaultproperties.go | 8 + .../model_crossregionrestoresettings.go | 8 + .../model_crosssubscriptionrestoresettings.go | 8 + .../backupvaults/model_dppidentitydetails.go | 11 + .../backupvaults/model_encryptionsettings.go | 11 + .../backupvaults/model_featuresettings.go | 9 + .../model_immutabilitysettings.go | 8 + .../backupvaults/model_monitoringsettings.go | 8 + .../model_patchbackupvaultinput.go | 11 + .../model_patchresourcerequestinput.go | 10 + .../backupvaults/model_resourcemovedetails.go | 12 + .../backupvaults/model_securitysettings.go | 10 + .../backupvaults/model_softdeletesettings.go | 9 + .../backupvaults/model_storagesetting.go | 9 + .../model_userassignedidentity.go | 9 + .../2025-02-01/backupvaults/predicates.go | 37 + .../2025-02-01/backupvaults/version.go | 10 + .../dataprotection/2025-02-01/client.go | 145 ++ .../deletedbackupinstances/README.md | 65 + .../deletedbackupinstances/client.go | 26 + .../deletedbackupinstances/constants.go | 339 ++++ .../deletedbackupinstances/id_backupvault.go | 130 ++ .../id_backupvault_test.go | 282 ++++ .../id_deletedbackupinstance.go | 139 ++ .../id_deletedbackupinstance_test.go | 327 ++++ .../deletedbackupinstances/method_get.go | 53 + .../deletedbackupinstances/method_list.go | 105 ++ .../deletedbackupinstances/method_undelete.go | 70 + ...odel_adlsblobbackupdatasourceparameters.go | 50 + .../model_authcredentials.go | 75 + .../model_azureoperationalstoreparameters.go | 52 + .../model_backupdatasourceparameters.go | 91 + .../model_baseresourceproperties.go | 75 + .../model_blobbackupdatasourceparameters.go | 50 + .../model_datasource.go | 60 + .../model_datasourceset.go | 60 + .../model_datastoreparameters.go | 76 + .../model_defaultresourceproperties.go | 49 + .../model_deletedbackupinstance.go | 78 + .../model_deletedbackupinstanceresource.go | 16 + .../model_deletioninfo.go | 11 + .../model_identitydetails.go | 9 + .../model_innererror.go | 10 + ...rnetesclusterbackupdatasourceparameters.go | 58 + .../model_namespacednameresource.go | 9 + .../model_policyinfo.go | 10 + .../model_policyparameters.go | 60 + .../model_protectionstatusdetails.go | 9 + .../model_secretstorebasedauthcredentials.go | 50 + .../model_secretstoreresource.go | 10 + .../model_userfacingerror.go | 16 + .../deletedbackupinstances/predicates.go | 27 + .../deletedbackupinstances/version.go | 10 + .../2025-02-01/dppfeaturesupport/README.md | 41 + .../2025-02-01/dppfeaturesupport/client.go | 26 + .../2025-02-01/dppfeaturesupport/constants.go | 104 ++ .../dppfeaturesupport/id_location.go | 121 ++ .../dppfeaturesupport/id_location_test.go | 237 +++ ...ethod_dataprotectioncheckfeaturesupport.go | 63 + .../model_featurevalidationrequest.go | 51 + .../model_featurevalidationrequestbase.go | 75 + .../model_featurevalidationresponse.go | 51 + .../model_featurevalidationresponsebase.go | 75 + .../model_supportedfeature.go | 10 + .../2025-02-01/dppfeaturesupport/version.go | 10 + .../2025-02-01/dppjob/README.md | 63 + .../2025-02-01/dppjob/client.go | 26 + .../2025-02-01/dppjob/id_providerlocation.go | 130 ++ .../dppjob/id_providerlocation_test.go | 282 ++++ .../method_fetchcrossregionrestorejobget.go | 58 + .../method_fetchcrossregionrestorejobslist.go | 134 ++ .../2025-02-01/dppjob/model_azurebackupjob.go | 65 + .../dppjob/model_azurebackupjobresource.go | 16 + .../model_crossregionrestorejobrequest.go | 10 + .../model_crossregionrestorejobsrequest.go | 9 + .../2025-02-01/dppjob/model_innererror.go | 10 + .../dppjob/model_jobextendedinfo.go | 15 + .../2025-02-01/dppjob/model_jobsubtask.go | 12 + .../model_restorejobrecoverypointdetails.go | 27 + .../dppjob/model_userfacingerror.go | 16 + .../dppjob/model_userfacingwarningdetail.go | 9 + .../2025-02-01/dppjob/predicates.go | 27 + .../2025-02-01/dppjob/version.go | 10 + .../dppresourceguardproxies/README.md | 111 ++ .../dppresourceguardproxies/client.go | 26 + .../id_backupresourceguardproxy.go | 139 ++ .../id_backupresourceguardproxy_test.go | 327 ++++ .../dppresourceguardproxies/id_backupvault.go | 130 ++ .../id_backupvault_test.go | 282 ++++ ...hod_dppresourceguardproxycreateorupdate.go | 57 + .../method_dppresourceguardproxydelete.go | 47 + .../method_dppresourceguardproxyget.go | 53 + .../method_dppresourceguardproxylist.go | 105 ++ ...ethod_dppresourceguardproxyunlockdelete.go | 87 + .../model_resourceguardoperationdetail.go | 9 + .../model_resourceguardproxybase.go | 11 + .../model_resourceguardproxybaseresource.go | 16 + .../model_unlockdeleterequest.go | 9 + .../model_unlockdeleteresponse.go | 8 + .../dppresourceguardproxies/predicates.go | 27 + .../dppresourceguardproxies/version.go | 10 + .../fetchsecondaryrecoverypoints/README.md | 42 + .../fetchsecondaryrecoverypoints/client.go | 26 + .../fetchsecondaryrecoverypoints/constants.go | 101 ++ .../id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../method_list.go | 134 ++ .../model_azurebackupdiscreterecoverypoint.go | 60 + .../model_azurebackuprecoverypoint.go | 75 + .../model_azurebackuprecoverypointresource.go | 53 + ...odel_fetchsecondaryrpsrequestparameters.go | 9 + .../model_recoverypointdatastoredetails.go | 58 + .../predicates.go | 27 + .../fetchsecondaryrecoverypoints/version.go | 10 + .../findrestorabletimeranges/README.md | 41 + .../findrestorabletimeranges/client.go | 26 + .../findrestorabletimeranges/constants.go | 54 + .../id_backupinstance.go | 139 ++ .../id_backupinstance_test.go | 327 ++++ .../method_restorabletimerangesfind.go | 58 + ...rebackupfindrestorabletimerangesrequest.go | 10 + ...ebackupfindrestorabletimerangesresponse.go | 9 + ...indrestorabletimerangesresponseresource.go | 16 + .../model_restorabletimerange.go | 10 + .../findrestorabletimeranges/version.go | 10 + .../2025-02-01/recoverypoint/README.md | 53 + .../2025-02-01/recoverypoint/client.go | 26 + .../2025-02-01/recoverypoint/constants.go | 101 ++ .../recoverypoint/id_backupinstance.go | 139 ++ .../recoverypoint/id_backupinstance_test.go | 327 ++++ .../recoverypoint/id_recoverypoint.go | 148 ++ .../recoverypoint/id_recoverypoint_test.go | 372 +++++ .../2025-02-01/recoverypoint/method_get.go | 53 + .../2025-02-01/recoverypoint/method_list.go | 134 ++ .../model_azurebackupdiscreterecoverypoint.go | 60 + .../model_azurebackuprecoverypoint.go | 75 + .../model_azurebackuprecoverypointresource.go | 53 + .../model_recoverypointdatastoredetails.go | 58 + .../2025-02-01/recoverypoint/predicates.go | 27 + .../2025-02-01/recoverypoint/version.go | 10 + .../2025-02-01/resourceguards/README.md | 327 ++++ .../2025-02-01/resourceguards/client.go | 26 + .../2025-02-01/resourceguards/constants.go | 60 + .../id_deleteprotecteditemrequest.go | 139 ++ .../id_deleteprotecteditemrequest_test.go | 327 ++++ .../id_deleteresourceguardproxyrequest.go | 139 ++ ...id_deleteresourceguardproxyrequest_test.go | 327 ++++ .../id_disablesoftdeleterequest.go | 139 ++ .../id_disablesoftdeleterequest_test.go | 327 ++++ .../id_getbackupsecuritypinrequest.go | 139 ++ .../id_getbackupsecuritypinrequest_test.go | 327 ++++ .../resourceguards/id_resourceguard.go | 130 ++ .../resourceguards/id_resourceguard_test.go | 282 ++++ .../id_updateprotecteditemrequest.go | 139 ++ .../id_updateprotecteditemrequest_test.go | 327 ++++ .../id_updateprotectionpolicyrequest.go | 139 ++ .../id_updateprotectionpolicyrequest_test.go | 327 ++++ .../resourceguards/method_delete.go | 47 + .../2025-02-01/resourceguards/method_get.go | 53 + ...hod_getbackupsecuritypinrequestsobjects.go | 105 ++ ...tdefaultbackupsecuritypinrequestsobject.go | 53 + ...efaultdeleteprotecteditemrequestsobject.go | 53 + ...tdeleteresourceguardproxyrequestsobject.go | 53 + ...tdefaultdisablesoftdeleterequestsobject.go | 53 + ...efaultupdateprotecteditemrequestsobject.go | 53 + ...ultupdateprotectionpolicyrequestsobject.go | 53 + ...d_getdeleteprotecteditemrequestsobjects.go | 105 ++ ...deleteresourceguardproxyrequestsobjects.go | 105 ++ ...hod_getdisablesoftdeleterequestsobjects.go | 105 ++ .../method_getresourcesinresourcegroup.go | 106 ++ .../method_getresourcesinsubscription.go | 106 ++ ...d_getupdateprotecteditemrequestsobjects.go | 105 ++ ...etupdateprotectionpolicyrequestsobjects.go | 105 ++ .../2025-02-01/resourceguards/method_patch.go | 57 + .../2025-02-01/resourceguards/method_put.go | 58 + .../resourceguards/model_dppbaseresource.go | 10 + .../model_patchresourceguardinput.go | 8 + .../resourceguards/model_resourceguard.go | 12 + .../model_resourceguardoperation.go | 9 + .../model_resourceguardresource.go | 19 + .../2025-02-01/resourceguards/predicates.go | 60 + .../2025-02-01/resourceguards/version.go | 10 + .../2025-01-13/agentversions/README.md | 53 + .../2025-01-13/agentversions/client.go | 26 + .../agentversions/id_agentversion.go | 121 ++ .../agentversions/id_agentversion_test.go | 237 +++ .../2025-01-13/agentversions/id_ostype.go | 112 ++ .../agentversions/id_ostype_test.go | 192 +++ .../agentversions/method_agentversionget.go | 53 + .../agentversions/method_agentversionlist.go | 105 ++ .../agentversions/model_agentversion.go | 10 + .../2025-01-13/agentversions/predicates.go | 27 + .../2025-01-13/agentversions/version.go | 10 + .../hybridcompute/2025-01-13/client.go | 181 ++ .../2025-01-13/extensions/README.md | 119 ++ .../2025-01-13/extensions/client.go | 26 + .../2025-01-13/extensions/id_extensiontype.go | 130 ++ .../extensions/id_extensiontype_test.go | 282 ++++ .../extensions/id_extensiontypeversion.go | 148 ++ .../id_extensiontypeversion_test.go | 372 +++++ .../2025-01-13/extensions/id_location.go | 112 ++ .../2025-01-13/extensions/id_location_test.go | 192 +++ .../2025-01-13/extensions/id_publisher.go | 121 ++ .../extensions/id_publisher_test.go | 237 +++ .../extensions/id_publisherextensiontype.go | 139 ++ .../id_publisherextensiontype_test.go | 327 ++++ .../2025-01-13/extensions/id_version.go | 139 ++ .../2025-01-13/extensions/id_version_test.go | 327 ++++ .../extensions/method_extensionmetadataget.go | 53 + .../method_extensionmetadatalist.go | 54 + .../method_extensionmetadatav2get.go | 53 + .../method_extensionmetadatav2list.go | 105 ++ .../method_extensionpublisherlist.go | 105 ++ .../extensions/method_extensiontypelist.go | 105 ++ .../extensions/model_extensionpublisher.go | 9 + .../extensions/model_extensiontype.go | 9 + .../extensions/model_extensionvalue.go | 16 + .../model_extensionvaluelistresult.go | 8 + .../model_extensionvalueproperties.go | 10 + .../extensions/model_extensionvaluev2.go | 16 + .../model_extensionvaluev2properties.go | 14 + .../2025-01-13/extensions/predicates.go | 63 + .../2025-01-13/extensions/version.go | 10 + .../2025-01-13/gateways/README.md | 121 ++ .../2025-01-13/gateways/client.go | 26 + .../2025-01-13/gateways/constants.go | 107 ++ .../2025-01-13/gateways/id_gateway.go | 130 ++ .../2025-01-13/gateways/id_gateway_test.go | 282 ++++ .../gateways/method_createorupdate.go | 75 + .../2025-01-13/gateways/method_delete.go | 70 + .../2025-01-13/gateways/method_get.go | 53 + .../gateways/method_listbyresourcegroup.go | 106 ++ .../gateways/method_listbysubscription.go | 106 ++ .../2025-01-13/gateways/method_update.go | 57 + .../2025-01-13/gateways/model_gateway.go | 18 + .../gateways/model_gatewayproperties.go | 12 + .../gateways/model_gatewayupdate.go | 9 + .../gateways/model_gatewayupdateproperties.go | 8 + .../2025-01-13/gateways/predicates.go | 32 + .../2025-01-13/gateways/version.go | 10 + .../hybrididentitymetadata/README.md | 53 + .../hybrididentitymetadata/client.go | 26 + .../id_hybrididentitymetadata.go | 139 ++ .../id_hybrididentitymetadata_test.go | 327 ++++ .../hybrididentitymetadata/id_machine.go | 130 ++ .../hybrididentitymetadata/id_machine_test.go | 282 ++++ .../hybrididentitymetadata/method_get.go | 53 + .../method_listbymachines.go | 105 ++ .../model_hybrididentitymetadata.go | 16 + .../model_hybrididentitymetadataproperties.go | 14 + .../hybrididentitymetadata/predicates.go | 27 + .../hybrididentitymetadata/version.go | 10 + .../2025-01-13/licenseprofiles/README.md | 99 ++ .../2025-01-13/licenseprofiles/client.go | 26 + .../2025-01-13/licenseprofiles/constants.go | 330 ++++ .../2025-01-13/licenseprofiles/id_machine.go | 130 ++ .../licenseprofiles/id_machine_test.go | 282 ++++ .../licenseprofiles/method_createorupdate.go | 75 + .../licenseprofiles/method_delete.go | 70 + .../2025-01-13/licenseprofiles/method_get.go | 54 + .../2025-01-13/licenseprofiles/method_list.go | 105 ++ .../licenseprofiles/method_update.go | 75 + .../model_erroradditionalinfo.go | 9 + .../licenseprofiles/model_errordetail.go | 12 + .../licenseprofiles/model_esukey.go | 9 + .../model_esuprofileupdateproperties.go | 8 + .../licenseprofiles/model_licenseprofile.go | 18 + .../model_licenseprofilearmesuproperties.go | 13 + ...censeprofilearmproductprofileproperties.go | 69 + .../model_licenseprofileproperties.go | 11 + ...censeprofilepropertiessoftwareassurance.go | 8 + .../model_licenseprofileupdate.go | 9 + .../model_licenseprofileupdateproperties.go | 10 + ...rofileupdatepropertiessoftwareassurance.go | 8 + .../licenseprofiles/model_productfeature.go | 68 + .../model_productfeatureupdate.go | 9 + .../model_productprofileupdateproperties.go | 10 + .../2025-01-13/licenseprofiles/predicates.go | 32 + .../2025-01-13/licenseprofiles/version.go | 10 + .../2025-01-13/licenses/README.md | 134 ++ .../2025-01-13/licenses/client.go | 26 + .../2025-01-13/licenses/constants.go | 315 ++++ .../2025-01-13/licenses/id_license.go | 130 ++ .../2025-01-13/licenses/id_license_test.go | 282 ++++ .../licenses/method_createorupdate.go | 74 + .../2025-01-13/licenses/method_delete.go | 70 + .../2025-01-13/licenses/method_get.go | 53 + .../licenses/method_listbyresourcegroup.go | 106 ++ .../licenses/method_listbysubscription.go | 106 ++ .../2025-01-13/licenses/method_update.go | 74 + .../licenses/method_validatelicense.go | 75 + .../2025-01-13/licenses/model_license.go | 18 + .../licenses/model_licensedetails.go | 15 + .../licenses/model_licenseproperties.go | 11 + .../licenses/model_licenseupdate.go | 9 + .../licenses/model_licenseupdateproperties.go | 9 + ...l_licenseupdatepropertieslicensedetails.go | 12 + .../licenses/model_volumelicensedetails.go | 9 + .../2025-01-13/licenses/predicates.go | 32 + .../2025-01-13/licenses/version.go | 10 + .../2025-01-13/machineextensions/README.md | 99 ++ .../2025-01-13/machineextensions/client.go | 26 + .../2025-01-13/machineextensions/constants.go | 54 + .../machineextensions/id_extension.go | 139 ++ .../machineextensions/id_extension_test.go | 327 ++++ .../machineextensions/id_machine.go | 130 ++ .../machineextensions/id_machine_test.go | 282 ++++ .../method_createorupdate.go | 75 + .../machineextensions/method_delete.go | 71 + .../machineextensions/method_get.go | 53 + .../machineextensions/method_list.go | 134 ++ .../machineextensions/method_update.go | 75 + .../model_machineextension.go | 18 + .../model_machineextensioninstanceview.go | 11 + ...odel_machineextensioninstanceviewstatus.go | 30 + .../model_machineextensionproperties.go | 17 + .../model_machineextensionupdate.go | 9 + .../model_machineextensionupdateproperties.go | 15 + .../machineextensions/predicates.go | 32 + .../2025-01-13/machineextensions/version.go | 10 + .../machineextensionssetup/README.md | 37 + .../machineextensionssetup/client.go | 26 + .../machineextensionssetup/constants.go | 54 + .../machineextensionssetup/id_machine.go | 130 ++ .../machineextensionssetup/id_machine_test.go | 282 ++++ .../method_setupextensions.go | 75 + .../model_machineextensioninstanceview.go | 11 + ...odel_machineextensioninstanceviewstatus.go | 30 + .../model_machineextensionproperties.go | 17 + .../model_setupextensionrequest.go | 8 + .../machineextensionssetup/version.go | 10 + .../machineextensionsupgrade/README.md | 37 + .../machineextensionsupgrade/client.go | 26 + .../machineextensionsupgrade/id_machine.go | 130 ++ .../id_machine_test.go | 282 ++++ .../method_upgradeextensions.go | 74 + .../model_extensiontargetproperties.go | 8 + .../model_machineextensionupgrade.go | 8 + .../machineextensionsupgrade/version.go | 10 + .../machinenetworkprofile/README.md | 36 + .../machinenetworkprofile/client.go | 26 + .../machinenetworkprofile/id_machine.go | 130 ++ .../machinenetworkprofile/id_machine_test.go | 282 ++++ .../method_networkprofileget.go | 54 + .../machinenetworkprofile/model_ipaddress.go | 10 + .../model_networkinterface.go | 11 + .../model_networkprofile.go | 8 + .../machinenetworkprofile/model_subnet.go | 8 + .../machinenetworkprofile/version.go | 10 + .../2025-01-13/machineruncommands/README.md | 99 ++ .../2025-01-13/machineruncommands/client.go | 26 + .../machineruncommands/constants.go | 110 ++ .../machineruncommands/id_machine.go | 130 ++ .../machineruncommands/id_machine_test.go | 282 ++++ .../machineruncommands/id_runcommand.go | 139 ++ .../machineruncommands/id_runcommand_test.go | 327 ++++ .../method_createorupdate.go | 75 + .../machineruncommands/method_delete.go | 70 + .../machineruncommands/method_get.go | 53 + .../machineruncommands/method_list.go | 134 ++ .../machineruncommands/method_update.go | 75 + .../model_extensionsresourcestatus.go | 30 + .../model_machineruncommand.go | 18 + .../model_machineruncommandinstanceview.go | 45 + .../model_machineruncommandproperties.go | 20 + .../model_machineruncommandscriptsource.go | 11 + .../model_resourceupdate.go | 8 + .../model_runcommandinputparameter.go | 9 + .../model_runcommandmanagedidentity.go | 9 + .../machineruncommands/predicates.go | 32 + .../2025-01-13/machineruncommands/version.go | 10 + .../2025-01-13/machines/README.md | 154 ++ .../2025-01-13/machines/client.go | 26 + .../2025-01-13/machines/constants.go | 1460 +++++++++++++++++ .../2025-01-13/machines/id_machine.go | 130 ++ .../2025-01-13/machines/id_machine_test.go | 282 ++++ .../machines/method_assesspatches.go | 71 + .../machines/method_createorupdate.go | 87 + .../2025-01-13/machines/method_delete.go | 70 + .../2025-01-13/machines/method_get.go | 83 + .../machines/method_installpatches.go | 75 + .../machines/method_listbyresourcegroup.go | 135 ++ .../machines/method_listbysubscription.go | 106 ++ .../2025-01-13/machines/method_update.go | 57 + .../machines/model_agentconfiguration.go | 15 + .../2025-01-13/machines/model_agentupgrade.go | 14 + ...del_availablepatchcountbyclassification.go | 16 + .../machines/model_cloudmetadata.go | 8 + .../machines/model_configurationextension.go | 9 + .../2025-01-13/machines/model_disk.go | 14 + .../machines/model_erroradditionalinfo.go | 9 + .../2025-01-13/machines/model_errordetail.go | 12 + .../2025-01-13/machines/model_esukey.go | 9 + .../machines/model_firmwareprofile.go | 9 + .../machines/model_hardwareprofile.go | 10 + .../2025-01-13/machines/model_ipaddress.go | 10 + .../2025-01-13/machines/model_license.go | 18 + .../machines/model_licensedetails.go | 15 + ...censeprofilearmproductprofileproperties.go | 69 + ...model_licenseprofilemachineinstanceview.go | 12 + ...profilemachineinstanceviewesuproperties.go | 14 + ...ilemachineinstanceviewsoftwareassurance.go | 8 + .../machines/model_licenseproperties.go | 11 + .../machines/model_linuxparameters.go | 10 + .../2025-01-13/machines/model_locationdata.go | 11 + .../2025-01-13/machines/model_machine.go | 22 + .../model_machineassesspatchesresult.go | 47 + .../machines/model_machineextension.go | 18 + .../model_machineextensioninstanceview.go | 11 + ...odel_machineextensioninstanceviewstatus.go | 30 + .../model_machineextensionproperties.go | 17 + .../model_machineinstallpatchesparameters.go | 11 + .../model_machineinstallpatchesresult.go | 52 + .../machines/model_machineproperties.go | 61 + .../machines/model_machineupdate.go | 15 + .../machines/model_machineupdateproperties.go | 15 + .../machines/model_networkinterface.go | 11 + .../machines/model_networkprofile.go | 8 + .../2025-01-13/machines/model_osprofile.go | 10 + .../model_osprofilelinuxconfiguration.go | 8 + .../model_osprofilewindowsconfiguration.go | 8 + .../machines/model_patchsettings.go | 11 + .../machines/model_patchsettingsstatus.go | 9 + .../2025-01-13/machines/model_processor.go | 9 + .../machines/model_productfeature.go | 68 + .../machines/model_servicestatus.go | 9 + .../machines/model_servicestatuses.go | 9 + .../machines/model_storageprofile.go | 8 + .../2025-01-13/machines/model_subnet.go | 8 + .../machines/model_volumelicensedetails.go | 9 + .../machines/model_windowsparameters.go | 30 + .../2025-01-13/machines/predicates.go | 32 + .../2025-01-13/machines/version.go | 10 + .../networkconfigurations/README.md | 78 + .../networkconfigurations/client.go | 26 + .../networkconfigurations/id_machine.go | 130 ++ .../networkconfigurations/id_machine_test.go | 282 ++++ .../method_createorupdate.go | 59 + .../networkconfigurations/method_get.go | 54 + .../networkconfigurations/method_update.go | 58 + .../networkconfigurations/model_keydetails.go | 40 + .../model_keyproperties.go | 9 + .../model_networkconfiguration.go | 16 + .../model_networkconfigurationproperties.go | 12 + .../networkconfigurations/version.go | 10 + .../README.md | 65 + .../client.go | 26 + .../constants.go | 183 +++ ...d_networksecurityperimeterconfiguration.go | 139 ++ ...worksecurityperimeterconfiguration_test.go | 327 ++++ .../id_providerprivatelinkscope.go | 130 ++ .../id_providerprivatelinkscope_test.go | 282 ++++ .../method_getbyprivatelinkscope.go | 53 + .../method_listbyprivatelinkscope.go | 105 ++ .../method_reconcileforprivatelinkscope.go | 71 + .../model_accessrule.go | 9 + .../model_accessruleproperties.go | 9 + .../model_networksecurityperimeter.go | 10 + ...l_networksecurityperimeterconfiguration.go | 11 + ...ecurityperimeterconfigurationproperties.go | 12 + ...typerimeterconfigurationreconcileresult.go | 8 + .../model_networksecurityperimeterprofile.go | 12 + .../model_provisioningissue.go | 9 + .../model_provisioningissueproperties.go | 12 + .../model_resourceassociation.go | 9 + .../predicates.go | 27 + .../version.go | 10 + .../privateendpointconnections/README.md | 82 + .../privateendpointconnections/client.go | 26 + .../id_privateendpointconnection.go | 139 ++ .../id_privateendpointconnection_test.go | 327 ++++ .../id_providerprivatelinkscope.go | 130 ++ .../id_providerprivatelinkscope_test.go | 282 ++++ .../method_createorupdate.go | 75 + .../method_delete.go | 71 + .../privateendpointconnections/method_get.go | 53 + .../method_listbyprivatelinkscope.go | 105 ++ .../model_privateendpointconnection.go | 16 + ...del_privateendpointconnectionproperties.go | 11 + .../model_privateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../privateendpointconnections/predicates.go | 27 + .../privateendpointconnections/version.go | 10 + .../2025-01-13/privatelinkresources/README.md | 53 + .../2025-01-13/privatelinkresources/client.go | 26 + .../id_privatelinkresource.go | 139 ++ .../id_privatelinkresource_test.go | 327 ++++ .../id_providerprivatelinkscope.go | 130 ++ .../id_providerprivatelinkscope_test.go | 282 ++++ .../privatelinkresources/method_get.go | 53 + .../method_listbyprivatelinkscope.go | 105 ++ .../model_privatelinkresource.go | 16 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/predicates.go | 27 + .../privatelinkresources/version.go | 10 + .../2025-01-13/privatelinkscopes/README.md | 157 ++ .../2025-01-13/privatelinkscopes/client.go | 26 + .../2025-01-13/privatelinkscopes/constants.go | 51 + .../privatelinkscopes/id_machine.go | 130 ++ .../privatelinkscopes/id_machine_test.go | 282 ++++ .../privatelinkscopes/id_privatelinkscope.go | 130 ++ .../id_privatelinkscope_test.go | 282 ++++ .../id_providerprivatelinkscope.go | 130 ++ .../id_providerprivatelinkscope_test.go | 282 ++++ .../method_createorupdate.go | 58 + .../privatelinkscopes/method_delete.go | 71 + .../privatelinkscopes/method_get.go | 53 + .../method_getvalidationdetails.go | 53 + .../method_getvalidationdetailsformachine.go | 54 + .../privatelinkscopes/method_list.go | 106 ++ .../method_listbyresourcegroup.go | 106 ++ .../privatelinkscopes/method_updatetags.go | 57 + .../model_connectiondetail.go | 12 + .../model_hybridcomputeprivatelinkscope.go | 18 + ...hybridcomputeprivatelinkscopeproperties.go | 11 + ...odel_privateendpointconnectiondatamodel.go | 11 + ...del_privateendpointconnectionproperties.go | 11 + .../model_privateendpointproperty.go | 8 + ...model_privatelinkscopevalidationdetails.go | 10 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../privatelinkscopes/model_tagsresource.go | 8 + .../privatelinkscopes/predicates.go | 32 + .../2025-01-13/privatelinkscopes/version.go | 10 + .../2025-01-13/settings/README.md | 78 + .../2025-01-13/settings/client.go | 26 + .../2025-01-13/settings/id_scopedsetting.go | 120 ++ .../settings/id_scopedsetting_test.go | 222 +++ .../2025-01-13/settings/method_get.go | 53 + .../2025-01-13/settings/method_patch.go | 57 + .../2025-01-13/settings/method_update.go | 58 + .../2025-01-13/settings/model_settings.go | 16 + .../model_settingsgatewayproperties.go | 8 + .../settings/model_settingsproperties.go | 9 + .../2025-01-13/settings/version.go | 10 + .../constants.go | 6 - .../constants.go | 6 - .../constants.go | 6 + .../constants.go | 6 + .../availableservicetiers/README.md | 36 + .../availableservicetiers/client.go | 26 + .../availableservicetiers/constants.go | 66 + .../availableservicetiers/id_workspace.go | 130 ++ .../id_workspace_test.go | 282 ++++ .../method_listbyworkspace.go | 54 + .../model_availableservicetier.go | 14 + .../availableservicetiers/version.go | 10 + .../operationalinsights/2025-02-01/client.go | 145 ++ .../2025-02-01/clusters/README.md | 117 ++ .../2025-02-01/clusters/client.go | 26 + .../2025-02-01/clusters/constants.go | 239 +++ .../2025-02-01/clusters/id_cluster.go | 130 ++ .../2025-02-01/clusters/id_cluster_test.go | 282 ++++ .../clusters/method_createorupdate.go | 75 + .../2025-02-01/clusters/method_delete.go | 71 + .../2025-02-01/clusters/method_get.go | 53 + .../2025-02-01/clusters/method_list.go | 106 ++ .../clusters/method_listbyresourcegroup.go | 106 ++ .../2025-02-01/clusters/method_update.go | 75 + .../clusters/model_associatedworkspace.go | 29 + .../model_capacityreservationproperties.go | 27 + .../2025-02-01/clusters/model_cluster.go | 19 + .../2025-02-01/clusters/model_clusterpatch.go | 15 + .../clusters/model_clusterpatchproperties.go | 9 + .../clusters/model_clusterproperties.go | 48 + .../model_clusterreplicationproperties.go | 43 + .../2025-02-01/clusters/model_clustersku.go | 9 + .../clusters/model_keyvaultproperties.go | 11 + .../2025-02-01/clusters/predicates.go | 32 + .../2025-02-01/clusters/version.go | 10 + .../2025-02-01/dataexport/README.md | 89 + .../2025-02-01/dataexport/client.go | 26 + .../2025-02-01/dataexport/constants.go | 51 + .../2025-02-01/dataexport/id_dataexport.go | 139 ++ .../dataexport/id_dataexport_test.go | 327 ++++ .../2025-02-01/dataexport/id_workspace.go | 130 ++ .../dataexport/id_workspace_test.go | 282 ++++ .../dataexport/method_createorupdate.go | 58 + .../2025-02-01/dataexport/method_delete.go | 46 + .../2025-02-01/dataexport/method_get.go | 53 + .../dataexport/method_listbyworkspace.go | 54 + .../2025-02-01/dataexport/model_dataexport.go | 11 + .../dataexport/model_dataexportlistresult.go | 8 + .../dataexport/model_dataexportproperties.go | 13 + .../dataexport/model_destination.go | 10 + .../dataexport/model_destinationmetadata.go | 8 + .../2025-02-01/dataexport/version.go | 10 + .../2025-02-01/datasources/README.md | 90 + .../2025-02-01/datasources/client.go | 26 + .../2025-02-01/datasources/constants.go | 144 ++ .../2025-02-01/datasources/id_datasource.go | 139 ++ .../datasources/id_datasource_test.go | 327 ++++ .../2025-02-01/datasources/id_workspace.go | 130 ++ .../datasources/id_workspace_test.go | 282 ++++ .../datasources/method_createorupdate.go | 58 + .../2025-02-01/datasources/method_delete.go | 47 + .../2025-02-01/datasources/method_get.go | 53 + .../datasources/method_listbyworkspace.go | 134 ++ .../datasources/model_datasource.go | 14 + .../2025-02-01/datasources/predicates.go | 37 + .../2025-02-01/datasources/version.go | 10 + .../2025-02-01/deletedworkspaces/README.md | 53 + .../2025-02-01/deletedworkspaces/client.go | 26 + .../2025-02-01/deletedworkspaces/constants.go | 363 ++++ .../deletedworkspaces/method_list.go | 55 + .../method_listbyresourcegroup.go | 55 + .../model_privatelinkscopedresource.go | 9 + .../deletedworkspaces/model_workspace.go | 21 + .../model_workspacecapping.go | 10 + .../model_workspacefailoverproperties.go | 27 + .../model_workspacefeatures.go | 13 + .../model_workspacelistresult.go | 8 + .../model_workspaceproperties.go | 52 + .../model_workspacereplicationproperties.go | 42 + .../deletedworkspaces/model_workspacesku.go | 28 + .../2025-02-01/deletedworkspaces/version.go | 10 + .../2025-02-01/intelligencepacks/README.md | 68 + .../2025-02-01/intelligencepacks/client.go | 26 + .../intelligencepacks/id_intelligencepack.go | 139 ++ .../id_intelligencepack_test.go | 327 ++++ .../intelligencepacks/id_workspace.go | 130 ++ .../intelligencepacks/id_workspace_test.go | 282 ++++ .../intelligencepacks/method_disable.go | 47 + .../intelligencepacks/method_enable.go | 47 + .../intelligencepacks/method_list.go | 54 + .../model_intelligencepack.go | 10 + .../2025-02-01/intelligencepacks/version.go | 10 + .../2025-02-01/linkedservices/README.md | 81 + .../2025-02-01/linkedservices/client.go | 26 + .../2025-02-01/linkedservices/constants.go | 57 + .../linkedservices/id_linkedservice.go | 139 ++ .../linkedservices/id_linkedservice_test.go | 327 ++++ .../2025-02-01/linkedservices/id_workspace.go | 130 ++ .../linkedservices/id_workspace_test.go | 282 ++++ .../linkedservices/method_createorupdate.go | 76 + .../linkedservices/method_delete.go | 72 + .../2025-02-01/linkedservices/method_get.go | 53 + .../linkedservices/method_listbyworkspace.go | 54 + .../linkedservices/model_linkedservice.go | 12 + .../model_linkedservicelistresult.go | 8 + .../model_linkedserviceproperties.go | 10 + .../2025-02-01/linkedservices/version.go | 10 + .../linkedstorageaccounts/README.md | 89 + .../linkedstorageaccounts/client.go | 26 + .../linkedstorageaccounts/constants.go | 60 + .../id_datasourcetype.go | 147 ++ .../id_datasourcetype_test.go | 327 ++++ .../linkedstorageaccounts/id_workspace.go | 130 ++ .../id_workspace_test.go | 282 ++++ .../method_createorupdate.go | 57 + .../linkedstorageaccounts/method_delete.go | 46 + .../linkedstorageaccounts/method_get.go | 53 + .../method_listbyworkspace.go | 54 + .../model_linkedstorageaccountslistresult.go | 8 + .../model_linkedstorageaccountsproperties.go | 9 + .../model_linkedstorageaccountsresource.go | 11 + .../linkedstorageaccounts/version.go | 10 + .../2025-02-01/querypackqueries/README.md | 133 ++ .../2025-02-01/querypackqueries/client.go | 26 + .../2025-02-01/querypackqueries/id_query.go | 139 ++ .../querypackqueries/id_query_test.go | 327 ++++ .../querypackqueries/id_querypack.go | 130 ++ .../querypackqueries/id_querypack_test.go | 282 ++++ .../querypackqueries/method_queriesdelete.go | 47 + .../querypackqueries/method_queriesget.go | 53 + .../querypackqueries/method_querieslist.go | 138 ++ .../querypackqueries/method_queriesput.go | 57 + .../querypackqueries/method_queriessearch.go | 138 ++ .../querypackqueries/method_queriesupdate.go | 57 + .../model_loganalyticsquerypackquery.go | 16 + ...el_loganalyticsquerypackqueryproperties.go | 47 + ...nalyticsquerypackquerypropertiesrelated.go | 10 + ...analyticsquerypackquerysearchproperties.go | 9 + ...csquerypackquerysearchpropertiesrelated.go | 10 + .../2025-02-01/querypackqueries/predicates.go | 27 + .../2025-02-01/querypackqueries/version.go | 10 + .../2025-02-01/querypacks/README.md | 150 ++ .../2025-02-01/querypacks/client.go | 26 + .../2025-02-01/querypacks/id_querypack.go | 130 ++ .../querypacks/id_querypack_test.go | 282 ++++ .../querypacks/method_createorupdate.go | 57 + .../method_createorupdatewithoutname.go | 59 + .../2025-02-01/querypacks/method_delete.go | 47 + .../2025-02-01/querypacks/method_get.go | 53 + .../2025-02-01/querypacks/method_list.go | 106 ++ .../querypacks/method_listbyresourcegroup.go | 106 ++ .../querypacks/method_updatetags.go | 57 + .../querypacks/model_loganalyticsquerypack.go | 18 + .../model_loganalyticsquerypackproperties.go | 41 + .../querypacks/model_tagsresource.go | 8 + .../2025-02-01/querypacks/predicates.go | 32 + .../2025-02-01/querypacks/version.go | 10 + .../2025-02-01/savedsearches/README.md | 89 + .../2025-02-01/savedsearches/client.go | 26 + .../savedsearches/id_savedsearch.go | 139 ++ .../savedsearches/id_savedsearch_test.go | 327 ++++ .../2025-02-01/savedsearches/id_workspace.go | 130 ++ .../savedsearches/id_workspace_test.go | 282 ++++ .../savedsearches/method_createorupdate.go | 57 + .../2025-02-01/savedsearches/method_delete.go | 46 + .../2025-02-01/savedsearches/method_get.go | 53 + .../savedsearches/method_listbyworkspace.go | 54 + .../savedsearches/model_savedsearch.go | 12 + .../model_savedsearcheslistresult.go | 8 + .../model_savedsearchproperties.go | 14 + .../2025-02-01/savedsearches/model_tag.go | 9 + .../2025-02-01/savedsearches/version.go | 10 + .../2025-02-01/storageinsights/README.md | 90 + .../2025-02-01/storageinsights/client.go | 26 + .../2025-02-01/storageinsights/constants.go | 51 + .../id_storageinsightconfig.go | 139 ++ .../id_storageinsightconfig_test.go | 327 ++++ .../storageinsights/id_workspace.go | 130 ++ .../storageinsights/id_workspace_test.go | 282 ++++ ...hod_storageinsightconfigscreateorupdate.go | 58 + .../method_storageinsightconfigsdelete.go | 47 + .../method_storageinsightconfigsget.go | 53 + ...od_storageinsightconfigslistbyworkspace.go | 105 ++ .../storageinsights/model_storageaccount.go | 9 + .../storageinsights/model_storageinsight.go | 13 + .../model_storageinsightproperties.go | 11 + .../model_storageinsightstatus.go | 9 + .../2025-02-01/storageinsights/predicates.go | 32 + .../2025-02-01/storageinsights/version.go | 10 + .../2025-02-01/tables/README.md | 130 ++ .../2025-02-01/tables/client.go | 26 + .../2025-02-01/tables/constants.go | 336 ++++ .../2025-02-01/tables/id_table.go | 139 ++ .../2025-02-01/tables/id_table_test.go | 327 ++++ .../2025-02-01/tables/id_workspace.go | 130 ++ .../2025-02-01/tables/id_workspace_test.go | 282 ++++ .../2025-02-01/tables/method_cancelsearch.go | 47 + .../tables/method_createorupdate.go | 75 + .../2025-02-01/tables/method_delete.go | 71 + .../2025-02-01/tables/method_get.go | 53 + .../tables/method_listbyworkspace.go | 54 + .../2025-02-01/tables/method_migrate.go | 47 + .../2025-02-01/tables/method_update.go | 75 + .../2025-02-01/tables/model_column.go | 14 + .../2025-02-01/tables/model_restoredlogs.go | 41 + .../tables/model_resultstatistics.go | 10 + .../2025-02-01/tables/model_schema.go | 18 + .../2025-02-01/tables/model_searchresults.go | 44 + .../2025-02-01/tables/model_table.go | 16 + .../tables/model_tableproperties.go | 19 + .../tables/model_tableslistresult.go | 8 + .../2025-02-01/tables/version.go | 10 + .../2025-02-01/workspaces/README.md | 300 ++++ .../2025-02-01/workspaces/client.go | 26 + .../2025-02-01/workspaces/constants.go | 445 +++++ .../2025-02-01/workspaces/id_gateway.go | 139 ++ .../2025-02-01/workspaces/id_gateway_test.go | 327 ++++ .../workspaces/id_intelligencepack.go | 139 ++ .../workspaces/id_intelligencepack_test.go | 327 ++++ .../2025-02-01/workspaces/id_operation.go | 139 ++ .../workspaces/id_operation_test.go | 327 ++++ .../2025-02-01/workspaces/id_workspace.go | 130 ++ .../workspaces/id_workspace_test.go | 282 ++++ .../workspaces/method_createorupdate.go | 76 + .../2025-02-01/workspaces/method_delete.go | 100 ++ .../workspaces/method_gatewaysdelete.go | 46 + .../2025-02-01/workspaces/method_get.go | 53 + .../method_intelligencepacksdisable.go | 47 + .../method_intelligencepacksenable.go | 47 + .../method_intelligencepackslist.go | 54 + .../2025-02-01/workspaces/method_list.go | 55 + .../workspaces/method_listbyresourcegroup.go | 55 + .../workspaces/method_managementgroupslist.go | 54 + .../2025-02-01/workspaces/method_schemaget.go | 54 + .../method_sharedkeysgetsharedkeys.go | 54 + .../workspaces/method_sharedkeysregenerate.go | 54 + .../2025-02-01/workspaces/method_update.go | 57 + .../workspaces/method_usageslist.go | 54 + .../method_workspacepurgegetpurgestatus.go | 53 + .../workspaces/method_workspacepurgepurge.go | 58 + .../workspaces/model_coresummary.go | 9 + .../workspaces/model_intelligencepack.go | 10 + .../workspaces/model_managementgroup.go | 8 + .../model_managementgroupproperties.go | 45 + .../2025-02-01/workspaces/model_metricname.go | 9 + .../model_privatelinkscopedresource.go | 9 + .../model_searchgetschemaresponse.go | 9 + .../workspaces/model_searchmetadata.go | 54 + .../workspaces/model_searchmetadataschema.go | 9 + .../workspaces/model_searchschemavalue.go | 14 + .../2025-02-01/workspaces/model_searchsort.go | 9 + .../2025-02-01/workspaces/model_sharedkeys.go | 9 + .../workspaces/model_usagemetric.go | 31 + .../2025-02-01/workspaces/model_workspace.go | 21 + .../workspaces/model_workspacecapping.go | 10 + .../model_workspacefailoverproperties.go | 27 + .../workspaces/model_workspacefeatures.go | 13 + ...del_workspacelistmanagementgroupsresult.go | 8 + .../workspaces/model_workspacelistresult.go | 8 + .../model_workspacelistusagesresult.go | 8 + .../workspaces/model_workspacepatch.go | 18 + .../workspaces/model_workspaceproperties.go | 52 + .../workspaces/model_workspacepurgebody.go | 9 + .../model_workspacepurgebodyfilters.go | 11 + .../model_workspacepurgeresponse.go | 8 + .../model_workspacepurgestatusresponse.go | 8 + .../model_workspacereplicationproperties.go | 42 + .../workspaces/model_workspacesku.go | 28 + .../2025-02-01/workspaces/version.go | 10 + .../accesspolicyassignments/README.md | 82 + .../accesspolicyassignments/client.go | 26 + .../accesspolicyassignments/constants.go | 63 + .../id_accesspolicyassignment.go | 148 ++ .../id_accesspolicyassignment_test.go | 372 +++++ .../accesspolicyassignments/id_database.go | 139 ++ .../id_database_test.go | 327 ++++ ...thod_accesspolicyassignmentcreateupdate.go | 75 + .../method_accesspolicyassignmentdelete.go | 70 + .../method_accesspolicyassignmentget.go | 53 + .../method_accesspolicyassignmentlist.go | 105 ++ .../model_accesspolicyassignment.go | 11 + .../model_accesspolicyassignmentproperties.go | 10 + ...el_accesspolicyassignmentpropertiesuser.go | 8 + .../accesspolicyassignments/predicates.go | 27 + .../accesspolicyassignments/version.go | 10 + .../redisenterprise/2025-04-01/client.go | 64 + .../2025-04-01/databases/README.md | 291 ++++ .../2025-04-01/databases/client.go | 26 + .../2025-04-01/databases/constants.go | 542 ++++++ .../databases/id_accesspolicyassignment.go | 148 ++ .../id_accesspolicyassignment_test.go | 372 +++++ .../2025-04-01/databases/id_database.go | 139 ++ .../2025-04-01/databases/id_database_test.go | 327 ++++ .../databases/id_redisenterprise.go | 130 ++ .../databases/id_redisenterprise_test.go | 282 ++++ ...thod_accesspolicyassignmentcreateupdate.go | 75 + .../method_accesspolicyassignmentdelete.go | 70 + .../method_accesspolicyassignmentget.go | 53 + .../method_accesspolicyassignmentlist.go | 105 ++ .../2025-04-01/databases/method_create.go | 75 + .../2025-04-01/databases/method_delete.go | 71 + .../2025-04-01/databases/method_export.go | 74 + .../2025-04-01/databases/method_flush.go | 74 + .../method_forcelinktoreplicationgroup.go | 73 + .../databases/method_forceunlink.go | 74 + .../2025-04-01/databases/method_get.go | 53 + .../2025-04-01/databases/method_import.go | 74 + .../databases/method_listbycluster.go | 105 ++ .../2025-04-01/databases/method_listkeys.go | 54 + .../databases/method_regeneratekey.go | 75 + .../2025-04-01/databases/method_update.go | 75 + .../databases/method_upgradedbredisversion.go | 69 + .../2025-04-01/databases/model_accesskeys.go | 9 + .../databases/model_accesspolicyassignment.go | 11 + .../model_accesspolicyassignmentproperties.go | 10 + ...el_accesspolicyassignmentpropertiesuser.go | 8 + .../2025-04-01/databases/model_database.go | 11 + .../databases/model_databaseproperties.go | 19 + .../model_databasepropertiesgeoreplication.go | 9 + .../databases/model_databaseupdate.go | 8 + .../model_exportclusterparameters.go | 8 + .../databases/model_flushparameters.go | 8 + .../databases/model_forcelinkparameters.go | 8 + ...model_forcelinkparametersgeoreplication.go | 9 + .../databases/model_forceunlinkparameters.go | 8 + .../model_importclusterparameters.go | 8 + .../databases/model_linkeddatabase.go | 9 + .../2025-04-01/databases/model_module.go | 10 + .../2025-04-01/databases/model_persistence.go | 11 + .../model_regeneratekeyparameters.go | 8 + .../2025-04-01/databases/predicates.go | 50 + .../2025-04-01/databases/version.go | 10 + .../privateendpointconnections/README.md | 81 + .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 101 ++ .../id_privateendpointconnection.go | 139 ++ .../id_privateendpointconnection_test.go | 327 ++++ .../id_redisenterprise.go | 130 ++ .../id_redisenterprise_test.go | 282 ++++ .../method_delete.go | 71 + .../privateendpointconnections/method_get.go | 53 + .../privateendpointconnections/method_list.go | 54 + .../privateendpointconnections/method_put.go | 74 + .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionlistresult.go | 8 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnections/version.go | 10 + .../2025-04-01/privatelinkresources/README.md | 36 + .../2025-04-01/privatelinkresources/client.go | 26 + .../id_redisenterprise.go | 130 ++ .../id_redisenterprise_test.go | 282 ++++ .../method_listbycluster.go | 54 + .../model_privatelinkresource.go | 11 + .../model_privatelinkresourcelistresult.go | 8 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/version.go | 10 + .../2025-04-01/redisenterprise/README.md | 388 +++++ .../2025-04-01/redisenterprise/client.go | 26 + .../2025-04-01/redisenterprise/constants.go | 1044 ++++++++++++ .../id_accesspolicyassignment.go | 148 ++ .../id_accesspolicyassignment_test.go | 372 +++++ .../2025-04-01/redisenterprise/id_database.go | 139 ++ .../redisenterprise/id_database_test.go | 327 ++++ .../redisenterprise/id_redisenterprise.go | 130 ++ .../id_redisenterprise_test.go | 282 ++++ ...thod_accesspolicyassignmentcreateupdate.go | 75 + .../method_accesspolicyassignmentdelete.go | 70 + .../method_accesspolicyassignmentget.go | 53 + .../method_accesspolicyassignmentlist.go | 105 ++ .../redisenterprise/method_create.go | 75 + .../redisenterprise/method_databasescreate.go | 75 + .../redisenterprise/method_databasesdelete.go | 71 + .../redisenterprise/method_databasesexport.go | 74 + .../redisenterprise/method_databasesflush.go | 74 + ...od_databasesforcelinktoreplicationgroup.go | 73 + .../method_databasesforceunlink.go | 74 + .../redisenterprise/method_databasesget.go | 53 + .../redisenterprise/method_databasesimport.go | 74 + .../method_databaseslistbycluster.go | 105 ++ .../method_databaseslistkeys.go | 54 + .../method_databasesregeneratekey.go | 75 + .../redisenterprise/method_databasesupdate.go | 75 + .../method_databasesupgradedbredisversion.go | 69 + .../redisenterprise/method_delete.go | 71 + .../2025-04-01/redisenterprise/method_get.go | 53 + .../2025-04-01/redisenterprise/method_list.go | 106 ++ .../method_listbyresourcegroup.go | 106 ++ .../redisenterprise/method_update.go | 75 + .../redisenterprise/model_accesskeys.go | 9 + .../model_accesspolicyassignment.go | 11 + .../model_accesspolicyassignmentproperties.go | 10 + ...el_accesspolicyassignmentpropertiesuser.go | 8 + .../redisenterprise/model_cluster.go | 22 + .../model_clusterproperties.go | 16 + .../model_clusterpropertiesencryption.go | 8 + ...sencryptioncustomermanagedkeyencryption.go | 9 + ...edkeyencryptionkeyencryptionkeyidentity.go | 9 + .../redisenterprise/model_clusterupdate.go | 15 + .../redisenterprise/model_database.go | 11 + .../model_databaseproperties.go | 19 + .../model_databasepropertiesgeoreplication.go | 9 + .../redisenterprise/model_databaseupdate.go | 8 + .../model_exportclusterparameters.go | 8 + .../redisenterprise/model_flushparameters.go | 8 + .../model_forcelinkparameters.go | 8 + ...model_forcelinkparametersgeoreplication.go | 9 + .../model_forceunlinkparameters.go | 8 + .../model_importclusterparameters.go | 8 + .../redisenterprise/model_linkeddatabase.go | 9 + .../redisenterprise/model_module.go | 10 + .../redisenterprise/model_persistence.go | 11 + .../redisenterprise/model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../model_regeneratekeyparameters.go | 8 + .../2025-04-01/redisenterprise/model_sku.go | 9 + .../2025-04-01/redisenterprise/predicates.go | 78 + .../2025-04-01/redisenterprise/version.go | 10 + .../resources/2025-03-01/client.go | 54 + .../2025-03-01/deploymentoperations/README.md | 185 +++ .../2025-03-01/deploymentoperations/client.go | 26 + .../deploymentoperations/constants.go | 131 ++ .../deploymentoperations/id_deployment.go | 112 ++ .../id_deployment_test.go | 192 +++ .../id_deploymentoperation.go | 130 ++ .../id_deploymentoperation_test.go | 282 ++++ .../deploymentoperations/id_operation.go | 121 ++ .../deploymentoperations/id_operation_test.go | 237 +++ .../id_providerdeployment.go | 121 ++ .../id_providerdeployment_test.go | 237 +++ .../id_providers2deployment.go | 123 ++ .../id_providers2deployment_test.go | 267 +++ .../id_providers2deploymentoperation.go | 132 ++ .../id_providers2deploymentoperation_test.go | 312 ++++ .../id_resourcegroupdeployment.go | 128 ++ .../id_resourcegroupdeployment_test.go | 252 +++ .../id_resourcegroupdeploymentoperation.go | 137 ++ ...d_resourcegroupdeploymentoperation_test.go | 297 ++++ .../id_scopeddeployment.go | 120 ++ .../id_scopeddeployment_test.go | 222 +++ .../id_scopedoperation.go | 129 ++ .../id_scopedoperation_test.go | 267 +++ .../deploymentoperations/method_get.go | 53 + .../method_getatmanagementgroupscope.go | 53 + .../deploymentoperations/method_getatscope.go | 53 + .../method_getatsubscriptionscope.go | 53 + .../method_getattenantscope.go | 53 + .../deploymentoperations/method_list.go | 134 ++ .../method_listatmanagementgroupscope.go | 134 ++ .../method_listatscope.go | 134 ++ .../method_listatsubscriptionscope.go | 134 ++ .../method_listattenantscope.go | 134 ++ .../model_deploymentextensionconfigitem.go | 10 + .../model_deploymentextensiondefinition.go | 12 + .../model_deploymentoperation.go | 10 + .../model_deploymentoperationproperties.go | 35 + .../model_erroradditionalinfo.go | 9 + .../model_errorresponse.go | 12 + .../deploymentoperations/model_httpmessage.go | 8 + .../model_keyvaultparameterreference.go | 10 + .../model_keyvaultreference.go | 8 + .../model_statusmessage.go | 9 + .../model_targetresource.go | 14 + .../deploymentoperations/predicates.go | 22 + .../deploymentoperations/version.go | 10 + .../2025-03-01/deployments/README.md | 740 +++++++++ .../2025-03-01/deployments/client.go | 26 + .../2025-03-01/deployments/constants.go | 730 +++++++++ .../2025-03-01/deployments/id_deployment.go | 112 ++ .../deployments/id_deployment_test.go | 192 +++ .../deployments/id_providerdeployment.go | 121 ++ .../deployments/id_providerdeployment_test.go | 237 +++ .../deployments/id_providers2deployment.go | 123 ++ .../id_providers2deployment_test.go | 267 +++ .../id_resourcegroupproviderdeployment.go | 130 ++ ...id_resourcegroupproviderdeployment_test.go | 282 ++++ .../deployments/id_scopeddeployment.go | 120 ++ .../deployments/id_scopeddeployment_test.go | 222 +++ .../method_calculatetemplatehash.go | 57 + .../2025-03-01/deployments/method_cancel.go | 47 + .../method_cancelatmanagementgroupscope.go | 47 + .../deployments/method_cancelatscope.go | 47 + .../method_cancelatsubscriptionscope.go | 47 + .../deployments/method_cancelattenantscope.go | 47 + .../deployments/method_checkexistence.go | 46 + ...od_checkexistenceatmanagementgroupscope.go | 46 + .../method_checkexistenceatscope.go | 46 + ...ethod_checkexistenceatsubscriptionscope.go | 46 + .../method_checkexistenceattenantscope.go | 46 + .../deployments/method_createorupdate.go | 75 + ...od_createorupdateatmanagementgroupscope.go | 75 + .../method_createorupdateatscope.go | 75 + ...ethod_createorupdateatsubscriptionscope.go | 75 + .../method_createorupdateattenantscope.go | 75 + .../2025-03-01/deployments/method_delete.go | 70 + .../method_deleteatmanagementgroupscope.go | 70 + .../deployments/method_deleteatscope.go | 70 + .../method_deleteatsubscriptionscope.go | 70 + .../deployments/method_deleteattenantscope.go | 70 + .../deployments/method_exporttemplate.go | 54 + ...od_exporttemplateatmanagementgroupscope.go | 54 + .../method_exporttemplateatscope.go | 54 + ...ethod_exporttemplateatsubscriptionscope.go | 54 + .../method_exporttemplateattenantscope.go | 54 + .../2025-03-01/deployments/method_get.go | 53 + .../method_getatmanagementgroupscope.go | 53 + .../deployments/method_getatscope.go | 53 + .../method_getatsubscriptionscope.go | 53 + .../deployments/method_getattenantscope.go | 53 + .../method_listatmanagementgroupscope.go | 139 ++ .../deployments/method_listatscope.go | 139 ++ .../method_listatsubscriptionscope.go | 139 ++ .../deployments/method_listattenantscope.go | 138 ++ .../deployments/method_listbyresourcegroup.go | 139 ++ .../2025-03-01/deployments/method_validate.go | 75 + .../method_validateatmanagementgroupscope.go | 75 + .../deployments/method_validateatscope.go | 75 + .../method_validateatsubscriptionscope.go | 75 + .../method_validateattenantscope.go | 75 + .../2025-03-01/deployments/method_whatif.go | 75 + .../method_whatifatmanagementgroupscope.go | 75 + .../method_whatifatsubscriptionscope.go | 75 + .../deployments/method_whatifattenantscope.go | 75 + .../2025-03-01/deployments/model_alias.go | 13 + .../2025-03-01/deployments/model_aliaspath.go | 11 + .../deployments/model_aliaspathmetadata.go | 9 + .../deployments/model_aliaspattern.go | 10 + .../deployments/model_apiprofile.go | 9 + .../deployments/model_basicdependency.go | 10 + .../deployments/model_debugsetting.go | 8 + .../deployments/model_dependency.go | 11 + .../deployments/model_deployment.go | 10 + .../model_deploymentdiagnosticsdefinition.go | 12 + .../model_deploymentexportresult.go | 8 + .../deployments/model_deploymentextended.go | 13 + .../model_deploymentextensionconfigitem.go | 10 + .../model_deploymentextensiondefinition.go | 12 + .../deployments/model_deploymentparameter.go | 9 + .../deployments/model_deploymentproperties.go | 17 + .../model_deploymentpropertiesextended.go | 45 + .../model_deploymentvalidateresult.go | 12 + .../deployments/model_deploymentwhatif.go | 9 + .../model_deploymentwhatifproperties.go | 18 + .../model_deploymentwhatifsettings.go | 8 + .../deployments/model_erroradditionalinfo.go | 9 + .../deployments/model_errorresponse.go | 12 + .../model_expressionevaluationoptions.go | 8 + .../model_keyvaultparameterreference.go | 10 + .../deployments/model_keyvaultreference.go | 8 + .../deployments/model_onerrordeployment.go | 9 + .../model_onerrordeploymentextended.go | 10 + .../deployments/model_parameterslink.go | 9 + .../2025-03-01/deployments/model_provider.go | 13 + .../model_providerextendedlocation.go | 10 + .../deployments/model_providerresourcetype.go | 17 + .../deployments/model_resourcereference.go | 12 + .../deployments/model_scopeddeployment.go | 10 + .../model_scopeddeploymentwhatif.go | 9 + .../deployments/model_templatehashresult.go | 9 + .../deployments/model_templatelink.go | 12 + .../deployments/model_whatifchange.go | 16 + .../model_whatifoperationproperties.go | 10 + .../model_whatifoperationresult.go | 10 + .../deployments/model_whatifpropertychange.go | 12 + .../deployments/model_zonemapping.go | 13 + .../2025-03-01/deployments/predicates.go | 32 + .../2025-03-01/deployments/version.go | 10 + .../resources/2025-03-01/providers/README.md | 174 ++ .../resources/2025-03-01/providers/client.go | 26 + .../2025-03-01/providers/constants.go | 242 +++ .../2025-03-01/providers/id_provider.go | 110 ++ .../2025-03-01/providers/id_provider_test.go | 162 ++ .../2025-03-01/providers/id_providers2.go | 121 ++ .../providers/id_providers2_test.go | 237 +++ .../providers/id_subscriptionprovider.go | 119 ++ .../providers/id_subscriptionprovider_test.go | 207 +++ .../2025-03-01/providers/method_get.go | 83 + .../providers/method_getattenantscope.go | 83 + .../2025-03-01/providers/method_list.go | 135 ++ .../providers/method_listattenantscope.go | 134 ++ .../providers/method_providerpermissions.go | 105 ++ .../method_providerresourcetypeslist.go | 134 ++ .../2025-03-01/providers/method_register.go | 58 + .../method_registeratmanagementgroupscope.go | 47 + .../2025-03-01/providers/method_unregister.go | 54 + .../2025-03-01/providers/model_alias.go | 13 + .../2025-03-01/providers/model_aliaspath.go | 11 + .../providers/model_aliaspathmetadata.go | 9 + .../providers/model_aliaspattern.go | 10 + .../2025-03-01/providers/model_apiprofile.go | 9 + .../2025-03-01/providers/model_permission.go | 11 + .../2025-03-01/providers/model_provider.go | 13 + .../model_providerconsentdefinition.go | 8 + .../model_providerextendedlocation.go | 10 + .../providers/model_providerpermission.go | 11 + .../model_providerregistrationrequest.go | 8 + .../providers/model_providerresourcetype.go | 17 + .../providers/model_roledefinition.go | 12 + .../2025-03-01/providers/model_zonemapping.go | 13 + .../2025-03-01/providers/predicates.go | 68 + .../resources/2025-03-01/providers/version.go | 10 + .../2025-03-01/resourcegroups/README.md | 158 ++ .../2025-03-01/resourcegroups/client.go | 26 + .../2025-03-01/resourcegroups/constants.go | 51 + .../resourcegroups/method_checkexistence.go | 47 + .../resourcegroups/method_createorupdate.go | 59 + .../resourcegroups/method_delete.go | 100 ++ .../resourcegroups/method_exporttemplate.go | 76 + .../2025-03-01/resourcegroups/method_get.go | 54 + .../2025-03-01/resourcegroups/method_list.go | 139 ++ .../method_resourceslistbyresourcegroup.go | 143 ++ .../resourcegroups/method_update.go | 58 + .../model_erroradditionalinfo.go | 9 + .../resourcegroups/model_errorresponse.go | 12 + .../model_exporttemplaterequest.go | 10 + .../model_genericresourceexpanded.go | 54 + .../2025-03-01/resourcegroups/model_plan.go | 12 + .../resourcegroups/model_resourcegroup.go | 14 + .../model_resourcegroupexportresult.go | 10 + .../model_resourcegrouppatchable.go | 11 + .../model_resourcegroupproperties.go | 8 + .../2025-03-01/resourcegroups/model_sku.go | 13 + .../2025-03-01/resourcegroups/predicates.go | 95 ++ .../2025-03-01/resourcegroups/version.go | 10 + .../resources/2025-03-01/resources/README.md | 228 +++ .../resources/2025-03-01/resources/client.go | 26 + .../resources/method_checkexistence.go | 47 + .../resources/method_checkexistencebyid.go | 47 + .../resources/method_createorupdate.go | 77 + .../resources/method_createorupdatebyid.go | 77 + .../2025-03-01/resources/method_delete.go | 72 + .../2025-03-01/resources/method_deletebyid.go | 72 + .../2025-03-01/resources/method_get.go | 54 + .../2025-03-01/resources/method_getbyid.go | 54 + .../2025-03-01/resources/method_list.go | 143 ++ .../resources/method_moveresources.go | 75 + .../2025-03-01/resources/method_update.go | 76 + .../2025-03-01/resources/method_updatebyid.go | 76 + .../resources/method_validatemoveresources.go | 75 + .../resources/model_genericresource.go | 24 + .../model_genericresourceexpanded.go | 54 + .../2025-03-01/resources/model_plan.go | 12 + .../resources/model_resourcesmoveinfo.go | 9 + .../2025-03-01/resources/model_sku.go | 13 + .../2025-03-01/resources/predicates.go | 62 + .../resources/2025-03-01/resources/version.go | 10 + .../resources/2025-03-01/tags/README.md | 164 ++ .../resources/2025-03-01/tags/client.go | 26 + .../resources/2025-03-01/tags/constants.go | 54 + .../resources/2025-03-01/tags/id_tagname.go | 119 ++ .../2025-03-01/tags/id_tagname_test.go | 207 +++ .../resources/2025-03-01/tags/id_tagvalue.go | 128 ++ .../2025-03-01/tags/id_tagvalue_test.go | 252 +++ .../2025-03-01/tags/method_createorupdate.go | 54 + .../tags/method_createorupdateatscope.go | 76 + .../tags/method_createorupdatevalue.go | 54 + .../2025-03-01/tags/method_delete.go | 47 + .../2025-03-01/tags/method_deleteatscope.go | 71 + .../2025-03-01/tags/method_deletevalue.go | 47 + .../2025-03-01/tags/method_getatscope.go | 55 + .../resources/2025-03-01/tags/method_list.go | 106 ++ .../2025-03-01/tags/method_updateatscope.go | 76 + .../2025-03-01/tags/model_tagcount.go | 9 + .../2025-03-01/tags/model_tagdetails.go | 11 + .../resources/2025-03-01/tags/model_tags.go | 8 + .../tags/model_tagspatchresource.go | 9 + .../2025-03-01/tags/model_tagsresource.go | 11 + .../2025-03-01/tags/model_tagvalue.go | 10 + .../resources/2025-03-01/tags/predicates.go | 22 + .../resources/2025-03-01/tags/version.go | 10 + .../README.md | 88 + .../client.go | 26 + .../constants.go | 18 + .../method_createorupdate.go | 76 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../method_update.go | 76 + .../model_backupshorttermretentionpolicy.go | 11 + ...ackupshorttermretentionpolicyproperties.go | 9 + .../predicates.go | 27 + .../version.go | 10 + .../sql/2023-08-01/blobauditing/README.md | 229 +++ .../sql/2023-08-01/blobauditing/client.go | 26 + .../sql/2023-08-01/blobauditing/constants.go | 51 + ...abaseblobauditingpoliciescreateorupdate.go | 60 + .../method_databaseblobauditingpoliciesget.go | 55 + ...abaseblobauditingpolicieslistbydatabase.go | 106 ++ ...abaseblobauditingpoliciescreateorupdate.go | 60 + ...extendeddatabaseblobauditingpoliciesget.go | 55 + ...abaseblobauditingpolicieslistbydatabase.go | 106 ++ ...erverblobauditingpoliciescreateorupdate.go | 76 + ...d_extendedserverblobauditingpoliciesget.go | 55 + ...dserverblobauditingpolicieslistbyserver.go | 106 ++ ...erverblobauditingpoliciescreateorupdate.go | 76 + .../method_serverblobauditingpoliciesget.go | 55 + ..._serverblobauditingpolicieslistbyserver.go | 106 ++ .../model_databaseblobauditingpolicy.go | 12 + ...el_databaseblobauditingpolicyproperties.go | 17 + ...odel_extendeddatabaseblobauditingpolicy.go | 11 + ...deddatabaseblobauditingpolicyproperties.go | 18 + .../model_extendedserverblobauditingpolicy.go | 11 + ...endedserverblobauditingpolicyproperties.go | 19 + .../model_serverblobauditingpolicy.go | 11 + ...odel_serverblobauditingpolicyproperties.go | 18 + .../sql/2023-08-01/blobauditing/predicates.go | 101 ++ .../sql/2023-08-01/blobauditing/version.go | 10 + resource-manager/sql/2023-08-01/client.go | 1270 ++++++++++++++ .../README.md | 75 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 60 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ ...odel_advancedthreatprotectionproperties.go | 27 + .../model_databaseadvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../sql/2023-08-01/databaseadvisors/README.md | 74 + .../sql/2023-08-01/databaseadvisors/client.go | 26 + .../2023-08-01/databaseadvisors/constants.go | 351 ++++ .../databaseadvisors/id_databaseadvisor.go | 148 ++ .../id_databaseadvisor_test.go | 372 +++++ .../2023-08-01/databaseadvisors/method_get.go | 53 + .../databaseadvisors/method_listbydatabase.go | 84 + .../databaseadvisors/method_update.go | 57 + .../databaseadvisors/model_advisor.go | 13 + .../model_advisorproperties.go | 31 + .../model_recommendedaction.go | 13 + .../model_recommendedactionerrorinfo.go | 9 + .../model_recommendedactionimpactrecord.go | 12 + ...del_recommendedactionimplementationinfo.go | 9 + .../model_recommendedactionmetricinfo.go | 30 + .../model_recommendedactionproperties.go | 108 ++ .../model_recommendedactionstateinfo.go | 28 + .../2023-08-01/databaseadvisors/version.go | 10 + .../databaseautomatictuning/README.md | 58 + .../databaseautomatictuning/client.go | 26 + .../databaseautomatictuning/constants.go | 198 +++ .../databaseautomatictuning/method_get.go | 55 + .../databaseautomatictuning/method_update.go | 59 + .../model_automatictuningoptions.go | 11 + .../model_databaseautomatictuning.go | 11 + ...model_databaseautomatictuningproperties.go | 10 + .../databaseautomatictuning/version.go | 10 + .../sql/2023-08-01/databasecolumns/README.md | 71 + .../sql/2023-08-01/databasecolumns/client.go | 26 + .../2023-08-01/databasecolumns/constants.go | 191 +++ .../2023-08-01/databasecolumns/id_column.go | 166 ++ .../databasecolumns/id_column_test.go | 462 ++++++ .../2023-08-01/databasecolumns/id_table.go | 157 ++ .../databasecolumns/id_table_test.go | 417 +++++ .../2023-08-01/databasecolumns/method_get.go | 53 + .../databasecolumns/method_listbydatabase.go | 147 ++ .../databasecolumns/method_listbytable.go | 134 ++ .../databasecolumns/model_databasecolumn.go | 11 + .../model_databasecolumnproperties.go | 11 + .../2023-08-01/databasecolumns/predicates.go | 27 + .../sql/2023-08-01/databasecolumns/version.go | 10 + .../client.go | 26 + ..._databaseencryptionprotectorsrevalidate.go | 71 + .../version.go | 10 + .../client.go | 26 + ...thod_databaseencryptionprotectorsrevert.go | 71 + .../version.go | 10 + .../2023-08-01/databaseextensions/README.md | 71 + .../2023-08-01/databaseextensions/client.go | 26 + .../databaseextensions/constants.go | 95 ++ .../databaseextensions/id_extension.go | 148 ++ .../databaseextensions/id_extension_test.go | 372 +++++ .../method_createorupdate.go | 75 + .../databaseextensions/method_get.go | 46 + .../method_listbydatabase.go | 106 ++ .../model_databaseextensions.go | 11 + .../model_databaseextensionsproperties.go | 18 + ...l_importexportextensionsoperationresult.go | 11 + ...portextensionsoperationresultproperties.go | 17 + .../model_networkisolationsettings.go | 9 + ..._privateendpointconnectionrequeststatus.go | 10 + .../databaseextensions/predicates.go | 27 + .../2023-08-01/databaseextensions/version.go | 10 + .../2023-08-01/databaseoperations/README.md | 38 + .../2023-08-01/databaseoperations/client.go | 26 + .../databaseoperations/constants.go | 116 ++ .../method_listbydatabase.go | 106 ++ .../model_databaseoperation.go | 11 + .../model_databaseoperationproperties.go | 52 + .../databaseoperations/model_phasedetails.go | 9 + .../databaseoperations/predicates.go | 27 + .../2023-08-01/databaseoperations/version.go | 10 + .../databaserecommendedactions/README.md | 73 + .../databaserecommendedactions/client.go | 26 + .../databaserecommendedactions/constants.go | 210 +++ .../id_databaseadvisor.go | 148 ++ .../id_databaseadvisor_test.go | 372 +++++ .../id_recommendedaction.go | 157 ++ .../id_recommendedaction_test.go | 417 +++++ .../databaserecommendedactions/method_get.go | 53 + .../method_listbydatabaseadvisor.go | 54 + .../method_update.go | 57 + .../model_recommendedaction.go | 13 + .../model_recommendedactionerrorinfo.go | 9 + .../model_recommendedactionimpactrecord.go | 12 + ...del_recommendedactionimplementationinfo.go | 9 + .../model_recommendedactionmetricinfo.go | 30 + .../model_recommendedactionproperties.go | 108 ++ .../model_recommendedactionstateinfo.go | 28 + .../databaserecommendedactions/version.go | 10 + .../sql/2023-08-01/databases/README.md | 237 +++ .../sql/2023-08-01/databases/client.go | 26 + .../sql/2023-08-01/databases/constants.go | 689 ++++++++ .../databases/method_createorupdate.go | 77 + .../sql/2023-08-01/databases/method_delete.go | 72 + .../sql/2023-08-01/databases/method_export.go | 76 + .../2023-08-01/databases/method_failover.go | 100 ++ .../sql/2023-08-01/databases/method_get.go | 88 + .../sql/2023-08-01/databases/method_import.go | 76 + .../databases/method_listbyelasticpool.go | 106 ++ .../databases/method_listbyserver.go | 106 ++ .../method_listinaccessiblebyserver.go | 106 ++ .../sql/2023-08-01/databases/method_pause.go | 72 + .../sql/2023-08-01/databases/method_rename.go | 52 + .../sql/2023-08-01/databases/method_resume.go | 72 + .../sql/2023-08-01/databases/method_update.go | 76 + .../databases/method_upgradedatawarehouse.go | 71 + .../2023-08-01/databases/model_database.go | 21 + .../2023-08-01/databases/model_databasekey.go | 29 + .../databases/model_databaseproperties.go | 133 ++ .../databases/model_databaseupdate.go | 15 + .../model_databaseupdateproperties.go | 131 ++ .../model_exportdatabasedefinition.go | 14 + .../model_importexistingdatabasedefinition.go | 14 + .../model_importexportoperationresult.go | 11 + ...l_importexportoperationresultproperties.go | 17 + .../model_networkisolationsettings.go | 9 + ..._privateendpointconnectionrequeststatus.go | 10 + .../databases/model_resourcemovedefinition.go | 8 + .../sql/2023-08-01/databases/model_sku.go | 12 + .../sql/2023-08-01/databases/predicates.go | 42 + .../sql/2023-08-01/databases/version.go | 10 + .../sql/2023-08-01/databaseschemas/README.md | 54 + .../sql/2023-08-01/databaseschemas/client.go | 26 + .../2023-08-01/databaseschemas/id_schema.go | 148 ++ .../databaseschemas/id_schema_test.go | 372 +++++ .../2023-08-01/databaseschemas/method_get.go | 53 + .../databaseschemas/method_listbydatabase.go | 135 ++ .../databaseschemas/model_resource.go | 10 + .../2023-08-01/databaseschemas/predicates.go | 27 + .../sql/2023-08-01/databaseschemas/version.go | 10 + .../databasesecurityalertpolicies/README.md | 75 + .../databasesecurityalertpolicies/client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 60 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_databasesecurityalertpolicy.go | 16 + .../model_securityalertspolicyproperties.go | 33 + .../predicates.go | 27 + .../databasesecurityalertpolicies/version.go | 10 + .../README.md | 75 + .../client.go | 26 + .../method_createorupdate.go | 59 + .../method_get.go | 55 + ...method_listbysqlvulnerabilityassessment.go | 106 ++ ...sesqlvulnerabilityassessmentbaselineset.go | 16 + ...rabilityassessmentbaselinesetproperties.go | 8 + ...rabilityassessmentrulebaselinelistinput.go | 16 + ...sessmentrulebaselinelistinputproperties.go | 9 + .../predicates.go | 27 + .../version.go | 10 + .../client.go | 26 + .../method_execute.go | 71 + .../version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../id_baselinerule.go | 152 ++ .../id_baselinerule_test.go | 432 +++++ .../method_createorupdate.go | 57 + .../method_delete.go | 47 + .../method_get.go | 53 + .../method_listbybaseline.go | 106 ++ ...esqlvulnerabilityassessmentrulebaseline.go | 16 + ...ulnerabilityassessmentrulebaselineinput.go | 16 + ...tyassessmentrulebaselineinputproperties.go | 9 + ...abilityassessmentrulebaselineproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 53 + .../client.go | 26 + .../constants.go | 151 ++ .../id_scanscanresult.go | 159 ++ .../id_scanscanresult_test.go | 447 +++++ ...tyassessmentvulnerabilityassessmentscan.go | 150 ++ ...essmentvulnerabilityassessmentscan_test.go | 402 +++++ .../method_get.go | 53 + .../method_listbyscan.go | 105 ++ .../model_baseline.go | 27 + .../model_baselineadjustedresult.go | 11 + .../model_benchmarkreference.go | 9 + .../model_querycheck.go | 10 + .../model_remediation.go | 11 + ...erabilityassessmentscanresultproperties.go | 15 + ...l_sqlvulnerabilityassessmentscanresults.go | 16 + .../model_varule.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 54 + .../client.go | 26 + .../constants.go | 98 ++ ...tyassessmentvulnerabilityassessmentscan.go | 150 ++ ...essmentvulnerabilityassessmentscan_test.go | 402 +++++ .../method_get.go | 53 + ...ethod_listbysqlvulnerabilityassessments.go | 106 ++ ...del_sqlvulnerabilityassessmentscanerror.go | 9 + ...el_sqlvulnerabilityassessmentscanrecord.go | 16 + ...erabilityassessmentscanrecordproperties.go | 66 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 54 + .../client.go | 26 + .../constants.go | 51 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_sqlvulnerabilityassessment.go | 16 + ...vulnerabilityassessmentpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../sql/2023-08-01/databasetables/README.md | 53 + .../sql/2023-08-01/databasetables/client.go | 26 + .../2023-08-01/databasetables/constants.go | 54 + .../2023-08-01/databasetables/id_schema.go | 148 ++ .../databasetables/id_schema_test.go | 372 +++++ .../sql/2023-08-01/databasetables/id_table.go | 157 ++ .../databasetables/id_table_test.go | 417 +++++ .../2023-08-01/databasetables/method_get.go | 53 + .../databasetables/method_listbyschema.go | 134 ++ .../databasetables/model_databasetable.go | 11 + .../model_databasetableproperties.go | 9 + .../2023-08-01/databasetables/predicates.go | 27 + .../sql/2023-08-01/databasetables/version.go | 10 + .../sql/2023-08-01/databaseusages/README.md | 38 + .../sql/2023-08-01/databaseusages/client.go | 26 + .../databaseusages/method_listbydatabase.go | 106 ++ .../databaseusages/model_databaseusage.go | 11 + .../model_databaseusageproperties.go | 11 + .../2023-08-01/databaseusages/predicates.go | 27 + .../sql/2023-08-01/databaseusages/version.go | 10 + .../README.md | 73 + .../client.go | 26 + .../constants.go | 51 + .../id_baseline.go | 167 ++ .../id_baseline_test.go | 447 +++++ .../method_createorupdate.go | 57 + .../method_delete.go | 46 + .../method_get.go | 53 + ...basevulnerabilityassessmentrulebaseline.go | 11 + ...vulnerabilityassessmentrulebaselineitem.go | 8 + ...abilityassessmentrulebaselineproperties.go | 8 + .../version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../method_createorupdate.go | 60 + .../method_delete.go | 48 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_databasevulnerabilityassessment.go | 11 + ...tabasevulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 82 + .../client.go | 26 + .../constants.go | 98 ++ .../id_vulnerabilityassessmentscan.go | 150 ++ .../id_vulnerabilityassessmentscan_test.go | 402 +++++ .../method_export.go | 54 + .../method_get.go | 53 + .../method_initiatescan.go | 70 + .../method_listbydatabase.go | 106 ++ ...erabilityassessmentscanexportproperties.go | 8 + ...abasevulnerabilityassessmentscansexport.go | 11 + .../model_vulnerabilityassessmentscanerror.go | 9 + ...model_vulnerabilityassessmentscanrecord.go | 11 + ...erabilityassessmentscanrecordproperties.go | 45 + .../predicates.go | 27 + .../version.go | 10 + .../2023-08-01/datamaskingpolicies/README.md | 58 + .../2023-08-01/datamaskingpolicies/client.go | 26 + .../datamaskingpolicies/constants.go | 51 + .../method_createorupdate.go | 60 + .../datamaskingpolicies/method_get.go | 55 + .../model_datamaskingpolicy.go | 13 + .../model_datamaskingpolicyproperties.go | 11 + .../2023-08-01/datamaskingpolicies/version.go | 10 + .../sql/2023-08-01/datamaskingrules/README.md | 59 + .../sql/2023-08-01/datamaskingrules/client.go | 26 + .../2023-08-01/datamaskingrules/constants.go | 104 ++ .../id_datamaskingpolicyrule.go | 150 ++ .../id_datamaskingpolicyrule_test.go | 402 +++++ .../datamaskingrules/method_createorupdate.go | 58 + .../datamaskingrules/method_listbydatabase.go | 106 ++ .../datamaskingrules/model_datamaskingrule.go | 13 + .../model_datamaskingruleproperties.go | 19 + .../2023-08-01/datamaskingrules/predicates.go | 37 + .../2023-08-01/datamaskingrules/version.go | 10 + .../datawarehouseuseractivities/README.md | 54 + .../datawarehouseuseractivities/client.go | 26 + .../datawarehouseuseractivities/method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_datawarehouseuseractivities.go | 11 + ...l_datawarehouseuseractivitiesproperties.go | 8 + .../datawarehouseuseractivities/predicates.go | 27 + .../datawarehouseuseractivities/version.go | 10 + .../sql/2023-08-01/deletedservers/README.md | 83 + .../sql/2023-08-01/deletedservers/client.go | 26 + .../deletedservers/id_deletedserver.go | 130 ++ .../deletedservers/id_deletedserver_test.go | 282 ++++ .../2023-08-01/deletedservers/id_location.go | 121 ++ .../deletedservers/id_location_test.go | 237 +++ .../2023-08-01/deletedservers/method_get.go | 53 + .../2023-08-01/deletedservers/method_list.go | 106 ++ .../deletedservers/method_listbylocation.go | 105 ++ .../deletedservers/method_recover.go | 71 + .../deletedservers/model_deletedserver.go | 11 + .../model_deletedserverproperties.go | 29 + .../2023-08-01/deletedservers/predicates.go | 27 + .../sql/2023-08-01/deletedservers/version.go | 10 + .../distributedavailabilitygroups/README.md | 134 ++ .../distributedavailabilitygroups/client.go | 26 + .../constants.go | 382 +++++ .../id_distributedavailabilitygroup.go | 139 ++ .../id_distributedavailabilitygroup_test.go | 327 ++++ .../method_createorupdate.go | 76 + .../method_delete.go | 71 + .../method_failover.go | 75 + .../method_get.go | 53 + .../method_listbyinstance.go | 106 ++ .../method_setrole.go | 75 + .../method_update.go | 75 + .../model_certificateinfo.go | 27 + .../model_distributedavailabilitygroup.go | 11 + ...el_distributedavailabilitygroupdatabase.go | 94 ++ ..._distributedavailabilitygroupproperties.go | 18 + ...del_distributedavailabilitygroupsetrole.go | 9 + ...ibutedavailabilitygroupsfailoverrequest.go | 8 + .../predicates.go | 27 + .../distributedavailabilitygroups/version.go | 10 + .../elasticpooloperations/README.md | 54 + .../elasticpooloperations/client.go | 26 + .../elasticpooloperations/id_operation.go | 148 ++ .../id_operation_test.go | 372 +++++ .../elasticpooloperations/method_cancel.go | 47 + .../method_listbyelasticpool.go | 106 ++ .../model_elasticpooloperation.go | 11 + .../model_elasticpooloperationproperties.go | 51 + .../elasticpooloperations/predicates.go | 27 + .../elasticpooloperations/version.go | 10 + .../sql/2023-08-01/elasticpools/README.md | 112 ++ .../sql/2023-08-01/elasticpools/client.go | 26 + .../sql/2023-08-01/elasticpools/constants.go | 183 +++ .../elasticpools/method_createorupdate.go | 77 + .../2023-08-01/elasticpools/method_delete.go | 72 + .../elasticpools/method_failover.go | 71 + .../sql/2023-08-01/elasticpools/method_get.go | 54 + .../elasticpools/method_listbyserver.go | 135 ++ .../2023-08-01/elasticpools/method_update.go | 76 + .../elasticpools/model_elasticpool.go | 15 + .../model_elasticpoolperdatabasesettings.go | 10 + .../model_elasticpoolproperties.go | 37 + .../elasticpools/model_elasticpoolupdate.go | 10 + .../model_elasticpoolupdateproperties.go | 17 + .../sql/2023-08-01/elasticpools/model_sku.go | 12 + .../sql/2023-08-01/elasticpools/predicates.go | 37 + .../sql/2023-08-01/elasticpools/version.go | 10 + .../2023-08-01/encryptionprotectors/README.md | 83 + .../2023-08-01/encryptionprotectors/client.go | 26 + .../encryptionprotectors/constants.go | 51 + .../method_createorupdate.go | 76 + .../encryptionprotectors/method_get.go | 55 + .../method_listbyserver.go | 106 ++ .../encryptionprotectors/method_revalidate.go | 71 + .../model_encryptionprotector.go | 13 + .../model_encryptionprotectorproperties.go | 13 + .../encryptionprotectors/predicates.go | 37 + .../encryptionprotectors/version.go | 10 + .../2023-08-01/endpointcertificates/README.md | 54 + .../2023-08-01/endpointcertificates/client.go | 26 + .../id_endpointcertificate.go | 139 ++ .../id_endpointcertificate_test.go | 327 ++++ .../endpointcertificates/method_get.go | 53 + .../method_listbyinstance.go | 106 ++ .../model_endpointcertificate.go | 11 + .../model_endpointcertificateproperties.go | 8 + .../endpointcertificates/predicates.go | 27 + .../endpointcertificates/version.go | 10 + .../sql/2023-08-01/failovergroups/README.md | 136 ++ .../sql/2023-08-01/failovergroups/client.go | 26 + .../2023-08-01/failovergroups/constants.go | 174 ++ .../failovergroups/id_failovergroup.go | 139 ++ .../failovergroups/id_failovergroup_test.go | 327 ++++ .../failovergroups/method_createorupdate.go | 76 + .../failovergroups/method_delete.go | 71 + .../failovergroups/method_failover.go | 71 + .../method_forcefailoverallowdataloss.go | 71 + .../2023-08-01/failovergroups/method_get.go | 53 + .../failovergroups/method_listbyserver.go | 106 ++ .../method_tryplannedbeforeforcedfailover.go | 71 + .../failovergroups/method_update.go | 75 + .../failovergroups/model_failovergroup.go | 13 + .../model_failovergroupproperties.go | 14 + .../model_failovergroupreadonlyendpoint.go | 9 + .../model_failovergroupreadwriteendpoint.go | 9 + .../model_failovergroupupdate.go | 9 + .../model_failovergroupupdateproperties.go | 12 + .../failovergroups/model_partnerinfo.go | 10 + .../2023-08-01/failovergroups/predicates.go | 32 + .../sql/2023-08-01/failovergroups/version.go | 10 + .../sql/2023-08-01/firewallrules/README.md | 112 ++ .../sql/2023-08-01/firewallrules/client.go | 26 + .../firewallrules/id_firewallrule.go | 139 ++ .../firewallrules/id_firewallrule_test.go | 327 ++++ .../firewallrules/method_createorupdate.go | 58 + .../2023-08-01/firewallrules/method_delete.go | 47 + .../2023-08-01/firewallrules/method_get.go | 53 + .../firewallrules/method_listbyserver.go | 106 ++ .../firewallrules/method_replace.go | 60 + .../firewallrules/model_firewallrule.go | 11 + .../firewallrules/model_firewallrulelist.go | 8 + .../model_serverfirewallruleproperties.go | 9 + .../2023-08-01/firewallrules/predicates.go | 27 + .../sql/2023-08-01/firewallrules/version.go | 10 + .../2023-08-01/geobackuppolicies/README.md | 75 + .../2023-08-01/geobackuppolicies/client.go | 26 + .../2023-08-01/geobackuppolicies/constants.go | 51 + .../method_createorupdate.go | 60 + .../geobackuppolicies/method_get.go | 55 + .../geobackuppolicies/method_list.go | 106 ++ .../model_geobackuppolicy.go | 13 + .../model_geobackuppolicyproperties.go | 9 + .../geobackuppolicies/predicates.go | 37 + .../2023-08-01/geobackuppolicies/version.go | 10 + .../instancefailovergroups/README.md | 106 ++ .../instancefailovergroups/client.go | 26 + .../instancefailovergroups/constants.go | 174 ++ .../id_instancefailovergroup.go | 139 ++ .../id_instancefailovergroup_test.go | 327 ++++ .../id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../method_createorupdate.go | 76 + .../instancefailovergroups/method_delete.go | 71 + .../instancefailovergroups/method_failover.go | 71 + .../method_forcefailoverallowdataloss.go | 71 + .../instancefailovergroups/method_get.go | 53 + .../method_listbylocation.go | 105 ++ .../model_instancefailovergroup.go | 11 + .../model_instancefailovergroupproperties.go | 14 + ...l_instancefailovergroupreadonlyendpoint.go | 8 + ..._instancefailovergroupreadwriteendpoint.go | 9 + .../model_managedinstancepairinfo.go | 9 + .../model_partnerregioninfo.go | 9 + .../instancefailovergroups/predicates.go | 27 + .../instancefailovergroups/version.go | 10 + .../sql/2023-08-01/instancepools/README.md | 117 ++ .../sql/2023-08-01/instancepools/client.go | 26 + .../sql/2023-08-01/instancepools/constants.go | 51 + .../instancepools/id_instancepool.go | 130 ++ .../instancepools/id_instancepool_test.go | 282 ++++ .../instancepools/method_createorupdate.go | 76 + .../2023-08-01/instancepools/method_delete.go | 71 + .../2023-08-01/instancepools/method_get.go | 53 + .../2023-08-01/instancepools/method_list.go | 106 ++ .../method_listbyresourcegroup.go | 106 ++ .../2023-08-01/instancepools/method_update.go | 75 + .../instancepools/model_instancepool.go | 14 + .../model_instancepoolproperties.go | 12 + .../instancepools/model_instancepoolupdate.go | 10 + .../sql/2023-08-01/instancepools/model_sku.go | 12 + .../2023-08-01/instancepools/predicates.go | 32 + .../sql/2023-08-01/instancepools/version.go | 10 + .../2023-08-01/ipv6firewallrules/README.md | 91 + .../2023-08-01/ipv6firewallrules/client.go | 26 + .../ipv6firewallrules/id_ipv6firewallrule.go | 139 ++ .../id_ipv6firewallrule_test.go | 327 ++++ .../method_createorupdate.go | 58 + .../ipv6firewallrules/method_delete.go | 47 + .../ipv6firewallrules/method_get.go | 53 + .../ipv6firewallrules/method_listbyserver.go | 106 ++ .../model_ipv6firewallrule.go | 11 + .../model_ipv6serverfirewallruleproperties.go | 9 + .../ipv6firewallrules/predicates.go | 27 + .../2023-08-01/ipv6firewallrules/version.go | 10 + .../sql/2023-08-01/jobagents/README.md | 100 ++ .../sql/2023-08-01/jobagents/client.go | 26 + .../sql/2023-08-01/jobagents/constants.go | 107 ++ .../sql/2023-08-01/jobagents/id_jobagent.go | 139 ++ .../2023-08-01/jobagents/id_jobagent_test.go | 327 ++++ .../jobagents/method_createorupdate.go | 76 + .../sql/2023-08-01/jobagents/method_delete.go | 71 + .../sql/2023-08-01/jobagents/method_get.go | 53 + .../jobagents/method_listbyserver.go | 106 ++ .../sql/2023-08-01/jobagents/method_update.go | 75 + .../2023-08-01/jobagents/model_jobagent.go | 15 + .../jobagents/model_jobagentidentity.go | 10 + .../jobagents/model_jobagentproperties.go | 9 + .../jobagents/model_jobagentupdate.go | 10 + .../model_jobagentuserassignedidentity.go | 9 + .../sql/2023-08-01/jobagents/model_sku.go | 12 + .../sql/2023-08-01/jobagents/predicates.go | 32 + .../sql/2023-08-01/jobagents/version.go | 10 + .../sql/2023-08-01/jobcredentials/README.md | 90 + .../sql/2023-08-01/jobcredentials/client.go | 26 + .../jobcredentials/id_credential.go | 148 ++ .../jobcredentials/id_credential_test.go | 372 +++++ .../2023-08-01/jobcredentials/id_jobagent.go | 139 ++ .../jobcredentials/id_jobagent_test.go | 327 ++++ .../jobcredentials/method_createorupdate.go | 58 + .../jobcredentials/method_delete.go | 47 + .../2023-08-01/jobcredentials/method_get.go | 53 + .../jobcredentials/method_listbyagent.go | 105 ++ .../jobcredentials/model_jobcredential.go | 11 + .../model_jobcredentialproperties.go | 9 + .../2023-08-01/jobcredentials/predicates.go | 27 + .../sql/2023-08-01/jobcredentials/version.go | 10 + .../sql/2023-08-01/jobexecutions/README.md | 110 ++ .../sql/2023-08-01/jobexecutions/client.go | 26 + .../sql/2023-08-01/jobexecutions/constants.go | 175 ++ .../2023-08-01/jobexecutions/id_execution.go | 157 ++ .../jobexecutions/id_execution_test.go | 417 +++++ .../sql/2023-08-01/jobexecutions/id_job.go | 148 ++ .../2023-08-01/jobexecutions/id_job_test.go | 372 +++++ .../2023-08-01/jobexecutions/id_jobagent.go | 139 ++ .../jobexecutions/id_jobagent_test.go | 327 ++++ .../2023-08-01/jobexecutions/method_cancel.go | 47 + .../2023-08-01/jobexecutions/method_create.go | 71 + .../jobexecutions/method_createorupdate.go | 72 + .../2023-08-01/jobexecutions/method_get.go | 53 + .../jobexecutions/method_listbyagent.go | 158 ++ .../jobexecutions/method_listbyjob.go | 158 ++ .../jobexecutions/model_jobexecution.go | 11 + .../model_jobexecutionproperties.go | 74 + .../jobexecutions/model_jobexecutiontarget.go | 10 + .../2023-08-01/jobexecutions/predicates.go | 27 + .../sql/2023-08-01/jobexecutions/version.go | 10 + .../2023-08-01/jobprivateendpoints/README.md | 82 + .../2023-08-01/jobprivateendpoints/client.go | 26 + .../jobprivateendpoints/id_jobagent.go | 139 ++ .../jobprivateendpoints/id_jobagent_test.go | 327 ++++ .../jobprivateendpoints/id_privateendpoint.go | 148 ++ .../id_privateendpoint_test.go | 372 +++++ .../method_createorupdate.go | 76 + .../jobprivateendpoints/method_delete.go | 71 + .../jobprivateendpoints/method_get.go | 53 + .../jobprivateendpoints/method_listbyagent.go | 105 ++ .../model_jobprivateendpoint.go | 11 + .../model_jobprivateendpointproperties.go | 9 + .../jobprivateendpoints/predicates.go | 27 + .../2023-08-01/jobprivateendpoints/version.go | 10 + .../sql/2023-08-01/jobs/README.md | 90 + .../sql/2023-08-01/jobs/client.go | 26 + .../sql/2023-08-01/jobs/constants.go | 51 + .../sql/2023-08-01/jobs/id_job.go | 148 ++ .../sql/2023-08-01/jobs/id_job_test.go | 372 +++++ .../sql/2023-08-01/jobs/id_jobagent.go | 139 ++ .../sql/2023-08-01/jobs/id_jobagent_test.go | 327 ++++ .../2023-08-01/jobs/method_createorupdate.go | 58 + .../sql/2023-08-01/jobs/method_delete.go | 47 + .../sql/2023-08-01/jobs/method_get.go | 53 + .../sql/2023-08-01/jobs/method_listbyagent.go | 105 ++ .../sql/2023-08-01/jobs/model_job.go | 11 + .../2023-08-01/jobs/model_jobproperties.go | 10 + .../sql/2023-08-01/jobs/model_jobschedule.go | 42 + .../sql/2023-08-01/jobs/predicates.go | 27 + .../sql/2023-08-01/jobs/version.go | 10 + .../2023-08-01/jobstepexecutions/README.md | 53 + .../2023-08-01/jobstepexecutions/client.go | 26 + .../2023-08-01/jobstepexecutions/constants.go | 175 ++ .../jobstepexecutions/id_execution.go | 157 ++ .../jobstepexecutions/id_execution_test.go | 417 +++++ .../jobstepexecutions/id_executionstep.go | 166 ++ .../id_executionstep_test.go | 462 ++++++ .../jobstepexecutions/method_get.go | 53 + .../method_listbyjobexecution.go | 158 ++ .../jobstepexecutions/model_jobexecution.go | 11 + .../model_jobexecutionproperties.go | 74 + .../model_jobexecutiontarget.go | 10 + .../jobstepexecutions/predicates.go | 27 + .../2023-08-01/jobstepexecutions/version.go | 10 + .../sql/2023-08-01/jobsteps/README.md | 123 ++ .../sql/2023-08-01/jobsteps/client.go | 26 + .../sql/2023-08-01/jobsteps/constants.go | 124 ++ .../sql/2023-08-01/jobsteps/id_job.go | 148 ++ .../sql/2023-08-01/jobsteps/id_job_test.go | 372 +++++ .../sql/2023-08-01/jobsteps/id_step.go | 157 ++ .../sql/2023-08-01/jobsteps/id_step_test.go | 417 +++++ .../sql/2023-08-01/jobsteps/id_version.go | 157 ++ .../2023-08-01/jobsteps/id_version_test.go | 417 +++++ .../sql/2023-08-01/jobsteps/id_versionstep.go | 166 ++ .../jobsteps/id_versionstep_test.go | 462 ++++++ .../jobsteps/method_createorupdate.go | 58 + .../sql/2023-08-01/jobsteps/method_delete.go | 47 + .../sql/2023-08-01/jobsteps/method_get.go | 53 + .../jobsteps/method_getbyversion.go | 53 + .../2023-08-01/jobsteps/method_listbyjob.go | 105 ++ .../jobsteps/method_listbyversion.go | 105 ++ .../sql/2023-08-01/jobsteps/model_jobstep.go | 11 + .../jobsteps/model_jobstepaction.go | 10 + .../jobsteps/model_jobstepexecutionoptions.go | 12 + .../jobsteps/model_jobstepoutput.go | 15 + .../jobsteps/model_jobstepproperties.go | 13 + .../sql/2023-08-01/jobsteps/predicates.go | 27 + .../sql/2023-08-01/jobsteps/version.go | 10 + .../2023-08-01/jobtargetexecutions/README.md | 70 + .../2023-08-01/jobtargetexecutions/client.go | 26 + .../jobtargetexecutions/constants.go | 175 ++ .../jobtargetexecutions/id_execution.go | 157 ++ .../jobtargetexecutions/id_execution_test.go | 417 +++++ .../jobtargetexecutions/id_executionstep.go | 166 ++ .../id_executionstep_test.go | 462 ++++++ .../jobtargetexecutions/id_target.go | 175 ++ .../jobtargetexecutions/id_target_test.go | 507 ++++++ .../jobtargetexecutions/method_get.go | 53 + .../method_listbyjobexecution.go | 158 ++ .../jobtargetexecutions/method_listbystep.go | 158 ++ .../jobtargetexecutions/model_jobexecution.go | 11 + .../model_jobexecutionproperties.go | 74 + .../model_jobexecutiontarget.go | 10 + .../jobtargetexecutions/predicates.go | 27 + .../2023-08-01/jobtargetexecutions/version.go | 10 + .../sql/2023-08-01/jobtargetgroups/README.md | 90 + .../sql/2023-08-01/jobtargetgroups/client.go | 26 + .../2023-08-01/jobtargetgroups/constants.go | 101 ++ .../2023-08-01/jobtargetgroups/id_jobagent.go | 139 ++ .../jobtargetgroups/id_jobagent_test.go | 327 ++++ .../jobtargetgroups/id_targetgroup.go | 148 ++ .../jobtargetgroups/id_targetgroup_test.go | 372 +++++ .../jobtargetgroups/method_createorupdate.go | 58 + .../jobtargetgroups/method_delete.go | 47 + .../2023-08-01/jobtargetgroups/method_get.go | 53 + .../jobtargetgroups/method_listbyagent.go | 105 ++ .../jobtargetgroups/model_jobtarget.go | 14 + .../jobtargetgroups/model_jobtargetgroup.go | 11 + .../model_jobtargetgroupproperties.go | 8 + .../2023-08-01/jobtargetgroups/predicates.go | 27 + .../sql/2023-08-01/jobtargetgroups/version.go | 10 + .../sql/2023-08-01/jobversions/README.md | 53 + .../sql/2023-08-01/jobversions/client.go | 26 + .../sql/2023-08-01/jobversions/id_job.go | 148 ++ .../sql/2023-08-01/jobversions/id_job_test.go | 372 +++++ .../sql/2023-08-01/jobversions/id_version.go | 157 ++ .../2023-08-01/jobversions/id_version_test.go | 417 +++++ .../sql/2023-08-01/jobversions/method_get.go | 53 + .../jobversions/method_listbyjob.go | 105 ++ .../2023-08-01/jobversions/model_resource.go | 10 + .../sql/2023-08-01/jobversions/predicates.go | 27 + .../sql/2023-08-01/jobversions/version.go | 10 + .../2023-08-01/ledgerdigestuploads/README.md | 83 + .../2023-08-01/ledgerdigestuploads/client.go | 26 + .../ledgerdigestuploads/constants.go | 51 + .../method_createorupdate.go | 76 + .../ledgerdigestuploads/method_disable.go | 72 + .../ledgerdigestuploads/method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_ledgerdigestuploads.go | 11 + .../model_ledgerdigestuploadsproperties.go | 9 + .../ledgerdigestuploads/predicates.go | 27 + .../2023-08-01/ledgerdigestuploads/version.go | 10 + .../2023-08-01/locationcapabilities/README.md | 36 + .../2023-08-01/locationcapabilities/client.go | 26 + .../locationcapabilities/constants.go | 374 +++++ .../locationcapabilities/id_location.go | 121 ++ .../locationcapabilities/id_location_test.go | 237 +++ .../method_capabilitieslistbylocation.go | 83 + .../model_autopausedelaytimerange.go | 13 + .../model_editioncapability.go | 15 + .../model_elasticpooleditioncapability.go | 13 + ...erdatabasemaxperformancelevelcapability.go | 12 + ...erdatabaseminperformancelevelcapability.go | 11 + ...l_elasticpoolperformancelevelcapability.go | 23 + ...l_freelimitexhaustionbehaviorcapability.go | 9 + .../model_instancepooleditioncapability.go | 11 + .../model_instancepoolfamilycapability.go | 12 + .../model_instancepoolvcorescapability.go | 12 + .../model_jobagenteditioncapability.go | 11 + ...jobagentservicelevelobjectivecapability.go | 11 + .../model_jobagentversioncapability.go | 11 + .../model_licensetypecapability.go | 10 + .../model_locationcapabilities.go | 13 + .../model_logsizecapability.go | 9 + ...odel_maintenanceconfigurationcapability.go | 11 + .../model_managedinstanceeditioncapability.go | 13 + .../model_managedinstancefamilycapability.go | 14 + ...tancemaintenanceconfigurationcapability.go | 10 + .../model_managedinstancevcorescapability.go | 25 + .../model_managedinstanceversioncapability.go | 12 + .../model_maxlimitrangecapability.go | 12 + .../model_maxsizecapability.go | 9 + .../model_maxsizerangecapability.go | 13 + .../model_mincapacitycapability.go | 10 + ...odel_perdatabaseautopausedelaytimerange.go | 13 + .../model_performancelevelcapability.go | 9 + .../model_readscalecapability.go | 10 + .../model_serverversioncapability.go | 12 + .../model_serviceobjectivecapability.go | 24 + .../locationcapabilities/model_sku.go | 12 + .../model_storagecapability.go | 10 + .../model_zonepinningcapability.go | 10 + .../locationcapabilities/version.go | 10 + .../longtermretentionbackups/README.md | 280 ++++ .../longtermretentionbackups/client.go | 26 + .../longtermretentionbackups/constants.go | 142 ++ .../longtermretentionbackups/id_location.go | 121 ++ .../id_location_test.go | 237 +++ .../id_locationlongtermretentionserver.go | 139 ++ ...id_locationlongtermretentionserver_test.go | 327 ++++ ...etentionserverlongtermretentiondatabase.go | 148 ++ ...ionserverlongtermretentiondatabase_test.go | 372 +++++ .../id_longtermretentionbackup.go | 148 ++ .../id_longtermretentionbackup_test.go | 372 +++++ ...etentiondatabaselongtermretentionbackup.go | 157 ++ ...iondatabaselongtermretentionbackup_test.go | 417 +++++ .../id_longtermretentionserver.go | 130 ++ .../id_longtermretentionserver_test.go | 282 ++++ ...etentionserverlongtermretentiondatabase.go | 139 ++ ...ionserverlongtermretentiondatabase_test.go | 327 ++++ .../id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../method_changeaccesstier.go | 75 + .../method_changeaccesstierbyresourcegroup.go | 75 + .../longtermretentionbackups/method_copy.go | 75 + .../method_copybyresourcegroup.go | 75 + .../longtermretentionbackups/method_delete.go | 70 + .../method_deletebyresourcegroup.go | 70 + .../longtermretentionbackups/method_get.go | 53 + .../method_getbyresourcegroup.go | 53 + .../method_listbydatabase.go | 138 ++ .../method_listbylocation.go | 138 ++ .../method_listbyresourcegroupdatabase.go | 138 ++ .../method_listbyresourcegrouplocation.go | 138 ++ .../method_listbyresourcegroupserver.go | 138 ++ .../method_listbyserver.go | 138 ++ .../longtermretentionbackups/method_update.go | 75 + .../method_updatebyresourcegroup.go | 75 + ...termretentionbackupaccesstierparameters.go | 9 + ...l_copylongtermretentionbackupparameters.go | 8 + ...termretentionbackupparametersproperties.go | 13 + .../model_longtermretentionbackup.go | 11 + ..._longtermretentionbackupoperationresult.go | 11 + ...model_longtermretentionbackupproperties.go | 71 + ...gtermretentionoperationresultproperties.go | 14 + ...updatelongtermretentionbackupparameters.go | 8 + ...termretentionbackupparametersproperties.go | 8 + .../longtermretentionbackups/predicates.go | 27 + .../longtermretentionbackups/version.go | 10 + .../README.md | 178 ++ .../client.go | 26 + .../constants.go | 142 ++ .../id_location.go | 121 ++ .../id_location_test.go | 237 +++ ...ocationlongtermretentionmanagedinstance.go | 139 ++ ...onlongtermretentionmanagedinstance_test.go | 327 ++++ .../id_longtermretentiondatabase.go | 139 ++ .../id_longtermretentiondatabase_test.go | 327 ++++ ...elongtermretentionmanagedinstancebackup.go | 157 ++ ...termretentionmanagedinstancebackup_test.go | 417 +++++ .../id_longtermretentionmanagedinstance.go | 130 ++ ...d_longtermretentionmanagedinstance_test.go | 282 ++++ ..._longtermretentionmanagedinstancebackup.go | 148 ++ ...termretentionmanagedinstancebackup_test.go | 372 +++++ ...anagedinstancelongtermretentiondatabase.go | 148 ++ ...dinstancelongtermretentiondatabase_test.go | 372 +++++ .../id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../method_delete.go | 70 + .../method_deletebyresourcegroup.go | 70 + .../method_get.go | 53 + .../method_getbyresourcegroup.go | 53 + .../method_listbydatabase.go | 138 ++ .../method_listbyinstance.go | 138 ++ .../method_listbylocation.go | 150 ++ .../method_listbyresourcegroupdatabase.go | 138 ++ .../method_listbyresourcegroupinstance.go | 138 ++ .../method_listbyresourcegrouplocation.go | 150 ++ ..._managedinstancelongtermretentionbackup.go | 11 + ...stancelongtermretentionbackupproperties.go | 69 + .../predicates.go | 27 + .../version.go | 10 + .../longtermretentionpolicies/README.md | 71 + .../longtermretentionpolicies/client.go | 26 + .../method_createorupdate.go | 76 + .../longtermretentionpolicies/method_get.go | 55 + .../method_listbydatabase.go | 106 ++ ...l_baselongtermretentionpolicyproperties.go | 11 + .../model_longtermretentionpolicy.go | 11 + .../longtermretentionpolicies/predicates.go | 27 + .../longtermretentionpolicies/version.go | 10 + .../maintenancewindowoptions/README.md | 37 + .../maintenancewindowoptions/client.go | 26 + .../maintenancewindowoptions/constants.go | 66 + .../maintenancewindowoptions/method_get.go | 84 + .../model_maintenancewindowoptions.go | 11 + ...odel_maintenancewindowoptionsproperties.go | 14 + .../model_maintenancewindowtimerange.go | 10 + .../maintenancewindowoptions/version.go | 10 + .../2023-08-01/maintenancewindows/README.md | 58 + .../2023-08-01/maintenancewindows/client.go | 26 + .../maintenancewindows/constants.go | 66 + .../method_createorupdate.go | 81 + .../maintenancewindows/method_get.go | 84 + .../model_maintenancewindows.go | 11 + .../model_maintenancewindowsproperties.go | 8 + .../model_maintenancewindowtimerange.go | 10 + .../2023-08-01/maintenancewindows/version.go | 10 + .../README.md | 88 + .../client.go | 26 + .../method_createorupdate.go | 76 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../method_update.go | 76 + ...l_managedbackupshorttermretentionpolicy.go | 11 + ...ackupshorttermretentionpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 75 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 60 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ ...odel_advancedthreatprotectionproperties.go | 27 + ...manageddatabaseadvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../manageddatabasecolumns/README.md | 71 + .../manageddatabasecolumns/client.go | 26 + .../manageddatabasecolumns/constants.go | 191 +++ .../manageddatabasecolumns/id_schematable.go | 157 ++ .../id_schematable_test.go | 417 +++++ .../manageddatabasecolumns/id_tablecolumn.go | 166 ++ .../id_tablecolumn_test.go | 462 ++++++ .../manageddatabasecolumns/method_get.go | 53 + .../method_listbydatabase.go | 147 ++ .../method_listbytable.go | 134 ++ .../model_databasecolumn.go | 11 + .../model_databasecolumnproperties.go | 11 + .../manageddatabasecolumns/predicates.go | 27 + .../manageddatabasecolumns/version.go | 10 + .../manageddatabasemoveoperations/README.md | 37 + .../manageddatabasemoveoperations/client.go | 26 + .../constants.go | 104 ++ .../id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../method_listbylocation.go | 138 ++ ...odel_manageddatabasemoveoperationresult.go | 11 + ...eddatabasemoveoperationresultproperties.go | 41 + .../predicates.go | 27 + .../manageddatabasemoveoperations/version.go | 10 + .../manageddatabasequeries/README.md | 53 + .../manageddatabasequeries/client.go | 26 + .../manageddatabasequeries/constants.go | 98 ++ .../manageddatabasequeries/id_query.go | 148 ++ .../manageddatabasequeries/id_query_test.go | 372 +++++ .../manageddatabasequeries/method_get.go | 53 + .../method_listbyquery.go | 142 ++ .../model_managedinstancequery.go | 11 + .../model_querymetricinterval.go | 11 + .../model_querymetricproperties.go | 16 + .../model_queryproperties.go | 8 + .../model_querystatistics.go | 11 + .../model_querystatisticsproperties.go | 12 + .../manageddatabasequeries/predicates.go | 27 + .../manageddatabasequeries/version.go | 10 + .../manageddatabaserestoredetails/README.md | 37 + .../manageddatabaserestoredetails/client.go | 26 + .../method_get.go | 55 + ...tabaserestoredetailsbackupsetproperties.go | 43 + ...manageddatabaserestoredetailsproperties.go | 59 + ...del_manageddatabaserestoredetailsresult.go | 11 + ...estoredetailsunrestorablefileproperties.go | 8 + .../manageddatabaserestoredetails/version.go | 10 + .../sql/2023-08-01/manageddatabases/README.md | 185 +++ .../sql/2023-08-01/manageddatabases/client.go | 26 + .../2023-08-01/manageddatabases/constants.go | 213 +++ .../manageddatabases/method_cancelmove.go | 75 + .../manageddatabases/method_completemove.go | 75 + .../method_completerestore.go | 75 + .../manageddatabases/method_createorupdate.go | 77 + .../manageddatabases/method_delete.go | 72 + .../2023-08-01/manageddatabases/method_get.go | 54 + .../manageddatabases/method_listbyinstance.go | 106 ++ .../method_listinaccessiblebyinstance.go | 106 ++ .../manageddatabases/method_startmove.go | 75 + .../manageddatabases/method_update.go | 76 + ...model_completedatabaserestoredefinition.go | 8 + .../manageddatabases/model_manageddatabase.go | 13 + .../model_manageddatabasemovedefinition.go | 8 + .../model_manageddatabaseproperties.go | 71 + ...odel_manageddatabasestartmovedefinition.go | 9 + .../model_manageddatabaseupdate.go | 9 + .../2023-08-01/manageddatabases/predicates.go | 32 + .../2023-08-01/manageddatabases/version.go | 10 + .../manageddatabaseschemas/README.md | 54 + .../manageddatabaseschemas/client.go | 26 + .../id_databaseschema.go | 148 ++ .../id_databaseschema_test.go | 372 +++++ .../manageddatabaseschemas/method_get.go | 53 + .../method_listbydatabase.go | 135 ++ .../manageddatabaseschemas/model_resource.go | 10 + .../manageddatabaseschemas/predicates.go | 27 + .../manageddatabaseschemas/version.go | 10 + .../README.md | 75 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 60 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ ...odel_manageddatabasesecurityalertpolicy.go | 11 + .../model_securityalertpolicyproperties.go | 33 + .../predicates.go | 27 + .../version.go | 10 + .../manageddatabasesecurityevents/README.md | 38 + .../manageddatabasesecurityevents/client.go | 26 + .../constants.go | 54 + .../method_listbydatabase.go | 143 ++ .../model_securityevent.go | 11 + .../model_securityeventproperties.go | 34 + ...tyeventsqlinjectionadditionalproperties.go | 14 + .../predicates.go | 27 + .../manageddatabasesecurityevents/version.go | 10 + .../README.md | 199 +++ .../client.go | 26 + .../constants.go | 230 +++ ..._sensitivitylabelsensitivitylabelsource.go | 183 +++ ...itivitylabelsensitivitylabelsource_test.go | 507 ++++++ .../id_tablecolumn.go | 166 ++ .../id_tablecolumn_test.go | 462 ++++++ .../method_createorupdate.go | 59 + .../method_delete.go | 47 + .../method_disablerecommendation.go | 47 + .../method_enablerecommendation.go | 47 + .../method_get.go | 53 + .../method_listbydatabase.go | 135 ++ .../method_listcurrentbydatabase.go | 139 ++ .../method_listrecommendedbydatabase.go | 139 ++ ...abaserecommendedsensitivitylabelsupdate.go | 52 + .../method_update.go | 52 + ...model_recommendedsensitivitylabelupdate.go | 11 + ...l_recommendedsensitivitylabelupdatelist.go | 8 + ...mmendedsensitivitylabelupdateproperties.go | 11 + .../model_sensitivitylabel.go | 12 + .../model_sensitivitylabelproperties.go | 17 + .../model_sensitivitylabelupdate.go | 11 + .../model_sensitivitylabelupdatelist.go | 8 + .../model_sensitivitylabelupdateproperties.go | 12 + .../predicates.go | 32 + .../version.go | 10 + .../manageddatabasetables/README.md | 53 + .../manageddatabasetables/client.go | 26 + .../manageddatabasetables/constants.go | 54 + .../id_databaseschema.go | 148 ++ .../id_databaseschema_test.go | 372 +++++ .../manageddatabasetables/id_schematable.go | 157 ++ .../id_schematable_test.go | 417 +++++ .../manageddatabasetables/method_get.go | 53 + .../method_listbyschema.go | 134 ++ .../model_databasetable.go | 11 + .../model_databasetableproperties.go | 9 + .../manageddatabasetables/predicates.go | 27 + .../manageddatabasetables/version.go | 10 + .../README.md | 75 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 60 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_managedtransparentdataencryption.go | 11 + ...agedtransparentdataencryptionproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 73 + .../client.go | 26 + .../constants.go | 51 + .../id_baselinebaseline.go | 167 ++ .../id_baselinebaseline_test.go | 447 +++++ .../method_createorupdate.go | 57 + .../method_delete.go | 46 + .../method_get.go | 53 + ...basevulnerabilityassessmentrulebaseline.go | 11 + ...vulnerabilityassessmentrulebaselineitem.go | 8 + ...abilityassessmentrulebaselineproperties.go | 8 + .../version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../method_createorupdate.go | 60 + .../method_delete.go | 48 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_databasevulnerabilityassessment.go | 11 + ...tabasevulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 82 + .../client.go | 26 + .../constants.go | 98 ++ ...tyassessmentvulnerabilityassessmentscan.go | 150 ++ ...essmentvulnerabilityassessmentscan_test.go | 402 +++++ .../method_export.go | 54 + .../method_get.go | 53 + .../method_initiatescan.go | 70 + .../method_listbydatabase.go | 106 ++ ...erabilityassessmentscanexportproperties.go | 8 + ...abasevulnerabilityassessmentscansexport.go | 11 + .../model_vulnerabilityassessmentscanerror.go | 9 + ...model_vulnerabilityassessmentscanrecord.go | 11 + ...erabilityassessmentscanrecordproperties.go | 45 + .../predicates.go | 27 + .../version.go | 10 + .../managedinstanceadministrators/README.md | 83 + .../managedinstanceadministrators/client.go | 26 + .../constants.go | 48 + .../method_createorupdate.go | 77 + .../method_delete.go | 71 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ .../model_managedinstanceadministrator.go | 11 + ..._managedinstanceadministratorproperties.go | 11 + .../predicates.go | 27 + .../managedinstanceadministrators/version.go | 10 + .../README.md | 71 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 76 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ ...odel_advancedthreatprotectionproperties.go | 27 + ...managedinstanceadvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 83 + .../client.go | 26 + .../method_createorupdate.go | 77 + .../method_delete.go | 72 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ ...anagedinstanceazureadonlyauthentication.go | 11 + ...anagedinstanceazureadonlyauthproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../2023-08-01/managedinstancedtcs/README.md | 71 + .../2023-08-01/managedinstancedtcs/client.go | 26 + .../managedinstancedtcs/constants.go | 60 + .../method_createorupdate.go | 75 + .../managedinstancedtcs/method_get.go | 55 + .../method_listbymanagedinstance.go | 106 ++ .../model_managedinstancedtc.go | 11 + .../model_managedinstancedtcproperties.go | 12 + ...odel_managedinstancedtcsecuritysettings.go | 12 + ...transactionmanagercommunicationsettings.go | 10 + .../managedinstancedtcs/predicates.go | 27 + .../2023-08-01/managedinstancedtcs/version.go | 10 + .../README.md | 83 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 76 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ .../method_revalidate.go | 71 + ...odel_managedinstanceencryptionprotector.go | 12 + ...edinstanceencryptionprotectorproperties.go | 12 + .../predicates.go | 32 + .../version.go | 10 + .../2023-08-01/managedinstancekeys/README.md | 83 + .../2023-08-01/managedinstancekeys/client.go | 26 + .../managedinstancekeys/constants.go | 51 + .../id_managedinstancekey.go | 139 ++ .../id_managedinstancekey_test.go | 327 ++++ .../method_createorupdate.go | 76 + .../managedinstancekeys/method_delete.go | 71 + .../managedinstancekeys/method_get.go | 53 + .../method_listbyinstance.go | 135 ++ .../model_managedinstancekey.go | 12 + .../model_managedinstancekeyproperties.go | 30 + .../managedinstancekeys/predicates.go | 32 + .../2023-08-01/managedinstancekeys/version.go | 10 + .../README.md | 83 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 76 + .../method_delete.go | 72 + .../method_get.go | 55 + .../method_listbydatabase.go | 106 ++ ..._managedinstancelongtermretentionpolicy.go | 11 + ...stancelongtermretentionpolicyproperties.go | 12 + .../predicates.go | 27 + .../version.go | 10 + .../managedinstanceoperations/README.md | 38 + .../managedinstanceoperations/client.go | 26 + .../managedinstanceoperations/constants.go | 116 ++ .../method_listbymanagedinstance.go | 106 ++ .../model_managedinstanceoperation.go | 11 + ..._managedinstanceoperationparameterspair.go | 9 + ...odel_managedinstanceoperationproperties.go | 52 + .../model_managedinstanceoperationsteps.go | 10 + ..._upsertmanagedserveroperationparameters.go | 11 + ...eroperationstepwithestimatesandduration.go | 43 + .../managedinstanceoperations/predicates.go | 27 + .../managedinstanceoperations/version.go | 10 + .../README.md | 83 + .../client.go | 26 + ...anagedinstanceprivateendpointconnection.go | 139 ++ ...dinstanceprivateendpointconnection_test.go | 327 ++++ .../method_createorupdate.go | 75 + .../method_delete.go | 71 + .../method_get.go | 53 + .../method_listbymanagedinstance.go | 106 ++ ...anagedinstanceprivateendpointconnection.go | 11 + ...anceprivateendpointconnectionproperties.go | 10 + ..._managedinstanceprivateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 54 + .../client.go | 26 + .../id_managedinstanceprivatelinkresource.go | 139 ++ ...managedinstanceprivatelinkresource_test.go | 327 ++++ .../method_get.go | 53 + .../method_listbymanagedinstance.go | 106 ++ .../model_managedinstanceprivatelink.go | 11 + ...el_managedinstanceprivatelinkproperties.go | 10 + .../predicates.go | 27 + .../version.go | 10 + .../sql/2023-08-01/managedinstances/README.md | 216 +++ .../sql/2023-08-01/managedinstances/client.go | 26 + .../2023-08-01/managedinstances/constants.go | 834 ++++++++++ .../managedinstances/id_instancepool.go | 130 ++ .../managedinstances/id_instancepool_test.go | 282 ++++ .../managedinstances/method_createorupdate.go | 77 + .../managedinstances/method_delete.go | 72 + .../managedinstances/method_failover.go | 100 ++ .../2023-08-01/managedinstances/method_get.go | 84 + .../managedinstances/method_list.go | 135 ++ .../method_listbyinstancepool.go | 134 ++ .../method_listbymanagedinstance.go | 159 ++ .../method_listbyresourcegroup.go | 135 ++ ...undnetworkdependenciesbymanagedinstance.go | 106 ++ .../managedinstances/method_refreshstatus.go | 72 + .../managedinstances/method_start.go | 72 + .../managedinstances/method_stop.go | 72 + .../managedinstances/method_update.go | 76 + .../model_endpointdependency.go | 9 + .../managedinstances/model_endpointdetail.go | 8 + .../managedinstances/model_managedinstance.go | 19 + ...el_managedinstanceexternaladministrator.go | 13 + .../model_managedinstancepecproperty.go | 9 + ...anceprivateendpointconnectionproperties.go | 10 + ..._managedinstanceprivateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../model_managedinstanceproperties.go | 77 + .../model_managedinstanceupdate.go | 15 + .../model_outboundenvironmentendpoint.go | 9 + .../model_querymetricinterval.go | 11 + .../model_querymetricproperties.go | 16 + .../model_querystatisticsproperties.go | 12 + ...ternalgovernancestatusoperationresultmi.go | 11 + ...rnancestatusoperationresultpropertiesmi.go | 13 + .../model_serviceprincipal.go | 11 + .../2023-08-01/managedinstances/model_sku.go | 12 + .../managedinstances/model_topqueries.go | 14 + .../2023-08-01/managedinstances/predicates.go | 78 + .../2023-08-01/managedinstances/version.go | 10 + .../managedinstancetdecertificates/README.md | 38 + .../managedinstancetdecertificates/client.go | 26 + .../method_create.go | 75 + .../model_tdecertificate.go | 11 + .../model_tdecertificateproperties.go | 9 + .../managedinstancetdecertificates/version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../method_createorupdate.go | 60 + .../method_delete.go | 48 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ ..._managedinstancevulnerabilityassessment.go | 11 + ...stancevulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../version.go | 10 + .../managedledgerdigestuploads/README.md | 83 + .../managedledgerdigestuploads/client.go | 26 + .../managedledgerdigestuploads/constants.go | 51 + .../method_createorupdate.go | 76 + .../method_disable.go | 72 + .../managedledgerdigestuploads/method_get.go | 55 + .../method_listbydatabase.go | 106 ++ .../model_managedledgerdigestuploads.go | 11 + ...el_managedledgerdigestuploadsproperties.go | 9 + .../managedledgerdigestuploads/predicates.go | 27 + .../managedledgerdigestuploads/version.go | 10 + .../README.md | 87 + .../client.go | 26 + ...anagedinstancerestorabledroppeddatabase.go | 139 ++ ...dinstancerestorabledroppeddatabase_test.go | 327 ++++ .../method_createorupdate.go | 75 + .../method_get.go | 54 + .../method_listbyrestorabledroppeddatabase.go | 105 ++ .../method_update.go | 75 + ...l_managedbackupshorttermretentionpolicy.go | 11 + ...ackupshorttermretentionpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../managedserverdnsaliases/README.md | 100 ++ .../managedserverdnsaliases/client.go | 26 + .../id_managedinstancednsalias.go | 139 ++ .../id_managedinstancednsalias_test.go | 327 ++++ .../managedserverdnsaliases/method_acquire.go | 75 + .../method_createorupdate.go | 76 + .../managedserverdnsaliases/method_delete.go | 71 + .../managedserverdnsaliases/method_get.go | 53 + .../method_listbymanagedinstance.go | 106 ++ .../model_managedserverdnsalias.go | 11 + .../model_managedserverdnsaliasacquisition.go | 8 + .../model_managedserverdnsaliascreation.go | 8 + .../model_managedserverdnsaliasproperties.go | 9 + .../managedserverdnsaliases/predicates.go | 27 + .../managedserverdnsaliases/version.go | 10 + .../README.md | 71 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 76 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ .../model_managedserversecurityalertpolicy.go | 16 + .../model_securityalertspolicyproperties.go | 33 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 66 + .../client.go | 26 + ...d_networksecurityperimeterconfiguration.go | 139 ++ ...worksecurityperimeterconfiguration_test.go | 327 ++++ .../method_get.go | 53 + .../method_listbyserver.go | 106 ++ .../method_reconcile.go | 71 + ...l_networksecurityperimeterconfiguration.go | 11 + ...ecurityperimeterconfigurationproperties.go | 12 + .../model_nspconfigaccessrule.go | 9 + .../model_nspconfigaccessruleproperties.go | 13 + .../model_nspconfigassociation.go | 9 + ...l_nspconfignetworksecurityperimeterrule.go | 10 + .../model_nspconfigperimeter.go | 10 + .../model_nspconfigprofile.go | 10 + .../model_nspprovisioningissue.go | 9 + .../model_nspprovisioningissueproperties.go | 12 + .../predicates.go | 27 + .../version.go | 10 + .../outboundfirewallrules/README.md | 78 + .../outboundfirewallrules/client.go | 26 + .../id_outboundfirewallrule.go | 139 ++ .../id_outboundfirewallrule_test.go | 327 ++++ .../method_createorupdate.go | 72 + .../outboundfirewallrules/method_delete.go | 71 + .../outboundfirewallrules/method_get.go | 53 + .../method_listbyserver.go | 106 ++ .../model_outboundfirewallrule.go | 11 + .../model_outboundfirewallruleproperties.go | 8 + .../outboundfirewallrules/predicates.go | 27 + .../outboundfirewallrules/version.go | 10 + .../privateendpointconnections/README.md | 83 + .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 145 ++ .../id_privateendpointconnection.go | 139 ++ .../id_privateendpointconnection_test.go | 327 ++++ .../method_createorupdate.go | 75 + .../method_delete.go | 71 + .../privateendpointconnections/method_get.go | 53 + .../method_listbyserver.go | 106 ++ .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionproperties.go | 11 + .../model_privateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../privateendpointconnections/predicates.go | 27 + .../privateendpointconnections/version.go | 10 + .../2023-08-01/privatelinkresources/README.md | 54 + .../2023-08-01/privatelinkresources/client.go | 26 + .../id_privatelinkresource.go | 139 ++ .../id_privatelinkresource_test.go | 327 ++++ .../privatelinkresources/method_get.go | 53 + .../method_listbyserver.go | 106 ++ .../model_privatelinkresource.go | 11 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/predicates.go | 27 + .../privatelinkresources/version.go | 10 + .../2023-08-01/recoverabledatabases/README.md | 54 + .../2023-08-01/recoverabledatabases/client.go | 26 + .../recoverabledatabases/constants.go | 48 + .../id_recoverabledatabase.go | 139 ++ .../id_recoverabledatabase_test.go | 327 ++++ .../recoverabledatabases/method_get.go | 87 + .../method_listbyserver.go | 106 ++ .../recoverabledatabases/model_databasekey.go | 29 + .../model_recoverabledatabase.go | 11 + .../model_recoverabledatabaseproperties.go | 30 + .../recoverabledatabases/predicates.go | 27 + .../recoverabledatabases/version.go | 10 + .../recoverablemanageddatabases/README.md | 54 + .../recoverablemanageddatabases/client.go | 26 + .../id_managedinstancerecoverabledatabase.go | 139 ++ ...managedinstancerecoverabledatabase_test.go | 327 ++++ .../recoverablemanageddatabases/method_get.go | 53 + .../method_listbyinstance.go | 106 ++ .../model_recoverablemanageddatabase.go | 11 + ...el_recoverablemanageddatabaseproperties.go | 8 + .../recoverablemanageddatabases/predicates.go | 27 + .../recoverablemanageddatabases/version.go | 10 + .../sql/2023-08-01/replicationlinks/README.md | 141 ++ .../sql/2023-08-01/replicationlinks/client.go | 26 + .../2023-08-01/replicationlinks/constants.go | 151 ++ .../replicationlinks/id_replicationlink.go | 148 ++ .../id_replicationlink_test.go | 372 +++++ .../replicationlinks/method_createorupdate.go | 75 + .../replicationlinks/method_delete.go | 70 + .../replicationlinks/method_failover.go | 71 + .../method_failoverallowdataloss.go | 71 + .../2023-08-01/replicationlinks/method_get.go | 53 + .../replicationlinks/method_listbydatabase.go | 106 ++ .../replicationlinks/method_listbyserver.go | 106 ++ .../replicationlinks/method_update.go | 75 + .../replicationlinks/model_replicationlink.go | 11 + .../model_replicationlinkproperties.go | 37 + .../model_replicationlinkupdate.go | 11 + .../model_replicationlinkupdateproperties.go | 8 + .../2023-08-01/replicationlinks/predicates.go | 27 + .../2023-08-01/replicationlinks/version.go | 10 + .../restorabledroppeddatabases/README.md | 54 + .../restorabledroppeddatabases/client.go | 26 + .../restorabledroppeddatabases/constants.go | 95 ++ .../id_restorabledroppeddatabase.go | 139 ++ .../id_restorabledroppeddatabase_test.go | 327 ++++ .../restorabledroppeddatabases/method_get.go | 87 + .../method_listbyserver.go | 106 ++ .../model_databasekey.go | 29 + .../model_restorabledroppeddatabase.go | 14 + ...del_restorabledroppeddatabaseproperties.go | 56 + .../restorabledroppeddatabases/model_sku.go | 12 + .../restorabledroppeddatabases/predicates.go | 32 + .../restorabledroppeddatabases/version.go | 10 + .../README.md | 54 + .../client.go | 26 + ...anagedinstancerestorabledroppeddatabase.go | 139 ++ ...dinstancerestorabledroppeddatabase_test.go | 327 ++++ .../method_get.go | 53 + .../method_listbyinstance.go | 106 ++ .../model_restorabledroppedmanageddatabase.go | 13 + ...torabledroppedmanageddatabaseproperties.go | 53 + .../predicates.go | 32 + .../version.go | 10 + .../sql/2023-08-01/restorepoints/README.md | 87 + .../sql/2023-08-01/restorepoints/client.go | 26 + .../sql/2023-08-01/restorepoints/constants.go | 51 + .../restorepoints/id_restorepoint.go | 148 ++ .../restorepoints/id_restorepoint_test.go | 372 +++++ .../2023-08-01/restorepoints/method_create.go | 77 + .../2023-08-01/restorepoints/method_delete.go | 46 + .../2023-08-01/restorepoints/method_get.go | 53 + .../restorepoints/method_listbydatabase.go | 106 ++ ...el_createdatabaserestorepointdefinition.go | 8 + .../restorepoints/model_restorepoint.go | 12 + .../model_restorepointproperties.go | 41 + .../2023-08-01/restorepoints/predicates.go | 32 + .../sql/2023-08-01/restorepoints/version.go | 10 + .../2023-08-01/sensitivitylabels/README.md | 199 +++ .../2023-08-01/sensitivitylabels/client.go | 26 + .../2023-08-01/sensitivitylabels/constants.go | 230 +++ .../2023-08-01/sensitivitylabels/id_column.go | 166 ++ .../sensitivitylabels/id_column_test.go | 462 ++++++ .../id_sensitivitylabelsource.go | 183 +++ .../id_sensitivitylabelsource_test.go | 507 ++++++ .../method_createorupdate.go | 59 + .../sensitivitylabels/method_delete.go | 47 + .../method_disablerecommendation.go | 47 + .../method_enablerecommendation.go | 47 + .../sensitivitylabels/method_get.go | 53 + .../method_listbydatabase.go | 135 ++ .../method_listcurrentbydatabase.go | 139 ++ .../method_listrecommendedbydatabase.go | 139 ++ ...thod_recommendedsensitivitylabelsupdate.go | 52 + .../sensitivitylabels/method_update.go | 52 + ...model_recommendedsensitivitylabelupdate.go | 11 + ...l_recommendedsensitivitylabelupdatelist.go | 8 + ...mmendedsensitivitylabelupdateproperties.go | 11 + .../model_sensitivitylabel.go | 12 + .../model_sensitivitylabelproperties.go | 17 + .../model_sensitivitylabelupdate.go | 11 + .../model_sensitivitylabelupdatelist.go | 8 + .../model_sensitivitylabelupdateproperties.go | 12 + .../sensitivitylabels/predicates.go | 32 + .../2023-08-01/sensitivitylabels/version.go | 10 + .../README.md | 71 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 76 + .../method_get.go | 55 + .../method_listbyserver.go | 106 ++ ...odel_advancedthreatprotectionproperties.go | 27 + .../model_serveradvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../sql/2023-08-01/serveradvisors/README.md | 74 + .../sql/2023-08-01/serveradvisors/client.go | 26 + .../2023-08-01/serveradvisors/constants.go | 351 ++++ .../2023-08-01/serveradvisors/id_advisor.go | 139 ++ .../serveradvisors/id_advisor_test.go | 327 ++++ .../2023-08-01/serveradvisors/method_get.go | 53 + .../serveradvisors/method_listbyserver.go | 84 + .../serveradvisors/method_update.go | 57 + .../serveradvisors/model_advisor.go | 13 + .../serveradvisors/model_advisorproperties.go | 31 + .../serveradvisors/model_recommendedaction.go | 13 + .../model_recommendedactionerrorinfo.go | 9 + .../model_recommendedactionimpactrecord.go | 12 + ...del_recommendedactionimplementationinfo.go | 9 + .../model_recommendedactionmetricinfo.go | 30 + .../model_recommendedactionproperties.go | 108 ++ .../model_recommendedactionstateinfo.go | 28 + .../sql/2023-08-01/serveradvisors/version.go | 10 + .../serverautomatictuning/README.md | 58 + .../serverautomatictuning/client.go | 26 + .../serverautomatictuning/constants.go | 183 +++ .../serverautomatictuning/method_get.go | 55 + .../serverautomatictuning/method_update.go | 59 + .../model_automatictuningserveroptions.go | 11 + .../model_automatictuningserverproperties.go | 10 + .../model_serverautomatictuning.go | 11 + .../serverautomatictuning/version.go | 10 + .../serverazureadadministrators/README.md | 83 + .../serverazureadadministrators/client.go | 26 + .../serverazureadadministrators/constants.go | 48 + .../method_createorupdate.go | 77 + .../method_delete.go | 72 + .../serverazureadadministrators/method_get.go | 55 + .../method_listbyserver.go | 106 ++ .../model_administratorproperties.go | 12 + .../model_serverazureadadministrator.go | 11 + .../serverazureadadministrators/predicates.go | 27 + .../serverazureadadministrators/version.go | 10 + .../README.md | 83 + .../client.go | 26 + .../method_createorupdate.go | 77 + .../method_delete.go | 72 + .../method_get.go | 55 + .../method_listbyserver.go | 106 ++ .../model_azureadonlyauthproperties.go | 8 + .../model_serverazureadonlyauthentication.go | 11 + .../predicates.go | 27 + .../version.go | 10 + .../serverconfigurationoptions/README.md | 71 + .../serverconfigurationoptions/client.go | 26 + .../serverconfigurationoptions/constants.go | 60 + .../method_createorupdate.go | 75 + .../serverconfigurationoptions/method_get.go | 55 + .../method_listbymanagedinstance.go | 106 ++ .../model_serverconfigurationoption.go | 11 + ...del_serverconfigurationoptionproperties.go | 9 + .../serverconfigurationoptions/predicates.go | 27 + .../serverconfigurationoptions/version.go | 10 + .../serverconnectionpolicies/README.md | 71 + .../serverconnectionpolicies/client.go | 26 + .../serverconnectionpolicies/constants.go | 54 + .../method_createorupdate.go | 76 + .../serverconnectionpolicies/method_get.go | 55 + .../method_listbyserver.go | 106 ++ .../model_serverconnectionpolicy.go | 13 + .../model_serverconnectionpolicyproperties.go | 8 + .../serverconnectionpolicies/predicates.go | 37 + .../serverconnectionpolicies/version.go | 10 + .../2023-08-01/serverdevopsaudit/README.md | 71 + .../2023-08-01/serverdevopsaudit/client.go | 26 + .../2023-08-01/serverdevopsaudit/constants.go | 51 + .../method_settingscreateorupdate.go | 76 + .../serverdevopsaudit/method_settingsget.go | 55 + .../method_settingslistbyserver.go | 106 ++ .../model_serverdevopsauditingsettings.go | 16 + ...del_serverdevopsauditsettingsproperties.go | 13 + .../serverdevopsaudit/predicates.go | 27 + .../2023-08-01/serverdevopsaudit/version.go | 10 + .../sql/2023-08-01/serverdnsaliases/README.md | 95 ++ .../sql/2023-08-01/serverdnsaliases/client.go | 26 + .../serverdnsaliases/id_dnsalias.go | 139 ++ .../serverdnsaliases/id_dnsalias_test.go | 327 ++++ .../serverdnsaliases/method_acquire.go | 75 + .../serverdnsaliases/method_createorupdate.go | 72 + .../serverdnsaliases/method_delete.go | 71 + .../2023-08-01/serverdnsaliases/method_get.go | 53 + .../serverdnsaliases/method_listbyserver.go | 106 ++ .../serverdnsaliases/model_serverdnsalias.go | 11 + .../model_serverdnsaliasacquisition.go | 8 + .../model_serverdnsaliasproperties.go | 8 + .../2023-08-01/serverdnsaliases/predicates.go | 27 + .../2023-08-01/serverdnsaliases/version.go | 10 + .../sql/2023-08-01/serverkeys/README.md | 83 + .../sql/2023-08-01/serverkeys/client.go | 26 + .../sql/2023-08-01/serverkeys/constants.go | 51 + .../sql/2023-08-01/serverkeys/id_key.go | 139 ++ .../sql/2023-08-01/serverkeys/id_key_test.go | 327 ++++ .../serverkeys/method_createorupdate.go | 76 + .../2023-08-01/serverkeys/method_delete.go | 71 + .../sql/2023-08-01/serverkeys/method_get.go | 53 + .../serverkeys/method_listbyserver.go | 106 ++ .../2023-08-01/serverkeys/model_serverkey.go | 13 + .../serverkeys/model_serverkeyproperties.go | 31 + .../sql/2023-08-01/serverkeys/predicates.go | 37 + .../sql/2023-08-01/serverkeys/version.go | 10 + .../sql/2023-08-01/serveroperations/README.md | 38 + .../sql/2023-08-01/serveroperations/client.go | 26 + .../2023-08-01/serveroperations/constants.go | 63 + .../serveroperations/method_listbyserver.go | 106 ++ .../serveroperations/model_serveroperation.go | 11 + .../model_serveroperationproperties.go | 50 + .../2023-08-01/serveroperations/predicates.go | 27 + .../2023-08-01/serveroperations/version.go | 10 + .../sql/2023-08-01/servers/README.md | 167 ++ .../sql/2023-08-01/servers/client.go | 26 + .../sql/2023-08-01/servers/constants.go | 564 +++++++ .../servers/method_checknameavailability.go | 59 + .../servers/method_createorupdate.go | 77 + .../sql/2023-08-01/servers/method_delete.go | 72 + .../sql/2023-08-01/servers/method_get.go | 84 + .../servers/method_importdatabase.go | 76 + .../sql/2023-08-01/servers/method_list.go | 135 ++ .../servers/method_listbyresourcegroup.go | 135 ++ .../servers/method_refreshstatus.go | 72 + .../sql/2023-08-01/servers/method_update.go | 76 + .../model_checknameavailabilityrequest.go | 9 + .../model_checknameavailabilityresponse.go | 11 + .../model_importexportoperationresult.go | 11 + ...l_importexportoperationresultproperties.go | 17 + .../model_importnewdatabasedefinition.go | 18 + .../servers/model_networkisolationsettings.go | 9 + ...del_privateendpointconnectionproperties.go | 11 + ..._privateendpointconnectionrequeststatus.go | 10 + .../servers/model_privateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + ...externalgovernancestatusoperationresult.go | 11 + ...vernancestatusoperationresultproperties.go | 13 + .../sql/2023-08-01/servers/model_server.go | 19 + .../model_serverexternaladministrator.go | 13 + .../model_serverprivateendpointconnection.go | 9 + .../servers/model_serverproperties.go | 23 + .../2023-08-01/servers/model_serverupdate.go | 14 + .../sql/2023-08-01/servers/predicates.go | 37 + .../sql/2023-08-01/servers/version.go | 10 + .../serversecurityalertpolicies/README.md | 71 + .../serversecurityalertpolicies/client.go | 26 + .../serversecurityalertpolicies/constants.go | 51 + .../method_createorupdate.go | 76 + .../serversecurityalertpolicies/method_get.go | 55 + .../method_listbyserver.go | 106 ++ .../model_securityalertspolicyproperties.go | 33 + .../model_serversecurityalertpolicy.go | 16 + .../serversecurityalertpolicies/predicates.go | 27 + .../serversecurityalertpolicies/version.go | 10 + .../servertrustcertificates/README.md | 83 + .../servertrustcertificates/client.go | 26 + .../id_servertrustcertificate.go | 139 ++ .../id_servertrustcertificate_test.go | 327 ++++ .../method_createorupdate.go | 76 + .../servertrustcertificates/method_delete.go | 71 + .../servertrustcertificates/method_get.go | 53 + .../method_listbyinstance.go | 106 ++ .../model_servertrustcertificate.go | 11 + .../model_servertrustcertificateproperties.go | 10 + .../servertrustcertificates/predicates.go | 27 + .../servertrustcertificates/version.go | 10 + .../2023-08-01/servertrustgroups/README.md | 100 ++ .../2023-08-01/servertrustgroups/client.go | 26 + .../2023-08-01/servertrustgroups/constants.go | 51 + .../servertrustgroups/id_providerlocation.go | 130 ++ .../id_providerlocation_test.go | 282 ++++ .../servertrustgroups/id_servertrustgroup.go | 139 ++ .../id_servertrustgroup_test.go | 327 ++++ .../method_createorupdate.go | 76 + .../servertrustgroups/method_delete.go | 71 + .../servertrustgroups/method_get.go | 53 + .../method_listbyinstance.go | 106 ++ .../method_listbylocation.go | 105 ++ .../servertrustgroups/model_serverinfo.go | 8 + .../model_servertrustgroup.go | 11 + .../model_servertrustgroupproperties.go | 9 + .../servertrustgroups/predicates.go | 27 + .../2023-08-01/servertrustgroups/version.go | 10 + .../sql/2023-08-01/serverusages/README.md | 38 + .../sql/2023-08-01/serverusages/client.go | 26 + .../serverusages/method_listbyserver.go | 106 ++ .../serverusages/model_serverusage.go | 11 + .../model_serverusageproperties.go | 11 + .../sql/2023-08-01/serverusages/predicates.go | 27 + .../sql/2023-08-01/serverusages/version.go | 10 + .../servervulnerabilityassessments/README.md | 91 + .../servervulnerabilityassessments/client.go | 26 + .../method_createorupdate.go | 60 + .../method_delete.go | 48 + .../method_get.go | 55 + .../method_listbyserver.go | 106 ++ .../model_servervulnerabilityassessment.go | 11 + ...servervulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../servervulnerabilityassessments/version.go | 10 + .../sql/2023-08-01/sqlagent/README.md | 58 + .../sql/2023-08-01/sqlagent/client.go | 26 + .../sql/2023-08-01/sqlagent/constants.go | 51 + .../sqlagent/method_createorupdate.go | 59 + .../sql/2023-08-01/sqlagent/method_get.go | 55 + .../sqlagent/model_sqlagentconfiguration.go | 11 + .../model_sqlagentconfigurationproperties.go | 8 + .../sql/2023-08-01/sqlagent/version.go | 10 + .../README.md | 75 + .../client.go | 26 + .../constants.go | 48 + .../method_createorupdate.go | 88 + .../method_get.go | 84 + ...method_listbysqlvulnerabilityassessment.go | 135 ++ ...sesqlvulnerabilityassessmentbaselineset.go | 16 + ...rabilityassessmentbaselinesetproperties.go | 8 + ...rabilityassessmentrulebaselinelistinput.go | 16 + ...sessmentrulebaselinelistinputproperties.go | 9 + .../predicates.go | 27 + .../version.go | 10 + .../client.go | 26 + .../constants.go | 48 + .../method_execute.go | 100 ++ .../version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../constants.go | 48 + .../id_rule.go | 143 ++ .../id_rule_test.go | 387 +++++ .../method_createorupdate.go | 87 + .../method_delete.go | 77 + .../method_get.go | 83 + .../method_listbybaseline.go | 135 ++ ...esqlvulnerabilityassessmentrulebaseline.go | 16 + ...ulnerabilityassessmentrulebaselineinput.go | 16 + ...tyassessmentrulebaselineinputproperties.go | 9 + ...abilityassessmentrulebaselineproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 53 + .../client.go | 26 + .../constants.go | 189 +++ .../id_scan.go | 141 ++ .../id_scan_test.go | 357 ++++ .../id_scanresult.go | 150 ++ .../id_scanresult_test.go | 402 +++++ .../method_get.go | 83 + .../method_listbyscan.go | 134 ++ .../model_baseline.go | 27 + .../model_baselineadjustedresult.go | 11 + .../model_benchmarkreference.go | 9 + .../model_querycheck.go | 10 + .../model_remediation.go | 11 + ...erabilityassessmentscanresultproperties.go | 15 + ...l_sqlvulnerabilityassessmentscanresults.go | 16 + .../model_varule.go | 16 + .../predicates.go | 27 + .../version.go | 10 + .../sqlvulnerabilityassessmentscans/README.md | 54 + .../sqlvulnerabilityassessmentscans/client.go | 26 + .../constants.go | 136 ++ .../id_scan.go | 141 ++ .../id_scan_test.go | 357 ++++ .../method_get.go | 83 + ...ethod_listbysqlvulnerabilityassessments.go | 135 ++ ...del_sqlvulnerabilityassessmentscanerror.go | 9 + ...el_sqlvulnerabilityassessmentscanrecord.go | 16 + ...erabilityassessmentscanrecordproperties.go | 66 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 60 + .../method_get.go | 55 + .../method_listbyserver.go | 106 ++ ...ethod_sqlvulnerabilityassessmentsdelete.go | 49 + .../model_sqlvulnerabilityassessment.go | 16 + ...vulnerabilityassessmentpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 10 + .../README.md | 91 + .../client.go | 26 + .../constants.go | 66 + .../method_createorupdate.go | 60 + .../method_delete.go | 49 + .../method_get.go | 55 + .../method_listbyinstance.go | 106 ++ .../model_scheduleitem.go | 11 + .../model_startstopmanagedinstanceschedule.go | 16 + ...rtstopmanagedinstancescheduleproperties.go | 12 + .../predicates.go | 27 + .../version.go | 10 + .../2023-08-01/subscriptionusages/README.md | 53 + .../2023-08-01/subscriptionusages/client.go | 26 + .../subscriptionusages/id_location.go | 121 ++ .../subscriptionusages/id_location_test.go | 237 +++ .../2023-08-01/subscriptionusages/id_usage.go | 130 ++ .../subscriptionusages/id_usage_test.go | 282 ++++ .../subscriptionusages/method_get.go | 53 + .../method_listbylocation.go | 105 ++ .../model_subscriptionusage.go | 11 + .../model_subscriptionusageproperties.go | 11 + .../subscriptionusages/predicates.go | 27 + .../2023-08-01/subscriptionusages/version.go | 10 + .../synapselinkworkspaces/README.md | 38 + .../synapselinkworkspaces/client.go | 26 + .../method_listbydatabase.go | 106 ++ .../model_synapselinkworkspace.go | 11 + ...odel_synapselinkworkspaceinfoproperties.go | 9 + .../model_synapselinkworkspaceproperties.go | 8 + .../synapselinkworkspaces/predicates.go | 27 + .../synapselinkworkspaces/version.go | 10 + .../sql/2023-08-01/syncagents/README.md | 116 ++ .../sql/2023-08-01/syncagents/client.go | 26 + .../sql/2023-08-01/syncagents/constants.go | 95 ++ .../sql/2023-08-01/syncagents/id_syncagent.go | 139 ++ .../syncagents/id_syncagent_test.go | 327 ++++ .../syncagents/method_createorupdate.go | 76 + .../2023-08-01/syncagents/method_delete.go | 71 + .../syncagents/method_generatekey.go | 54 + .../sql/2023-08-01/syncagents/method_get.go | 53 + .../syncagents/method_listbyserver.go | 106 ++ .../syncagents/method_listlinkeddatabases.go | 105 ++ .../2023-08-01/syncagents/model_syncagent.go | 11 + .../model_syncagentkeyproperties.go | 8 + .../model_syncagentlinkeddatabase.go | 11 + ...model_syncagentlinkeddatabaseproperties.go | 13 + .../syncagents/model_syncagentproperties.go | 44 + .../sql/2023-08-01/syncagents/predicates.go | 50 + .../sql/2023-08-01/syncagents/version.go | 10 + .../sql/2023-08-01/syncgroups/README.md | 195 +++ .../sql/2023-08-01/syncgroups/client.go | 26 + .../sql/2023-08-01/syncgroups/constants.go | 195 +++ .../sql/2023-08-01/syncgroups/id_location.go | 121 ++ .../2023-08-01/syncgroups/id_location_test.go | 237 +++ .../sql/2023-08-01/syncgroups/id_syncgroup.go | 148 ++ .../syncgroups/id_syncgroup_test.go | 372 +++++ .../syncgroups/method_cancelsync.go | 47 + .../syncgroups/method_createorupdate.go | 76 + .../2023-08-01/syncgroups/method_delete.go | 71 + .../sql/2023-08-01/syncgroups/method_get.go | 53 + .../syncgroups/method_listbydatabase.go | 106 ++ .../syncgroups/method_listhubschemas.go | 105 ++ .../2023-08-01/syncgroups/method_listlogs.go | 146 ++ .../syncgroups/method_listsyncdatabaseids.go | 105 ++ .../syncgroups/method_refreshhubschema.go | 70 + .../syncgroups/method_triggersync.go | 47 + .../2023-08-01/syncgroups/method_update.go | 75 + .../sql/2023-08-01/syncgroups/model_sku.go | 12 + .../model_syncdatabaseidproperties.go | 8 + .../model_syncfullschemaproperties.go | 27 + .../syncgroups/model_syncfullschematable.go | 12 + .../model_syncfullschematablecolumn.go | 14 + .../2023-08-01/syncgroups/model_syncgroup.go | 12 + .../model_syncgrouplogproperties.go | 31 + .../syncgroups/model_syncgroupproperties.go | 37 + .../syncgroups/model_syncgroupschema.go | 9 + .../syncgroups/model_syncgroupschematable.go | 9 + .../model_syncgroupschematablecolumn.go | 10 + .../sql/2023-08-01/syncgroups/predicates.go | 86 + .../sql/2023-08-01/syncgroups/version.go | 10 + .../sql/2023-08-01/syncmembers/README.md | 128 ++ .../sql/2023-08-01/syncmembers/client.go | 26 + .../sql/2023-08-01/syncmembers/constants.go | 184 +++ .../2023-08-01/syncmembers/id_syncgroup.go | 148 ++ .../syncmembers/id_syncgroup_test.go | 372 +++++ .../2023-08-01/syncmembers/id_syncmember.go | 157 ++ .../syncmembers/id_syncmember_test.go | 417 +++++ .../syncmembers/method_createorupdate.go | 76 + .../2023-08-01/syncmembers/method_delete.go | 71 + .../sql/2023-08-01/syncmembers/method_get.go | 53 + .../syncmembers/method_listbysyncgroup.go | 105 ++ .../syncmembers/method_listmemberschemas.go | 105 ++ .../syncmembers/method_refreshmemberschema.go | 70 + .../2023-08-01/syncmembers/method_update.go | 75 + .../model_syncfullschemaproperties.go | 27 + .../syncmembers/model_syncfullschematable.go | 12 + .../model_syncfullschematablecolumn.go | 14 + .../syncmembers/model_syncmember.go | 11 + .../syncmembers/model_syncmemberproperties.go | 19 + .../sql/2023-08-01/syncmembers/predicates.go | 40 + .../sql/2023-08-01/syncmembers/version.go | 10 + .../sql/2023-08-01/tdecertificates/README.md | 38 + .../sql/2023-08-01/tdecertificates/client.go | 26 + .../tdecertificates/method_create.go | 75 + .../tdecertificates/model_tdecertificate.go | 11 + .../model_tdecertificateproperties.go | 9 + .../sql/2023-08-01/tdecertificates/version.go | 10 + .../sql/2023-08-01/timezones/README.md | 53 + .../sql/2023-08-01/timezones/client.go | 26 + .../sql/2023-08-01/timezones/id_location.go | 121 ++ .../2023-08-01/timezones/id_location_test.go | 237 +++ .../sql/2023-08-01/timezones/id_timezone.go | 130 ++ .../2023-08-01/timezones/id_timezone_test.go | 282 ++++ .../sql/2023-08-01/timezones/method_get.go | 53 + .../timezones/method_listbylocation.go | 105 ++ .../2023-08-01/timezones/model_timezone.go | 11 + .../timezones/model_timezoneproperties.go | 9 + .../sql/2023-08-01/timezones/predicates.go | 27 + .../sql/2023-08-01/timezones/version.go | 10 + .../transparentdataencryptions/README.md | 71 + .../transparentdataencryptions/client.go | 26 + .../transparentdataencryptions/constants.go | 51 + .../method_createorupdate.go | 77 + .../transparentdataencryptions/method_get.go | 55 + .../method_listbydatabase.go | 106 ++ ...ogicaldatabasetransparentdataencryption.go | 11 + ...del_transparentdataencryptionproperties.go | 8 + .../transparentdataencryptions/predicates.go | 27 + .../transparentdataencryptions/version.go | 10 + .../sql/2023-08-01/usages/README.md | 37 + .../sql/2023-08-01/usages/client.go | 26 + .../sql/2023-08-01/usages/id_instancepool.go | 130 ++ .../2023-08-01/usages/id_instancepool_test.go | 282 ++++ .../usages/method_listbyinstancepool.go | 134 ++ .../sql/2023-08-01/usages/model_name.go | 9 + .../sql/2023-08-01/usages/model_usage.go | 14 + .../sql/2023-08-01/usages/predicates.go | 42 + .../sql/2023-08-01/usages/version.go | 10 + .../sql/2023-08-01/virtualclusters/README.md | 112 ++ .../sql/2023-08-01/virtualclusters/client.go | 26 + .../2023-08-01/virtualclusters/constants.go | 54 + .../virtualclusters/id_virtualcluster.go | 130 ++ .../virtualclusters/id_virtualcluster_test.go | 282 ++++ .../virtualclusters/method_delete.go | 71 + .../2023-08-01/virtualclusters/method_get.go | 53 + .../2023-08-01/virtualclusters/method_list.go | 106 ++ .../method_listbyresourcegroup.go | 106 ++ .../virtualclusters/method_update.go | 75 + .../method_updatednsservers.go | 71 + ...updatevirtualclusterdnsserversoperation.go | 11 + .../virtualclusters/model_virtualcluster.go | 13 + ...odel_virtualclusterdnsserversproperties.go | 8 + .../model_virtualclusterproperties.go | 10 + .../model_virtualclusterupdate.go | 9 + .../2023-08-01/virtualclusters/predicates.go | 32 + .../sql/2023-08-01/virtualclusters/version.go | 10 + .../2023-08-01/virtualnetworkrules/README.md | 83 + .../2023-08-01/virtualnetworkrules/client.go | 26 + .../virtualnetworkrules/constants.go | 63 + .../id_virtualnetworkrule.go | 139 ++ .../id_virtualnetworkrule_test.go | 327 ++++ .../method_createorupdate.go | 76 + .../virtualnetworkrules/method_delete.go | 71 + .../virtualnetworkrules/method_get.go | 53 + .../method_listbyserver.go | 106 ++ .../model_virtualnetworkrule.go | 11 + .../model_virtualnetworkruleproperties.go | 10 + .../virtualnetworkrules/predicates.go | 27 + .../2023-08-01/virtualnetworkrules/version.go | 10 + .../2023-08-01/workloadclassifiers/README.md | 82 + .../2023-08-01/workloadclassifiers/client.go | 26 + .../id_workloadclassifier.go | 157 ++ .../id_workloadclassifier_test.go | 417 +++++ .../workloadclassifiers/id_workloadgroup.go | 148 ++ .../id_workloadgroup_test.go | 372 +++++ .../method_createorupdate.go | 76 + .../workloadclassifiers/method_delete.go | 71 + .../workloadclassifiers/method_get.go | 53 + .../method_listbyworkloadgroup.go | 105 ++ .../model_workloadclassifier.go | 11 + .../model_workloadclassifierproperties.go | 13 + .../workloadclassifiers/predicates.go | 27 + .../2023-08-01/workloadclassifiers/version.go | 10 + .../sql/2023-08-01/workloadgroups/README.md | 83 + .../sql/2023-08-01/workloadgroups/client.go | 26 + .../workloadgroups/id_workloadgroup.go | 148 ++ .../workloadgroups/id_workloadgroup_test.go | 372 +++++ .../workloadgroups/method_createorupdate.go | 76 + .../workloadgroups/method_delete.go | 71 + .../2023-08-01/workloadgroups/method_get.go | 53 + .../workloadgroups/method_listbydatabase.go | 106 ++ .../workloadgroups/model_workloadgroup.go | 11 + .../model_workloadgroupproperties.go | 13 + .../2023-08-01/workloadgroups/predicates.go | 27 + .../sql/2023-08-01/workloadgroups/version.go | 10 + .../storagetaskassignments/constants.go | 3 + .../storagetaskassignments/constants.go | 3 + 4085 files changed, 302636 insertions(+), 12 deletions(-) create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/README.md create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/client.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/constants.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore_test.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/method_get.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/method_list.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentity.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentityproperties.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreresponse.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/model_scoreentity.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/model_timeseriesentitytimeseriesinlined.go create mode 100644 resource-manager/advisor/2025-01-01/advisorscore/version.go create mode 100644 resource-manager/advisor/2025-01-01/client.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/README.md create mode 100644 resource-manager/advisor/2025-01-01/configurations/client.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/constants.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/method_createinresourcegroup.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/method_createinsubscription.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/method_listbyresourcegroup.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/method_listbysubscription.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/model_configdata.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/model_configdataproperties.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/model_digestconfig.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/predicates.go create mode 100644 resource-manager/advisor/2025-01-01/configurations/version.go create mode 100644 resource-manager/advisor/2025-01-01/generaterecommendations/client.go create mode 100644 resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation.go create mode 100644 resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation_test.go create mode 100644 resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgenerate.go create mode 100644 resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgetgeneratestatus.go create mode 100644 resource-manager/advisor/2025-01-01/generaterecommendations/version.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/README.md create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/client.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/constants.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation_test.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationsget.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationslist.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/model_recommendationproperties.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/model_resourcemetadata.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/model_resourcerecommendationbase.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/model_shortdescription.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/predicates.go create mode 100644 resource-manager/advisor/2025-01-01/getrecommendations/version.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/README.md create mode 100644 resource-manager/advisor/2025-01-01/metadata/client.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/constants.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/id_metadata.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/id_metadata_test.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadataget.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadatalist.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/model_metadataentity.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/model_metadataentityproperties.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/model_metadatasupportedvaluedetail.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/predicates.go create mode 100644 resource-manager/advisor/2025-01-01/metadata/version.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/README.md create mode 100644 resource-manager/advisor/2025-01-01/prediction/client.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/constants.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/method_predict.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/model_predictionrequest.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/model_predictionrequestproperties.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/model_predictionresponse.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/model_predictionresponseproperties.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/model_shortdescription.go create mode 100644 resource-manager/advisor/2025-01-01/prediction/version.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/README.md create mode 100644 resource-manager/advisor/2025-01-01/suppressions/client.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression_test.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/method_create.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/method_delete.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/method_get.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/method_list.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/model_suppressioncontract.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/model_suppressionproperties.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/predicates.go create mode 100644 resource-manager/advisor/2025-01-01/suppressions/version.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/README.md create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/client.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location_test.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofile.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofileproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/availableworkloadprofiles/version.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/README.md create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/client.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/id_location.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/id_location_test.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeter.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/model_billingmetercollection.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeterproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/billingmeters/version.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/README.md create mode 100644 resource-manager/containerapps/2025-01-01/certificates/client.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_certificate.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_certificate_test.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate_test.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatescreateorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesdelete.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesget.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificateslist.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/model_certificate.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/model_certificatekeyvaultproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/model_certificatepatch.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/model_certificateproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/certificates/version.go create mode 100644 resource-manager/containerapps/2025-01-01/client.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/README.md create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/client.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate_test.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatescreateorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesdelete.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesget.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificateslist.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_checknameavailability.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbyresourcegroup.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbysubscription.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificate.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatekeyvaultproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatepatch.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificateproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityrequest.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityresponse.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironmentproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_customdomainconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/model_extendedlocation.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironments/version.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/README.md create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/client.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage_test.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_azurefileproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorage.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorageproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstoragescollection.go create mode 100644 resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/version.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/README.md create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/client.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/id_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/id_containerapp_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetrevision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetroot.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistdetectors.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistrevisions.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_getauthtoken.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_listbyresourcegroup.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_listbysubscription.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_listcustomhostnameanalysis.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_listsecrets.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_start.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_stop.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_basecontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_configuration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_container.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappauthtoken.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappauthtokenproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobe.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpget.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpgethttpheadersinlined.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobetcpsocket.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerappsecret.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_containerresources.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_corspolicy.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_customdomain.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresult.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfo.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfodetailsinlined.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_customscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_dapr.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadata.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadatapropertybaginlined.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponsecolumn.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponseobject.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticrendering.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnostics.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdataapiresponse.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdefinition.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsstatus.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsupporttopic.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_environmentvar.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_extendedlocation.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_httpscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_identitysettings.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_ingress.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_ingressportmapping.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_ingressstickysessions.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_ipsecurityrestrictionrule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_queuescalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_registrycredentials.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_revision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_revisionproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_runtime.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_runtimejava.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_scale.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_scalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_scaleruleauth.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_secret.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_secretscollection.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_secretvolumeitem.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_service.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_servicebind.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_tcpscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_template.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_trafficweight.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_volume.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/model_volumemount.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/containerapps/version.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/README.md create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/client.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_listbycontainerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedaudiencesvalidation.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedprincipals.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_apple.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appleregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfigproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authplatform.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectory.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectorylogin.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryvalidation.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebapps.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebappsregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_blobstoragetokenstore.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_clientregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_cookieexpiration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_customopenidconnectprovider.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_defaultauthorizationpolicy.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_encryptionsettings.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_facebook.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_forwardproxy.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_github.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_globalvalidation.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_google.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettings.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettingsroutes.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_identityproviders.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_jwtclaimchecks.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_login.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginroutes.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginscopes.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_nonce.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectclientcredential.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectlogin.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_tokenstore.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitter.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitterregistration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsauthconfigs/version.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/README.md create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/client.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_getreplica.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_listreplicas.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replica.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacollection.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicaproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/version.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/README.md create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/client.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/method_activaterevision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/method_deactivaterevision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/method_getrevision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/method_listrevisions.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/method_restartrevision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_basecontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_container.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobe.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpget.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpgethttpheadersinlined.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobetcpsocket.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerresources.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_customscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_environmentvar.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_httpscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_queuescalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revision.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revisionproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scale.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scaleruleauth.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_secretvolumeitem.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_servicebind.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_tcpscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_template.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volume.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volumemount.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappsrevisions/version.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/README.md create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/client.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbyresourcegroup.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbysubscription.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_customcontainertemplate.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_dynamicpoolconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_environmentvar.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_lifecycleconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_managedidentitysetting.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_scaleconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainerresources.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioningress.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionnetworkconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpool.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolsecret.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatableproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatablepropertiesproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionregistrycredentials.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssessionpools/version.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/README.md create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/client.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol_test.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_listbycontainerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_azurecredentials.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_githubactionconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_registryinfo.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrol.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrolproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/containerappssourcecontrols/version.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/README.md create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/client.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent_test.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent_test.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentscreateorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsdelete.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsget.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslist.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslistsecrets.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/method_listsecrets.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponentproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/model_daprmetadata.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecret.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecretscollection.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/model_secret.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/daprcomponents/version.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/README.md create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/client.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_detector.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_detector_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_job.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_job_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision_test.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetrevision.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetroot.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistdetectors.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistrevisions.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_jobsgetdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_jobslistdetectors.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_jobsproxyget.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticsgetdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticslistdetectors.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentsdiagnosticsgetroot.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_applogsconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_basecontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_certificatekeyvaultproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_configuration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_container.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerapp.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobe.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpget.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpgethttpheadersinlined.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobetcpsocket.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerappproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_containerresources.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_corspolicy.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_customdomain.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_customdomainconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_customscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_dapr.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_daprconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadata.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadatapropertybaginlined.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponsecolumn.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponseobject.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticrendering.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnostics.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdataapiresponse.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdefinition.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsstatus.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsupporttopic.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_environmentvar.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_extendedlocation.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_httpscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_identitysettings.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_ingress.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_ingressportmapping.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_ingressstickysessions.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_ipsecurityrestrictionrule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_job.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationeventtriggerconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationmanualtriggerconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationscheduletriggerconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobscale.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_jobtemplate.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_kedaconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_loganalyticsconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeerauthentication.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_mtls.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_queuescalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_registrycredentials.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_revision.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_revisionproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_runtime.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_runtimejava.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_scale.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_scalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_scaleruleauth.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_secret.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_secretvolumeitem.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_service.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_servicebind.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_tcpscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_template.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_trafficweight.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_vnetconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_volume.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_volumemount.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/model_workloadprofile.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/diagnostics/version.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/README.md create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/client.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent_test.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentconfigurationproperty.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentingress.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentpropertiesscale.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentservicebind.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_springbootadmincomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudconfigcomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudeurekacomponent.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/javacomponents/version.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/README.md create mode 100644 resource-manager/containerapps/2025-01-01/jobs/client.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_detector.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_detector_test.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty_test.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_execution.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_execution_test.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_job.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/id_job_test.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_executionslist.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_getdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_jobexecution.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_listbyresourcegroup.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_listbysubscription.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_listdetectors.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_listsecrets.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_proxyget.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_start.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_stopexecution.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_stopmultipleexecutions.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_basecontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_container.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_containerappprobe.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpget.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpgethttpheadersinlined.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_containerappprobetcpsocket.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_containerresources.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadata.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadatapropertybaginlined.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponsecolumn.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponseobject.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticrendering.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnostics.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdataapiresponse.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdefinition.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsstatus.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsupporttopic.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_environmentvar.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_identitysettings.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_job.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationeventtriggerconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationmanualtriggerconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationscheduletriggerconfig.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobexecution.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionbase.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobexecutioncontainer.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobexecutiontemplate.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobpatchproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobpatchpropertiesproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobscale.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobscalerule.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobsecretscollection.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_jobtemplate.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_registrycredentials.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_scaleruleauth.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_secret.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_secretvolumeitem.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_volume.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/model_volumemount.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/jobs/version.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/README.md create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/client.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificatepatch.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificateproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/managedcertificates/version.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/README.md create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/client.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatescreateorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesdelete.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesget.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_certificateslist.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_diagnosticsgetroot.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_getauthtoken.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_listbyresourcegroup.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_listbysubscription.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_listworkloadprofilestates.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatescreateorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesdelete.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesget.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificateslist.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticsgetdetector.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticslistdetectors.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_namespaceschecknameavailability.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/method_update.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_applogsconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_certificate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatekeyvaultproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatepatch.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_certificateproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityrequest.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityresponse.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_customdomainconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_daprconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadata.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadatapropertybaginlined.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponsecolumn.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponseobject.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticrendering.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnostics.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdataapiresponse.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdefinition.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsstatus.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsupporttopic.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtoken.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtokenproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_kedaconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_loganalyticsconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificatepatch.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificateproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeerauthentication.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_mtls.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_vnetconfiguration.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofile.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestates.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestatesproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironments/version.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/README.md create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/client.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage_test.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_createorupdate.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_delete.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_get.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_azurefileproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorage.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorageproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstoragescollection.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_nfsazurefileproperties.go create mode 100644 resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/version.go create mode 100644 resource-manager/containerapps/2025-01-01/subscriptions/client.go create mode 100644 resource-manager/containerapps/2025-01-01/subscriptions/method_getcustomdomainverificationid.go create mode 100644 resource-manager/containerapps/2025-01-01/subscriptions/version.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/README.md create mode 100644 resource-manager/containerapps/2025-01-01/usages/client.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/constants.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/id_location.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/id_location_test.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/id_managedenvironment.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/id_managedenvironment_test.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/method_list.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/method_managedenvironmentusageslist.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/model_usage.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/model_usagename.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/predicates.go create mode 100644 resource-manager/containerapps/2025-01-01/usages/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobsoperationresultget.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobstrigger.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/method_jobsget.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjob.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjobresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_exportjobsresult.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_innererror.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobextendedinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobsubtask.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_restorejobrecoverypointdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingerror.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingwarningdetail.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjob/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/method_jobslist.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjob.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjobresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_innererror.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobextendedinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobsubtask.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_restorejobrecoverypointdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingerror.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingwarningdetail.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/azurebackupjobs/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_adhocbackup.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_createorupdate.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_delete.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_get.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_list.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_resumebackups.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_resumeprotection.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_stopprotection.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_suspendbackups.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_syncbackupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_triggercrossregionrestore.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrehydrate.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrestore.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_validatecrossregionrestore.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforbackup.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_validateformodifybackup.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforrestore.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackupruleoptions.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackuptriggeroption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_adlsblobbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_authcredentials.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprehydrationrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorerequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_azureoperationalstoreparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_backupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstanceresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_baseresourceproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_blobbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestoredetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestorerequestobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_datasource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_datasourceset.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_datastoreparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_defaultresourceproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_identitydetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_innererror.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestoretargetinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_itempathbasedrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetespvrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_namespacednameresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_operationextendedinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_operationjobextendedinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_policyinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_policyparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_protectionstatusdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_restorefilestargetinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfobase.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstorebasedauthcredentials.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstoreresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_stopprotectionrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_suspendbackuprequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_syncbackupinstancerequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_targetdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_triggerbackuprequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_userfacingerror.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_validatecrossregionrestorerequestobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_validateforbackuprequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_validateformodifybackuprequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/model_validaterestorerequestobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstances/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/method_list.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_adlsblobbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_authcredentials.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_azureoperationalstoreparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstanceresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_baseresourceproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_blobbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasourceset.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datastoreparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_defaultresourceproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_identitydetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_innererror.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_kubernetesclusterbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_namespacednameresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_protectionstatusdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstorebasedauthcredentials.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstoreresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_userfacingerror.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/method_createorupdate.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/method_delete.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/method_get.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/method_list.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_absolutedeleteoption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtaggingcriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtriggercontext.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackupparams.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackuprule.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_azureretentionrule.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupcriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_backuppolicy.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupschedule.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicy.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicyresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_basepolicyrule.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyonexpiryoption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyoption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_customcopyoption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_datastoreinfobase.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_day.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_deleteoption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_immediatecopyoption.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_retentiontag.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedbackupcriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedtriggercontext.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_sourcelifecycle.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_taggingcriteria.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_targetcopysetting.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/model_triggercontext.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/backuppolicies/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_checknameavailability.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_createorupdate.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_delete.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_get.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_getinresourcegroup.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_getinsubscription.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/method_update.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_azuremonitoralertsettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvaultresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityresult.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkekidentity.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkeyvaultproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_crossregionrestoresettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_crosssubscriptionrestoresettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_dppidentitydetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_encryptionsettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_featuresettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_immutabilitysettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_monitoringsettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_patchbackupvaultinput.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_patchresourcerequestinput.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_resourcemovedetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_securitysettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_softdeletesettings.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_storagesetting.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/model_userassignedidentity.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/backupvaults/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_get.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_list.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_undelete.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_adlsblobbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_authcredentials.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_azureoperationalstoreparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_backupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_baseresourceproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasource.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasourceset.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datastoreparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_defaultresourceproperties.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstanceresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletioninfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_identitydetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_innererror.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_namespacednameresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_protectionstatusdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstoreresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_userfacingerror.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/deletedbackupinstances/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequestbase.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponse.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponsebase.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_supportedfeature.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppfeaturesupport/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobget.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobslist.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjob.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjobresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobsrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_innererror.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_jobextendedinfo.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_jobsubtask.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_restorejobrecoverypointdetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingerror.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingwarningdetail.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppjob/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyget.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxylist.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardoperationdetail.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybase.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleterequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleteresponse.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/method_list.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/method_restorabletimerangesfind.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_restorabletimerange.go create mode 100644 resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/method_get.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/method_list.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypoint.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypointresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/model_recoverypointdatastoredetails.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/recoverypoint/version.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/README.md create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/client.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/constants.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest_test.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_delete.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_get.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinresourcegroup.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinsubscription.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_patch.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/method_put.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/model_dppbaseresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/model_patchresourceguardinput.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguard.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardoperation.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardresource.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/predicates.go create mode 100644 resource-manager/dataprotection/2025-02-01/resourceguards/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionget.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionlist.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/model_agentversion.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/agentversions/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_location.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_location_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_publisher.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_publisher_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/id_version_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadataget.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatalist.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2list.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/method_extensionpublisherlist.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/method_extensiontypelist.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensionpublisher.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensiontype.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalue.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluelistresult.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalueproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2properties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/extensions/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/id_gateway.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/id_gateway_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/method_listbyresourcegroup.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/method_listbysubscription.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/model_gateway.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/gateways/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_listbymachines.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadata.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadataproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_list.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_erroradditionalinfo.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_errordetail.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esukey.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esuprofileupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmesuproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmproductprofileproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilepropertiessoftwareassurance.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdatepropertiessoftwareassurance.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeature.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeatureupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productprofileupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenseprofiles/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/id_license.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/id_license_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_listbyresourcegroup.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_listbysubscription.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/method_validatelicense.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_license.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_licensedetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_licenseproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdatepropertieslicensedetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/model_volumelicensedetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/licenses/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/method_list.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextension.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceview.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceviewstatus.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensions/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/method_setupextensions.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceview.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceviewstatus.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensionproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_setupextensionrequest.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionssetup/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/method_upgradeextensions.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_extensiontargetproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_machineextensionupgrade.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/method_networkprofileget.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_ipaddress.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkinterface.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_subnet.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/method_list.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_extensionsresourcestatus.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommand.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandinstanceview.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandscriptsource.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_resourceupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandinputparameter.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandmanagedidentity.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machineruncommands/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_assesspatches.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_installpatches.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_listbyresourcegroup.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_listbysubscription.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_agentconfiguration.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_agentupgrade.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_availablepatchcountbyclassification.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_cloudmetadata.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_configurationextension.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_disk.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_erroradditionalinfo.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_errordetail.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_esukey.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_firmwareprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_hardwareprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_ipaddress.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_license.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_licensedetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilearmproductprofileproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceview.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewesuproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewsoftwareassurance.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_licenseproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_linuxparameters.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_locationdata.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineassesspatchesresult.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineextension.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceview.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceviewstatus.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineextensionproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesparameters.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesresult.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_machineupdateproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_networkinterface.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_networkprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_osprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_osprofilelinuxconfiguration.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_osprofilewindowsconfiguration.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_patchsettings.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_patchsettingsstatus.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_processor.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_productfeature.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_servicestatus.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_servicestatuses.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_storageprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_subnet.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_volumelicensedetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/model_windowsparameters.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/machines/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keydetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keyproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfiguration.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfigurationproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networkconfigurations/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_getbyprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_listbyprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_reconcileforprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessrule.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessruleproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeter.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfiguration.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationreconcileresult.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterprofile.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissue.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissueproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_resourceassociation.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_listbyprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointproperty.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privateendpointconnections/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_listbyprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkresources/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/constants.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_createorupdate.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_delete.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetailsformachine.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_list.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_listbyresourcegroup.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_updatetags.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_connectiondetail.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscope.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscopeproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectiondatamodel.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointproperty.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkscopevalidationdetails.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_tagsresource.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/predicates.go create mode 100644 resource-manager/hybridcompute/2025-01-13/privatelinkscopes/version.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/README.md create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/client.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting_test.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/method_get.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/method_patch.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/method_update.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/model_settings.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/model_settingsgatewayproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/model_settingsproperties.go create mode 100644 resource-manager/hybridcompute/2025-01-13/settings/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/model_availableservicetier.go create mode 100644 resource-manager/operationalinsights/2025-02-01/availableservicetiers/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/id_cluster.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/id_cluster_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/method_list.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/method_listbyresourcegroup.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/method_update.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_associatedworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_capacityreservationproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_cluster.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatch.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatchproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_clusterproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_clusterreplicationproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_clustersku.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/model_keyvaultproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/predicates.go create mode 100644 resource-manager/operationalinsights/2025-02-01/clusters/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexport.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportlistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/model_destination.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/model_destinationmetadata.go create mode 100644 resource-manager/operationalinsights/2025-02-01/dataexport/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/id_datasource.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/id_datasource_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/model_datasource.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/predicates.go create mode 100644 resource-manager/operationalinsights/2025-02-01/datasources/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_list.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_listbyresourcegroup.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_privatelinkscopedresource.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacecapping.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefailoverproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefeatures.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacelistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspaceproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacereplicationproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacesku.go create mode 100644 resource-manager/operationalinsights/2025-02-01/deletedworkspaces/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_disable.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_enable.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_list.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/model_intelligencepack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/intelligencepacks/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservice.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservicelistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedserviceproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedservices/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountslistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsresource.go create mode 100644 resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesdelete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesget.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/method_querieslist.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesput.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriessearch.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquery.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackqueryproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerypropertiesrelated.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchpropertiesrelated.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/predicates.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypackqueries/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdatewithoutname.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_list.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_listbyresourcegroup.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/method_updatetags.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypackproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/model_tagsresource.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/predicates.go create mode 100644 resource-manager/operationalinsights/2025-02-01/querypacks/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearch.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearcheslistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearchproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/model_tag.go create mode 100644 resource-manager/operationalinsights/2025-02-01/savedsearches/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigscreateorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsdelete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsget.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigslistbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageaccount.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsight.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightstatus.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/predicates.go create mode 100644 resource-manager/operationalinsights/2025-02-01/storageinsights/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/id_table.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/id_table_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_cancelsearch.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_listbyworkspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_migrate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/method_update.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_column.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_restoredlogs.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_resultstatistics.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_schema.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_searchresults.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_table.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_tableproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/model_tableslistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/tables/version.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/README.md create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/client.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/constants.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_operation.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_operation_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace_test.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_createorupdate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_delete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_gatewaysdelete.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_get.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksdisable.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksenable.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepackslist.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_list.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_listbyresourcegroup.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_managementgroupslist.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_schemaget.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysgetsharedkeys.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysregenerate.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_update.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_usageslist.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgegetpurgestatus.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgepurge.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_coresummary.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_intelligencepack.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroup.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroupproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_metricname.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_privatelinkscopedresource.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_searchgetschemaresponse.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadata.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadataschema.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_searchschemavalue.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_searchsort.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_sharedkeys.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_usagemetric.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspace.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacecapping.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefailoverproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefeatures.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistmanagementgroupsresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistusagesresult.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepatch.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspaceproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebody.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebodyfilters.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgeresponse.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgestatusresponse.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacereplicationproperties.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacesku.go create mode 100644 resource-manager/operationalinsights/2025-02-01/workspaces/version.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/README.md create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/client.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/constants.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentcreateupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentdelete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentget.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentlist.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignment.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentpropertiesuser.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/predicates.go create mode 100644 resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/version.go create mode 100644 resource-manager/redisenterprise/2025-04-01/client.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/README.md create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/client.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/constants.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/id_database.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/id_database_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentcreateupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentdelete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentget.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentlist.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_create.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_delete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_export.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_flush.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_forcelinktoreplicationgroup.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_forceunlink.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_get.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_import.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_listbycluster.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_listkeys.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_regeneratekey.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_update.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/method_upgradedbredisversion.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_accesskeys.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignment.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentpropertiesuser.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_database.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_databaseproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_databasepropertiesgeoreplication.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_databaseupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_exportclusterparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_flushparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparametersgeoreplication.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_forceunlinkparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_importclusterparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_linkeddatabase.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_module.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_persistence.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/model_regeneratekeyparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/predicates.go create mode 100644 resource-manager/redisenterprise/2025-04-01/databases/version.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/README.md create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/client.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/constants.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_delete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_get.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_list.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_put.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpoint.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionlistresult.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privateendpointconnections/version.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/README.md create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/client.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/method_listbycluster.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourcelistresult.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/privatelinkresources/version.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/README.md create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/client.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/constants.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentcreateupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentdelete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentget.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentlist.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_create.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasescreate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesdelete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesexport.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesflush.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforceunlink.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesget.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesimport.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistbycluster.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistkeys.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesregeneratekey.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupgradedbredisversion.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_delete.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_get.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_list.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_listbyresourcegroup.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/method_update.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesskeys.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignment.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentpropertiesuser.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_cluster.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryption.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_database.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databasepropertiesgeoreplication.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseupdate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_exportclusterparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_flushparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparametersgeoreplication.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forceunlinkparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_importclusterparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_linkeddatabase.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_module.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_persistence.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpoint.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnection.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_regeneratekeyparameters.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/model_sku.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/predicates.go create mode 100644 resource-manager/redisenterprise/2025-04-01/redisenterprise/version.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/README.md create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/client.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/constants.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_deployment.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_deployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_operation.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_operation_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation_test.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_get.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_getatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_getatscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_getatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_getattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_list.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_listatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_listatscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_listatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/method_listattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensionconfigitem.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensiondefinition.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperation.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperationproperties.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_erroradditionalinfo.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_errorresponse.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_httpmessage.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultparameterreference.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultreference.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_statusmessage.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/model_targetresource.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/predicates.go create mode 100644 resource-manager/resources/2025-03-01/deploymentoperations/version.go create mode 100644 resource-manager/resources/2025-03-01/deployments/README.md create mode 100644 resource-manager/resources/2025-03-01/deployments/client.go create mode 100644 resource-manager/resources/2025-03-01/deployments/constants.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_deployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_deployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_providerdeployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_providerdeployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_providers2deployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_providers2deployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_scopeddeployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/id_scopeddeployment_test.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_calculatetemplatehash.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_cancel.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_cancelatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_cancelatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_cancelatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_cancelattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_checkexistence.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_checkexistenceatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_checkexistenceatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_checkexistenceatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_checkexistenceattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_createorupdate.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_createorupdateatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_createorupdateatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_createorupdateatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_createorupdateattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_delete.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_deleteatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_deleteatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_deleteatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_deleteattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_exporttemplate.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_exporttemplateatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_exporttemplateatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_exporttemplateatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_exporttemplateattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_get.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_getatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_getatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_getatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_getattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_listatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_listatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_listatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_listattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_listbyresourcegroup.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_validate.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_validateatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_validateatscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_validateatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_validateattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_whatif.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_whatifatmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_whatifatsubscriptionscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/method_whatifattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_alias.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_aliaspath.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_aliaspathmetadata.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_aliaspattern.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_apiprofile.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_basicdependency.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_debugsetting.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_dependency.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentdiagnosticsdefinition.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentexportresult.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentextended.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentextensionconfigitem.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentextensiondefinition.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentparameter.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentproperties.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentpropertiesextended.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentvalidateresult.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentwhatif.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifproperties.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifsettings.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_erroradditionalinfo.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_errorresponse.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_expressionevaluationoptions.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_keyvaultparameterreference.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_keyvaultreference.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_onerrordeployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_onerrordeploymentextended.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_parameterslink.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_provider.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_providerextendedlocation.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_providerresourcetype.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_resourcereference.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_scopeddeployment.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_scopeddeploymentwhatif.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_templatehashresult.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_templatelink.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_whatifchange.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_whatifoperationproperties.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_whatifoperationresult.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_whatifpropertychange.go create mode 100644 resource-manager/resources/2025-03-01/deployments/model_zonemapping.go create mode 100644 resource-manager/resources/2025-03-01/deployments/predicates.go create mode 100644 resource-manager/resources/2025-03-01/deployments/version.go create mode 100644 resource-manager/resources/2025-03-01/providers/README.md create mode 100644 resource-manager/resources/2025-03-01/providers/client.go create mode 100644 resource-manager/resources/2025-03-01/providers/constants.go create mode 100644 resource-manager/resources/2025-03-01/providers/id_provider.go create mode 100644 resource-manager/resources/2025-03-01/providers/id_provider_test.go create mode 100644 resource-manager/resources/2025-03-01/providers/id_providers2.go create mode 100644 resource-manager/resources/2025-03-01/providers/id_providers2_test.go create mode 100644 resource-manager/resources/2025-03-01/providers/id_subscriptionprovider.go create mode 100644 resource-manager/resources/2025-03-01/providers/id_subscriptionprovider_test.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_get.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_getattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_list.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_listattenantscope.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_providerpermissions.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_providerresourcetypeslist.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_register.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_registeratmanagementgroupscope.go create mode 100644 resource-manager/resources/2025-03-01/providers/method_unregister.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_alias.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_aliaspath.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_aliaspathmetadata.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_aliaspattern.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_apiprofile.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_permission.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_provider.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_providerconsentdefinition.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_providerextendedlocation.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_providerpermission.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_providerregistrationrequest.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_providerresourcetype.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_roledefinition.go create mode 100644 resource-manager/resources/2025-03-01/providers/model_zonemapping.go create mode 100644 resource-manager/resources/2025-03-01/providers/predicates.go create mode 100644 resource-manager/resources/2025-03-01/providers/version.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/README.md create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/client.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/constants.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_checkexistence.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_createorupdate.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_delete.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_exporttemplate.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_get.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_list.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_resourceslistbyresourcegroup.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/method_update.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_erroradditionalinfo.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_errorresponse.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_exporttemplaterequest.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_genericresourceexpanded.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_plan.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroup.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupexportresult.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_resourcegrouppatchable.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupproperties.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/model_sku.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/predicates.go create mode 100644 resource-manager/resources/2025-03-01/resourcegroups/version.go create mode 100644 resource-manager/resources/2025-03-01/resources/README.md create mode 100644 resource-manager/resources/2025-03-01/resources/client.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_checkexistence.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_checkexistencebyid.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_createorupdate.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_createorupdatebyid.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_delete.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_deletebyid.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_get.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_getbyid.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_list.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_moveresources.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_update.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_updatebyid.go create mode 100644 resource-manager/resources/2025-03-01/resources/method_validatemoveresources.go create mode 100644 resource-manager/resources/2025-03-01/resources/model_genericresource.go create mode 100644 resource-manager/resources/2025-03-01/resources/model_genericresourceexpanded.go create mode 100644 resource-manager/resources/2025-03-01/resources/model_plan.go create mode 100644 resource-manager/resources/2025-03-01/resources/model_resourcesmoveinfo.go create mode 100644 resource-manager/resources/2025-03-01/resources/model_sku.go create mode 100644 resource-manager/resources/2025-03-01/resources/predicates.go create mode 100644 resource-manager/resources/2025-03-01/resources/version.go create mode 100644 resource-manager/resources/2025-03-01/tags/README.md create mode 100644 resource-manager/resources/2025-03-01/tags/client.go create mode 100644 resource-manager/resources/2025-03-01/tags/constants.go create mode 100644 resource-manager/resources/2025-03-01/tags/id_tagname.go create mode 100644 resource-manager/resources/2025-03-01/tags/id_tagname_test.go create mode 100644 resource-manager/resources/2025-03-01/tags/id_tagvalue.go create mode 100644 resource-manager/resources/2025-03-01/tags/id_tagvalue_test.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_createorupdate.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_createorupdateatscope.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_createorupdatevalue.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_delete.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_deleteatscope.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_deletevalue.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_getatscope.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_list.go create mode 100644 resource-manager/resources/2025-03-01/tags/method_updateatscope.go create mode 100644 resource-manager/resources/2025-03-01/tags/model_tagcount.go create mode 100644 resource-manager/resources/2025-03-01/tags/model_tagdetails.go create mode 100644 resource-manager/resources/2025-03-01/tags/model_tags.go create mode 100644 resource-manager/resources/2025-03-01/tags/model_tagspatchresource.go create mode 100644 resource-manager/resources/2025-03-01/tags/model_tagsresource.go create mode 100644 resource-manager/resources/2025-03-01/tags/model_tagvalue.go create mode 100644 resource-manager/resources/2025-03-01/tags/predicates.go create mode 100644 resource-manager/resources/2025-03-01/tags/version.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_update.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/README.md create mode 100644 resource-manager/sql/2023-08-01/blobauditing/client.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/constants.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpolicieslistbyserver.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/predicates.go create mode 100644 resource-manager/sql/2023-08-01/blobauditing/version.go create mode 100644 resource-manager/sql/2023-08-01/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/constants.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor_test.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/method_update.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_advisor.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_advisorproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedaction.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionerrorinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimpactrecord.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimplementationinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionmetricinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionstateinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaseadvisors/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/constants.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/method_update.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/model_automatictuningoptions.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuning.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuningproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseautomatictuning/version.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/README.md create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/client.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/id_column.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/id_column_test.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/id_table.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/id_table_test.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/method_listbytable.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumn.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumnproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasecolumns/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go create mode 100644 resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go create mode 100644 resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/constants.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/id_extension.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/id_extension_test.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensions.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensionsproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresult.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/model_networkisolationsettings.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/model_privateendpointconnectionrequeststatus.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databaseextensions/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/constants.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperation.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperationproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/model_phasedetails.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databaseoperations/version.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/README.md create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/client.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/constants.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor_test.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction_test.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/method_listbydatabaseadvisor.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/method_update.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedaction.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionerrorinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimpactrecord.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimplementationinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionmetricinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionstateinfo.go create mode 100644 resource-manager/sql/2023-08-01/databaserecommendedactions/version.go create mode 100644 resource-manager/sql/2023-08-01/databases/README.md create mode 100644 resource-manager/sql/2023-08-01/databases/client.go create mode 100644 resource-manager/sql/2023-08-01/databases/constants.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_export.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_import.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_listbyelasticpool.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_listinaccessiblebyserver.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_pause.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_rename.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_resume.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_update.go create mode 100644 resource-manager/sql/2023-08-01/databases/method_upgradedatawarehouse.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_database.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_databasekey.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_databaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_databaseupdate.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_databaseupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_exportdatabasedefinition.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_importexistingdatabasedefinition.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_importexportoperationresult.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_importexportoperationresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_networkisolationsettings.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_privateendpointconnectionrequeststatus.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_resourcemovedefinition.go create mode 100644 resource-manager/sql/2023-08-01/databases/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/databases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databases/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/id_schema.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/id_schema_test.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/model_resource.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databaseschemas/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_securityalertspolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasesecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/README.md create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/method_execute.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/README.md create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/README.md create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baseline.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_remediation.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_varule.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/README.md create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/client.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/version.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/README.md create mode 100644 resource-manager/sql/2023-08-01/databasetables/client.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/id_schema.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/id_schema_test.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/id_table.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/id_table_test.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/method_listbyschema.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/model_databasetable.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/model_databasetableproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasetables/version.go create mode 100644 resource-manager/sql/2023-08-01/databaseusages/README.md create mode 100644 resource-manager/sql/2023-08-01/databaseusages/client.go create mode 100644 resource-manager/sql/2023-08-01/databaseusages/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databaseusages/model_databaseusage.go create mode 100644 resource-manager/sql/2023-08-01/databaseusages/model_databaseusageproperties.go create mode 100644 resource-manager/sql/2023-08-01/databaseusages/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databaseusages/version.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/README.md create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/client.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/version.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_export.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_initiatescan.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicy.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/README.md create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/client.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/constants.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule_test.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingrule.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingruleproperties.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/predicates.go create mode 100644 resource-manager/sql/2023-08-01/datamaskingrules/version.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/README.md create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/client.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_get.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivities.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/predicates.go create mode 100644 resource-manager/sql/2023-08-01/datawarehouseuseractivities/version.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/README.md create mode 100644 resource-manager/sql/2023-08-01/deletedservers/client.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/id_deletedserver.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/id_deletedserver_test.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/id_location.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/method_get.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/method_list.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/method_recover.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/model_deletedserver.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/model_deletedserverproperties.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/predicates.go create mode 100644 resource-manager/sql/2023-08-01/deletedservers/version.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/README.md create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/client.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/constants.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_setrole.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_update.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_certificateinfo.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroup.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsfailoverrequest.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/distributedavailabilitygroups/version.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/README.md create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/client.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/id_operation.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/id_operation_test.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/method_cancel.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/method_listbyelasticpool.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperation.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperationproperties.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/predicates.go create mode 100644 resource-manager/sql/2023-08-01/elasticpooloperations/version.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/README.md create mode 100644 resource-manager/sql/2023-08-01/elasticpools/client.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/constants.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/method_get.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/method_update.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/model_elasticpool.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolperdatabasesettings.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolproperties.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdate.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/predicates.go create mode 100644 resource-manager/sql/2023-08-01/elasticpools/version.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/README.md create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/client.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/constants.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/method_get.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/method_revalidate.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotector.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotectorproperties.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/predicates.go create mode 100644 resource-manager/sql/2023-08-01/encryptionprotectors/version.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/README.md create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/client.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate_test.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/method_get.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificate.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificateproperties.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/predicates.go create mode 100644 resource-manager/sql/2023-08-01/endpointcertificates/version.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/README.md create mode 100644 resource-manager/sql/2023-08-01/failovergroups/client.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/constants.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/id_failovergroup.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/id_failovergroup_test.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_forcefailoverallowdataloss.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_tryplannedbeforeforcedfailover.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/method_update.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_failovergroup.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_failovergroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadonlyendpoint.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadwriteendpoint.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdate.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/model_partnerinfo.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/failovergroups/version.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/README.md create mode 100644 resource-manager/sql/2023-08-01/firewallrules/client.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/id_firewallrule.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/id_firewallrule_test.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/method_get.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/method_replace.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/model_firewallrule.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/model_firewallrulelist.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/model_serverfirewallruleproperties.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/predicates.go create mode 100644 resource-manager/sql/2023-08-01/firewallrules/version.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/method_list.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicy.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/geobackuppolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/README.md create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/client.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/constants.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup_test.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/method_forcefailoverallowdataloss.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroup.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/model_managedinstancepairinfo.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/model_partnerregioninfo.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/instancefailovergroups/version.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/README.md create mode 100644 resource-manager/sql/2023-08-01/instancepools/client.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/constants.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/id_instancepool.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/id_instancepool_test.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/method_get.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/method_list.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/method_update.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/model_instancepool.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/model_instancepoolproperties.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/model_instancepoolupdate.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/predicates.go create mode 100644 resource-manager/sql/2023-08-01/instancepools/version.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/README.md create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/client.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule_test.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/method_get.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6firewallrule.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/predicates.go create mode 100644 resource-manager/sql/2023-08-01/ipv6firewallrules/version.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/README.md create mode 100644 resource-manager/sql/2023-08-01/jobagents/client.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/id_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/method_update.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/model_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/model_jobagentidentity.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/model_jobagentproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/model_jobagentupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/model_jobagentuserassignedidentity.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobagents/version.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/README.md create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/client.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/id_credential.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/id_credential_test.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/id_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/method_listbyagent.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/model_jobcredential.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/model_jobcredentialproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobcredentials/version.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/README.md create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/client.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/id_execution.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/id_execution_test.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/id_job.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/id_job_test.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/id_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/method_cancel.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/method_create.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/method_listbyagent.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/method_listbyjob.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/model_jobexecution.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutionproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutiontarget.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobexecutions/version.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/README.md create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/client.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint_test.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/method_listbyagent.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpoint.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpointproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobprivateendpoints/version.go create mode 100644 resource-manager/sql/2023-08-01/jobs/README.md create mode 100644 resource-manager/sql/2023-08-01/jobs/client.go create mode 100644 resource-manager/sql/2023-08-01/jobs/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobs/id_job.go create mode 100644 resource-manager/sql/2023-08-01/jobs/id_job_test.go create mode 100644 resource-manager/sql/2023-08-01/jobs/id_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobs/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-08-01/jobs/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobs/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/jobs/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobs/method_listbyagent.go create mode 100644 resource-manager/sql/2023-08-01/jobs/model_job.go create mode 100644 resource-manager/sql/2023-08-01/jobs/model_jobproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobs/model_jobschedule.go create mode 100644 resource-manager/sql/2023-08-01/jobs/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobs/version.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/README.md create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/client.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/id_execution.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/id_execution_test.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep_test.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/method_listbyjobexecution.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecution.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutionproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutiontarget.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobstepexecutions/version.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/README.md create mode 100644 resource-manager/sql/2023-08-01/jobsteps/client.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_job.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_job_test.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_step.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_step_test.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_version.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_version_test.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_versionstep.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/id_versionstep_test.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/method_getbyversion.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/method_listbyjob.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/method_listbyversion.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/model_jobstep.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/model_jobstepaction.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/model_jobstepexecutionoptions.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/model_jobstepoutput.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/model_jobstepproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobsteps/version.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/README.md create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/client.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution_test.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep_test.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/id_target.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/id_target_test.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbyjobexecution.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbystep.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecution.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutionproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutiontarget.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetexecutions/version.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/README.md create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/client.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/constants.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup_test.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/method_listbyagent.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtarget.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroup.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobtargetgroups/version.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/README.md create mode 100644 resource-manager/sql/2023-08-01/jobversions/client.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/id_job.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/id_job_test.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/id_version.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/id_version_test.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/method_listbyjob.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/model_resource.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/jobversions/version.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/README.md create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/client.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/constants.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/method_disable.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/method_get.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploads.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/predicates.go create mode 100644 resource-manager/sql/2023-08-01/ledgerdigestuploads/version.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/README.md create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/client.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/constants.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/id_location.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/method_capabilitieslistbylocation.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_autopausedelaytimerange.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_editioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpooleditioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperformancelevelcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_instancepooleditioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolfamilycapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolvcorescapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_jobagenteditioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentservicelevelobjectivecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentversioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_licensetypecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_locationcapabilities.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_logsizecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_maintenanceconfigurationcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceeditioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancefamilycapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancevcorescapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceversioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_maxlimitrangecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizerangecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_mincapacitycapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_perdatabaseautopausedelaytimerange.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_performancelevelcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_readscalecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_serverversioncapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_serviceobjectivecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_storagecapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/model_zonepinningcapability.go create mode 100644 resource-manager/sql/2023-08-01/locationcapabilities/version.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/README.md create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/client.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/constants.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_location.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstier.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_copy.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_copybyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_deletebyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_getbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupdatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegrouplocation.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupserver.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_update.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/method_updatebyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparameters.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupoperationresult.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupproperties.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionoperationresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionbackups/version.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/README.md create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/client.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/constants.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/version.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/model_baselongtermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/model_longtermretentionpolicy.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/longtermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/README.md create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/client.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/constants.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptions.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowtimerange.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindowoptions/version.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/README.md create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/client.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/constants.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/method_get.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindows.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowsproperties.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowtimerange.go create mode 100644 resource-manager/sql/2023-08-01/maintenancewindows/version.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_update.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbytable.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumn.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumnproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasecolumns/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasemoveoperations/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/id_query.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/id_query_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/method_listbyquery.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/model_managedinstancequery.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricinterval.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/model_queryproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatistics.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatisticsproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasequeries/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaserestoredetails/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_cancelmove.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_completemove.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_completerestore.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_listinaccessiblebyinstance.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_startmove.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/method_update.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/model_completedatabaserestoredefinition.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasemovedefinition.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasestartmovedefinition.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabases/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/model_resource.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabaseschemas/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityevent.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesecurityevents/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_disablerecommendation.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_enablerecommendation.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_update.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabel.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/method_listbyschema.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetable.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetableproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetables/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_export.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministrator.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministratorproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadministrators/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtc.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancedtcs/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_revalidate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey_test.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekey.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekeyproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancekeys/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperation.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationparameterspair.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationsteps.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceoperations/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstances/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/id_instancepool.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/id_instancepool_test.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_list.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_listbyinstancepool.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_refreshstatus.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_start.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_stop.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/method_update.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_endpointdependency.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_endpointdetail.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceexternaladministrator.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstancepecproperty.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointproperty.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_outboundenvironmentendpoint.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_querymetricinterval.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_querymetricproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_querystatisticsproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_serviceprincipal.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/model_topqueries.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstances/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancetdecertificates/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstancetdecertificates/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancetdecertificates/method_create.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificateproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancetdecertificates/version.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/README.md create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/client.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_disable.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploads.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedledgerdigestuploads/version.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/README.md create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/client.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias_test.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/method_acquire.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsalias.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliascreation.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedserverdnsaliases/version.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/README.md create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/client.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_get.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_reconcile.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigassociation.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigperimeter.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigprofile.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissue.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/predicates.go create mode 100644 resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/version.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/README.md create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/client.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule_test.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/method_get.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallrule.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallruleproperties.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/predicates.go create mode 100644 resource-manager/sql/2023-08-01/outboundfirewallrules/version.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/README.md create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/client.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/constants.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/method_get.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointproperty.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/predicates.go create mode 100644 resource-manager/sql/2023-08-01/privateendpointconnections/version.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/README.md create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/client.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource_test.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/method_get.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/predicates.go create mode 100644 resource-manager/sql/2023-08-01/privatelinkresources/version.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/README.md create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/client.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/constants.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/model_databasekey.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabase.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/recoverabledatabases/version.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/README.md create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/client.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabase.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/recoverablemanageddatabases/version.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/README.md create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/client.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/constants.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink_test.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_failover.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_failoverallowdataloss.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_get.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/method_update.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/model_replicationlink.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkproperties.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdate.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/predicates.go create mode 100644 resource-manager/sql/2023-08-01/replicationlinks/version.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/README.md create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/client.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/constants.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_databasekey.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppeddatabases/version.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/README.md create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/client.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/version.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/README.md create mode 100644 resource-manager/sql/2023-08-01/restorepoints/client.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/constants.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/id_restorepoint.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/id_restorepoint_test.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/method_create.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/method_get.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/model_createdatabaserestorepointdefinition.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/model_restorepoint.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/model_restorepointproperties.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/predicates.go create mode 100644 resource-manager/sql/2023-08-01/restorepoints/version.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/README.md create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/client.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/constants.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/id_column.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/id_column_test.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource_test.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_disablerecommendation.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_enablerecommendation.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_listcurrentbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_listrecommendedbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/method_update.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabel.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelproperties.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/predicates.go create mode 100644 resource-manager/sql/2023-08-01/sensitivitylabels/version.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/README.md create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/client.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/constants.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/id_advisor.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/id_advisor_test.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/method_update.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_advisor.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_advisorproperties.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedaction.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionerrorinfo.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimpactrecord.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimplementationinfo.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionmetricinfo.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionproperties.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionstateinfo.go create mode 100644 resource-manager/sql/2023-08-01/serveradvisors/version.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/README.md create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/client.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/constants.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/method_update.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserveroptions.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserverproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/model_serverautomatictuning.go create mode 100644 resource-manager/sql/2023-08-01/serverautomatictuning/version.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/README.md create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/client.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/constants.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/model_administratorproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/model_serverazureadadministrator.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadadministrators/version.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/README.md create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/client.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_azureadonlyauthproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverazureadonlyauthentications/version.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/README.md create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/client.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/constants.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoption.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoptionproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverconfigurationoptions/version.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicy.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverconnectionpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/README.md create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/client.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/constants.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingscreateorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingsget.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingslistbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditingsettings.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverdevopsaudit/version.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/README.md create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/client.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias_test.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/method_acquire.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsalias.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasacquisition.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverdnsaliases/version.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/README.md create mode 100644 resource-manager/sql/2023-08-01/serverkeys/client.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/constants.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/id_key.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/id_key_test.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/model_serverkey.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/model_serverkeyproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverkeys/version.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/README.md create mode 100644 resource-manager/sql/2023-08-01/serveroperations/client.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/constants.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/model_serveroperation.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/model_serveroperationproperties.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serveroperations/version.go create mode 100644 resource-manager/sql/2023-08-01/servers/README.md create mode 100644 resource-manager/sql/2023-08-01/servers/client.go create mode 100644 resource-manager/sql/2023-08-01/servers/constants.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_checknameavailability.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_get.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_importdatabase.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_list.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_refreshstatus.go create mode 100644 resource-manager/sql/2023-08-01/servers/method_update.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_checknameavailabilityrequest.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_checknameavailabilityresponse.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_importexportoperationresult.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_importexportoperationresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_importnewdatabasedefinition.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_networkisolationsettings.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionrequeststatus.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_privateendpointproperty.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_privatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresult.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_server.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_serverexternaladministrator.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_serverprivateendpointconnection.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_serverproperties.go create mode 100644 resource-manager/sql/2023-08-01/servers/model_serverupdate.go create mode 100644 resource-manager/sql/2023-08-01/servers/predicates.go create mode 100644 resource-manager/sql/2023-08-01/servers/version.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_securityalertspolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_serversecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serversecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/README.md create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/client.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate_test.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/method_get.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificate.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificateproperties.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/predicates.go create mode 100644 resource-manager/sql/2023-08-01/servertrustcertificates/version.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/README.md create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/client.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/constants.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup_test.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/model_serverinfo.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroup.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/servertrustgroups/version.go create mode 100644 resource-manager/sql/2023-08-01/serverusages/README.md create mode 100644 resource-manager/sql/2023-08-01/serverusages/client.go create mode 100644 resource-manager/sql/2023-08-01/serverusages/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/serverusages/model_serverusage.go create mode 100644 resource-manager/sql/2023-08-01/serverusages/model_serverusageproperties.go create mode 100644 resource-manager/sql/2023-08-01/serverusages/predicates.go create mode 100644 resource-manager/sql/2023-08-01/serverusages/version.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-08-01/servervulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/README.md create mode 100644 resource-manager/sql/2023-08-01/sqlagent/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfiguration.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfigurationproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlagent/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/README.md create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/predicates.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/method_execute.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/README.md create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/predicates.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/README.md create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan_test.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_listbyscan.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baseline.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_querycheck.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_remediation.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_varule.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/predicates.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan_test.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/README.md create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/client.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/constants.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_get.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/predicates.go create mode 100644 resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/version.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/README.md create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/client.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/constants.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_get.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_scheduleitem.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/predicates.go create mode 100644 resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/version.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/README.md create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/client.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/id_location.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/id_usage.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/id_usage_test.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/method_get.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusage.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusageproperties.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/predicates.go create mode 100644 resource-manager/sql/2023-08-01/subscriptionusages/version.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/README.md create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/client.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspace.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceproperties.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/predicates.go create mode 100644 resource-manager/sql/2023-08-01/synapselinkworkspaces/version.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/README.md create mode 100644 resource-manager/sql/2023-08-01/syncagents/client.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/constants.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/id_syncagent.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/id_syncagent_test.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/method_generatekey.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/method_get.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/method_listlinkeddatabases.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/model_syncagent.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/model_syncagentkeyproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabase.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabaseproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/model_syncagentproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/predicates.go create mode 100644 resource-manager/sql/2023-08-01/syncagents/version.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/README.md create mode 100644 resource-manager/sql/2023-08-01/syncgroups/client.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/constants.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/id_location.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/id_syncgroup.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/id_syncgroup_test.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_cancelsync.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_listhubschemas.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_listlogs.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_listsyncdatabaseids.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_refreshhubschema.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_triggersync.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/method_update.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_sku.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncdatabaseidproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncfullschemaproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematable.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematablecolumn.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncgroup.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncgrouplogproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncgroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschema.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematable.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematablecolumn.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/syncgroups/version.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/README.md create mode 100644 resource-manager/sql/2023-08-01/syncmembers/client.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/constants.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/id_syncgroup.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/id_syncgroup_test.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/id_syncmember.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/id_syncmember_test.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_get.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_listbysyncgroup.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_listmemberschemas.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_refreshmemberschema.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/method_update.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/model_syncfullschemaproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematable.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematablecolumn.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/model_syncmember.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/model_syncmemberproperties.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/predicates.go create mode 100644 resource-manager/sql/2023-08-01/syncmembers/version.go create mode 100644 resource-manager/sql/2023-08-01/tdecertificates/README.md create mode 100644 resource-manager/sql/2023-08-01/tdecertificates/client.go create mode 100644 resource-manager/sql/2023-08-01/tdecertificates/method_create.go create mode 100644 resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificate.go create mode 100644 resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificateproperties.go create mode 100644 resource-manager/sql/2023-08-01/tdecertificates/version.go create mode 100644 resource-manager/sql/2023-08-01/timezones/README.md create mode 100644 resource-manager/sql/2023-08-01/timezones/client.go create mode 100644 resource-manager/sql/2023-08-01/timezones/id_location.go create mode 100644 resource-manager/sql/2023-08-01/timezones/id_location_test.go create mode 100644 resource-manager/sql/2023-08-01/timezones/id_timezone.go create mode 100644 resource-manager/sql/2023-08-01/timezones/id_timezone_test.go create mode 100644 resource-manager/sql/2023-08-01/timezones/method_get.go create mode 100644 resource-manager/sql/2023-08-01/timezones/method_listbylocation.go create mode 100644 resource-manager/sql/2023-08-01/timezones/model_timezone.go create mode 100644 resource-manager/sql/2023-08-01/timezones/model_timezoneproperties.go create mode 100644 resource-manager/sql/2023-08-01/timezones/predicates.go create mode 100644 resource-manager/sql/2023-08-01/timezones/version.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/README.md create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/client.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/constants.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/method_get.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/model_transparentdataencryptionproperties.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/predicates.go create mode 100644 resource-manager/sql/2023-08-01/transparentdataencryptions/version.go create mode 100644 resource-manager/sql/2023-08-01/usages/README.md create mode 100644 resource-manager/sql/2023-08-01/usages/client.go create mode 100644 resource-manager/sql/2023-08-01/usages/id_instancepool.go create mode 100644 resource-manager/sql/2023-08-01/usages/id_instancepool_test.go create mode 100644 resource-manager/sql/2023-08-01/usages/method_listbyinstancepool.go create mode 100644 resource-manager/sql/2023-08-01/usages/model_name.go create mode 100644 resource-manager/sql/2023-08-01/usages/model_usage.go create mode 100644 resource-manager/sql/2023-08-01/usages/predicates.go create mode 100644 resource-manager/sql/2023-08-01/usages/version.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/README.md create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/client.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/constants.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster_test.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/method_get.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/method_list.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/method_update.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/method_updatednsservers.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/model_updatevirtualclusterdnsserversoperation.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/model_virtualcluster.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterdnsserversproperties.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterproperties.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterupdate.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/predicates.go create mode 100644 resource-manager/sql/2023-08-01/virtualclusters/version.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/README.md create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/client.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/constants.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule_test.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/method_get.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkrule.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkruleproperties.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/predicates.go create mode 100644 resource-manager/sql/2023-08-01/virtualnetworkrules/version.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/README.md create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/client.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier_test.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup_test.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/method_get.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/method_listbyworkloadgroup.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifier.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifierproperties.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/predicates.go create mode 100644 resource-manager/sql/2023-08-01/workloadclassifiers/version.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/README.md create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/client.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup_test.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/method_delete.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/method_get.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroup.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroupproperties.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/predicates.go create mode 100644 resource-manager/sql/2023-08-01/workloadgroups/version.go diff --git a/resource-manager/advisor/2025-01-01/advisorscore/README.md b/resource-manager/advisor/2025-01-01/advisorscore/README.md new file mode 100644 index 00000000000..bd4795d0de0 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/advisorscore` Documentation + +The `advisorscore` SDK allows for interaction with Azure Resource Manager `advisor` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/advisorscore" +``` + + +### Client Initialization + +```go +client := advisorscore.NewAdvisorScoreClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AdvisorScoreClient.Get` + +```go +ctx := context.TODO() +id := advisorscore.NewAdvisorScoreID("12345678-1234-9876-4563-123456789012", "advisorScoreName") + +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: `AdvisorScoreClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/advisor/2025-01-01/advisorscore/client.go b/resource-manager/advisor/2025-01-01/advisorscore/client.go new file mode 100644 index 00000000000..02760e8a079 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/client.go @@ -0,0 +1,26 @@ +package advisorscore + +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 AdvisorScoreClient struct { + Client *resourcemanager.Client +} + +func NewAdvisorScoreClientWithBaseURI(sdkApi sdkEnv.Api) (*AdvisorScoreClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "advisorscore", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AdvisorScoreClient: %+v", err) + } + + return &AdvisorScoreClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/constants.go b/resource-manager/advisor/2025-01-01/advisorscore/constants.go new file mode 100644 index 00000000000..3f69a295d4a --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/constants.go @@ -0,0 +1,54 @@ +package advisorscore + +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 Aggregated string + +const ( + AggregatedDay Aggregated = "day" + AggregatedMonth Aggregated = "month" + AggregatedWeek Aggregated = "week" +) + +func PossibleValuesForAggregated() []string { + return []string{ + string(AggregatedDay), + string(AggregatedMonth), + string(AggregatedWeek), + } +} + +func (s *Aggregated) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAggregated(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAggregated(input string) (*Aggregated, error) { + vals := map[string]Aggregated{ + "day": AggregatedDay, + "month": AggregatedMonth, + "week": AggregatedWeek, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Aggregated(input) + return &out, nil +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore.go b/resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore.go new file mode 100644 index 00000000000..c7e7c7ab1a6 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore.go @@ -0,0 +1,121 @@ +package advisorscore + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AdvisorScoreId{}) +} + +var _ resourceids.ResourceId = &AdvisorScoreId{} + +// AdvisorScoreId is a struct representing the Resource ID for a Advisor Score +type AdvisorScoreId struct { + SubscriptionId string + AdvisorScoreName string +} + +// NewAdvisorScoreID returns a new AdvisorScoreId struct +func NewAdvisorScoreID(subscriptionId string, advisorScoreName string) AdvisorScoreId { + return AdvisorScoreId{ + SubscriptionId: subscriptionId, + AdvisorScoreName: advisorScoreName, + } +} + +// ParseAdvisorScoreID parses 'input' into a AdvisorScoreId +func ParseAdvisorScoreID(input string) (*AdvisorScoreId, error) { + parser := resourceids.NewParserFromResourceIdType(&AdvisorScoreId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AdvisorScoreId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAdvisorScoreIDInsensitively parses 'input' case-insensitively into a AdvisorScoreId +// note: this method should only be used for API response data and not user input +func ParseAdvisorScoreIDInsensitively(input string) (*AdvisorScoreId, error) { + parser := resourceids.NewParserFromResourceIdType(&AdvisorScoreId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AdvisorScoreId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AdvisorScoreId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.AdvisorScoreName, ok = input.Parsed["advisorScoreName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "advisorScoreName", input) + } + + return nil +} + +// ValidateAdvisorScoreID checks that 'input' can be parsed as a Advisor Score ID +func ValidateAdvisorScoreID(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 := ParseAdvisorScoreID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Advisor Score ID +func (id AdvisorScoreId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Advisor/advisorScore/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.AdvisorScoreName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Advisor Score ID +func (id AdvisorScoreId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAdvisor", "Microsoft.Advisor", "Microsoft.Advisor"), + resourceids.StaticSegment("staticAdvisorScore", "advisorScore", "advisorScore"), + resourceids.UserSpecifiedSegment("advisorScoreName", "advisorScoreName"), + } +} + +// String returns a human-readable description of this Advisor Score ID +func (id AdvisorScoreId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Advisor Score Name: %q", id.AdvisorScoreName), + } + return fmt.Sprintf("Advisor Score (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore_test.go b/resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore_test.go new file mode 100644 index 00000000000..56079d118c4 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/id_advisorscore_test.go @@ -0,0 +1,237 @@ +package advisorscore + +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 = &AdvisorScoreId{} + +func TestNewAdvisorScoreID(t *testing.T) { + id := NewAdvisorScoreID("12345678-1234-9876-4563-123456789012", "advisorScoreName") + + 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.AdvisorScoreName != "advisorScoreName" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorScoreName'", id.AdvisorScoreName, "advisorScoreName") + } +} + +func TestFormatAdvisorScoreID(t *testing.T) { + actual := NewAdvisorScoreID("12345678-1234-9876-4563-123456789012", "advisorScoreName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore/advisorScoreName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAdvisorScoreID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AdvisorScoreId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore/advisorScoreName", + Expected: &AdvisorScoreId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + AdvisorScoreName: "advisorScoreName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore/advisorScoreName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAdvisorScoreID(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.AdvisorScoreName != v.Expected.AdvisorScoreName { + t.Fatalf("Expected %q but got %q for AdvisorScoreName", v.Expected.AdvisorScoreName, actual.AdvisorScoreName) + } + + } +} + +func TestParseAdvisorScoreIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AdvisorScoreId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr/aDvIsOrScOrE", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore/advisorScoreName", + Expected: &AdvisorScoreId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + AdvisorScoreName: "advisorScoreName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/advisorScore/advisorScoreName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr/aDvIsOrScOrE/aDvIsOrScOrEnAmE", + Expected: &AdvisorScoreId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + AdvisorScoreName: "aDvIsOrScOrEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr/aDvIsOrScOrE/aDvIsOrScOrEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAdvisorScoreIDInsensitively(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.AdvisorScoreName != v.Expected.AdvisorScoreName { + t.Fatalf("Expected %q but got %q for AdvisorScoreName", v.Expected.AdvisorScoreName, actual.AdvisorScoreName) + } + + } +} + +func TestSegmentsForAdvisorScoreId(t *testing.T) { + segments := AdvisorScoreId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AdvisorScoreId 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/advisor/2025-01-01/advisorscore/method_get.go b/resource-manager/advisor/2025-01-01/advisorscore/method_get.go new file mode 100644 index 00000000000..74d3f7df524 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/method_get.go @@ -0,0 +1,53 @@ +package advisorscore + +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 *AdvisorScoreEntity +} + +// Get ... +func (c AdvisorScoreClient) Get(ctx context.Context, id AdvisorScoreId) (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 AdvisorScoreEntity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/method_list.go b/resource-manager/advisor/2025-01-01/advisorscore/method_list.go new file mode 100644 index 00000000000..a6c1398add8 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/method_list.go @@ -0,0 +1,55 @@ +package advisorscore + +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 *AdvisorScoreResponse +} + +// List ... +func (c AdvisorScoreClient) List(ctx context.Context, id commonids.SubscriptionId) (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.Advisor/advisorScore", 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 AdvisorScoreResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentity.go b/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentity.go new file mode 100644 index 00000000000..981db5b6839 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentity.go @@ -0,0 +1,16 @@ +package advisorscore + +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 AdvisorScoreEntity struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvisorScoreEntityProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentityproperties.go b/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentityproperties.go new file mode 100644 index 00000000000..1c421517ccd --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreentityproperties.go @@ -0,0 +1,9 @@ +package advisorscore + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdvisorScoreEntityProperties struct { + LastRefreshedScore *ScoreEntity `json:"lastRefreshedScore,omitempty"` + TimeSeries *[]TimeSeriesEntityTimeSeriesInlined `json:"timeSeries,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreresponse.go b/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreresponse.go new file mode 100644 index 00000000000..009425f7849 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/model_advisorscoreresponse.go @@ -0,0 +1,8 @@ +package advisorscore + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdvisorScoreResponse struct { + Value *[]AdvisorScoreEntity `json:"value,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/model_scoreentity.go b/resource-manager/advisor/2025-01-01/advisorscore/model_scoreentity.go new file mode 100644 index 00000000000..830cbeb878b --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/model_scoreentity.go @@ -0,0 +1,13 @@ +package advisorscore + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScoreEntity struct { + CategoryCount *float64 `json:"categoryCount,omitempty"` + ConsumptionUnits *float64 `json:"consumptionUnits,omitempty"` + Date *string `json:"date,omitempty"` + ImpactedResourceCount *float64 `json:"impactedResourceCount,omitempty"` + PotentialScoreIncrease *float64 `json:"potentialScoreIncrease,omitempty"` + Score *float64 `json:"score,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/model_timeseriesentitytimeseriesinlined.go b/resource-manager/advisor/2025-01-01/advisorscore/model_timeseriesentitytimeseriesinlined.go new file mode 100644 index 00000000000..f78079268ec --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/model_timeseriesentitytimeseriesinlined.go @@ -0,0 +1,9 @@ +package advisorscore + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeSeriesEntityTimeSeriesInlined struct { + AggregationLevel *Aggregated `json:"aggregationLevel,omitempty"` + ScoreHistory *[]ScoreEntity `json:"scoreHistory,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/advisorscore/version.go b/resource-manager/advisor/2025-01-01/advisorscore/version.go new file mode 100644 index 00000000000..c52c55a6c0f --- /dev/null +++ b/resource-manager/advisor/2025-01-01/advisorscore/version.go @@ -0,0 +1,10 @@ +package advisorscore + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/advisorscore/2025-01-01" +} diff --git a/resource-manager/advisor/2025-01-01/client.go b/resource-manager/advisor/2025-01-01/client.go new file mode 100644 index 00000000000..f6e204b2b89 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/client.go @@ -0,0 +1,82 @@ +package v2025_01_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/advisorscore" + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/configurations" + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/generaterecommendations" + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/getrecommendations" + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/metadata" + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/prediction" + "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/suppressions" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AdvisorScore *advisorscore.AdvisorScoreClient + Configurations *configurations.ConfigurationsClient + GenerateRecommendations *generaterecommendations.GenerateRecommendationsClient + GetRecommendations *getrecommendations.GetRecommendationsClient + Metadata *metadata.MetadataClient + Prediction *prediction.PredictionClient + Suppressions *suppressions.SuppressionsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + advisorScoreClient, err := advisorscore.NewAdvisorScoreClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AdvisorScore client: %+v", err) + } + configureFunc(advisorScoreClient.Client) + + configurationsClient, err := configurations.NewConfigurationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Configurations client: %+v", err) + } + configureFunc(configurationsClient.Client) + + generateRecommendationsClient, err := generaterecommendations.NewGenerateRecommendationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GenerateRecommendations client: %+v", err) + } + configureFunc(generateRecommendationsClient.Client) + + getRecommendationsClient, err := getrecommendations.NewGetRecommendationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GetRecommendations client: %+v", err) + } + configureFunc(getRecommendationsClient.Client) + + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) + + predictionClient, err := prediction.NewPredictionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Prediction client: %+v", err) + } + configureFunc(predictionClient.Client) + + suppressionsClient, err := suppressions.NewSuppressionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Suppressions client: %+v", err) + } + configureFunc(suppressionsClient.Client) + + return &Client{ + AdvisorScore: advisorScoreClient, + Configurations: configurationsClient, + GenerateRecommendations: generateRecommendationsClient, + GetRecommendations: getRecommendationsClient, + Metadata: metadataClient, + Prediction: predictionClient, + Suppressions: suppressionsClient, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/configurations/README.md b/resource-manager/advisor/2025-01-01/configurations/README.md new file mode 100644 index 00000000000..9aafdb10e64 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/README.md @@ -0,0 +1,97 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/configurations` Documentation + +The `configurations` SDK allows for interaction with Azure Resource Manager `advisor` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/configurations" +``` + + +### Client Initialization + +```go +client := configurations.NewConfigurationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConfigurationsClient.CreateInResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := configurations.ConfigData{ + // ... +} + + +read, err := client.CreateInResourceGroup(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConfigurationsClient.CreateInSubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := configurations.ConfigData{ + // ... +} + + +read, err := client.CreateInSubscription(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConfigurationsClient.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: `ConfigurationsClient.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 +} +``` diff --git a/resource-manager/advisor/2025-01-01/configurations/client.go b/resource-manager/advisor/2025-01-01/configurations/client.go new file mode 100644 index 00000000000..f927d73df19 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/client.go @@ -0,0 +1,26 @@ +package configurations + +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 ConfigurationsClient struct { + Client *resourcemanager.Client +} + +func NewConfigurationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ConfigurationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "configurations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ConfigurationsClient: %+v", err) + } + + return &ConfigurationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/configurations/constants.go b/resource-manager/advisor/2025-01-01/configurations/constants.go new file mode 100644 index 00000000000..7df39004dbf --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/constants.go @@ -0,0 +1,201 @@ +package configurations + +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 CPUThreshold string + +const ( + CPUThresholdFive CPUThreshold = "5" + CPUThresholdOneFive CPUThreshold = "15" + CPUThresholdOneZero CPUThreshold = "10" + CPUThresholdTwoZero CPUThreshold = "20" +) + +func PossibleValuesForCPUThreshold() []string { + return []string{ + string(CPUThresholdFive), + string(CPUThresholdOneFive), + string(CPUThresholdOneZero), + string(CPUThresholdTwoZero), + } +} + +func (s *CPUThreshold) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCPUThreshold(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCPUThreshold(input string) (*CPUThreshold, error) { + vals := map[string]CPUThreshold{ + "5": CPUThresholdFive, + "15": CPUThresholdOneFive, + "10": CPUThresholdOneZero, + "20": CPUThresholdTwoZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CPUThreshold(input) + return &out, nil +} + +type Category string + +const ( + CategoryCost Category = "Cost" + CategoryHighAvailability Category = "HighAvailability" + CategoryOperationalExcellence Category = "OperationalExcellence" + CategoryPerformance Category = "Performance" + CategorySecurity Category = "Security" +) + +func PossibleValuesForCategory() []string { + return []string{ + string(CategoryCost), + string(CategoryHighAvailability), + string(CategoryOperationalExcellence), + string(CategoryPerformance), + string(CategorySecurity), + } +} + +func (s *Category) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCategory(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCategory(input string) (*Category, error) { + vals := map[string]Category{ + "cost": CategoryCost, + "highavailability": CategoryHighAvailability, + "operationalexcellence": CategoryOperationalExcellence, + "performance": CategoryPerformance, + "security": CategorySecurity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Category(input) + return &out, nil +} + +type DigestConfigState string + +const ( + DigestConfigStateActive DigestConfigState = "Active" + DigestConfigStateDisabled DigestConfigState = "Disabled" +) + +func PossibleValuesForDigestConfigState() []string { + return []string{ + string(DigestConfigStateActive), + string(DigestConfigStateDisabled), + } +} + +func (s *DigestConfigState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDigestConfigState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDigestConfigState(input string) (*DigestConfigState, error) { + vals := map[string]DigestConfigState{ + "active": DigestConfigStateActive, + "disabled": DigestConfigStateDisabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DigestConfigState(input) + return &out, nil +} + +type Duration string + +const ( + DurationNineZero Duration = "90" + DurationOneFour Duration = "14" + DurationSeven Duration = "7" + DurationSixZero Duration = "60" + DurationThreeZero Duration = "30" + DurationTwoOne Duration = "21" +) + +func PossibleValuesForDuration() []string { + return []string{ + string(DurationNineZero), + string(DurationOneFour), + string(DurationSeven), + string(DurationSixZero), + string(DurationThreeZero), + string(DurationTwoOne), + } +} + +func (s *Duration) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDuration(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDuration(input string) (*Duration, error) { + vals := map[string]Duration{ + "90": DurationNineZero, + "14": DurationOneFour, + "7": DurationSeven, + "60": DurationSixZero, + "30": DurationThreeZero, + "21": DurationTwoOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Duration(input) + return &out, nil +} diff --git a/resource-manager/advisor/2025-01-01/configurations/method_createinresourcegroup.go b/resource-manager/advisor/2025-01-01/configurations/method_createinresourcegroup.go new file mode 100644 index 00000000000..a46ebc075c7 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/method_createinresourcegroup.go @@ -0,0 +1,59 @@ +package configurations + +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 CreateInResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ConfigData +} + +// CreateInResourceGroup ... +func (c ConfigurationsClient) CreateInResourceGroup(ctx context.Context, id commonids.ResourceGroupId, input ConfigData) (result CreateInResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/configurations/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 ConfigData + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/configurations/method_createinsubscription.go b/resource-manager/advisor/2025-01-01/configurations/method_createinsubscription.go new file mode 100644 index 00000000000..64ab1cb6e84 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/method_createinsubscription.go @@ -0,0 +1,59 @@ +package configurations + +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 CreateInSubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ConfigData +} + +// CreateInSubscription ... +func (c ConfigurationsClient) CreateInSubscription(ctx context.Context, id commonids.SubscriptionId, input ConfigData) (result CreateInSubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/configurations/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 ConfigData + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/configurations/method_listbyresourcegroup.go b/resource-manager/advisor/2025-01-01/configurations/method_listbyresourcegroup.go new file mode 100644 index 00000000000..16198a62599 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package configurations + +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 *[]ConfigData +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ConfigData +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ConfigurationsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/configurations", 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 *[]ConfigData `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 ConfigurationsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ConfigDataOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ConfigurationsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConfigDataOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ConfigData, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/advisor/2025-01-01/configurations/method_listbysubscription.go b/resource-manager/advisor/2025-01-01/configurations/method_listbysubscription.go new file mode 100644 index 00000000000..d1861ed0179 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/method_listbysubscription.go @@ -0,0 +1,106 @@ +package configurations + +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 *[]ConfigData +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ConfigData +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ConfigurationsClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/configurations", 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 *[]ConfigData `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 ConfigurationsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ConfigDataOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ConfigurationsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConfigDataOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]ConfigData, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/advisor/2025-01-01/configurations/model_configdata.go b/resource-manager/advisor/2025-01-01/configurations/model_configdata.go new file mode 100644 index 00000000000..70dea5018b8 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/model_configdata.go @@ -0,0 +1,16 @@ +package configurations + +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 ConfigData struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ConfigDataProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/configurations/model_configdataproperties.go b/resource-manager/advisor/2025-01-01/configurations/model_configdataproperties.go new file mode 100644 index 00000000000..a58db787184 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/model_configdataproperties.go @@ -0,0 +1,11 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigDataProperties struct { + Digests *[]DigestConfig `json:"digests,omitempty"` + Duration *Duration `json:"duration,omitempty"` + Exclude *bool `json:"exclude,omitempty"` + LowCPUThreshold *CPUThreshold `json:"lowCpuThreshold,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/configurations/model_digestconfig.go b/resource-manager/advisor/2025-01-01/configurations/model_digestconfig.go new file mode 100644 index 00000000000..8d94f00aeb4 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/model_digestconfig.go @@ -0,0 +1,13 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DigestConfig struct { + ActionGroupResourceId *string `json:"actionGroupResourceId,omitempty"` + Categories *[]Category `json:"categories,omitempty"` + Frequency *int64 `json:"frequency,omitempty"` + Language *string `json:"language,omitempty"` + Name *string `json:"name,omitempty"` + State *DigestConfigState `json:"state,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/configurations/predicates.go b/resource-manager/advisor/2025-01-01/configurations/predicates.go new file mode 100644 index 00000000000..c91d4694b71 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/predicates.go @@ -0,0 +1,27 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigDataOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ConfigDataOperationPredicate) Matches(input ConfigData) 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/advisor/2025-01-01/configurations/version.go b/resource-manager/advisor/2025-01-01/configurations/version.go new file mode 100644 index 00000000000..be18dd85ce4 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/configurations/version.go @@ -0,0 +1,10 @@ +package configurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/configurations/2025-01-01" +} diff --git a/resource-manager/advisor/2025-01-01/generaterecommendations/client.go b/resource-manager/advisor/2025-01-01/generaterecommendations/client.go new file mode 100644 index 00000000000..8ba18d18bb1 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/generaterecommendations/client.go @@ -0,0 +1,26 @@ +package generaterecommendations + +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 GenerateRecommendationsClient struct { + Client *resourcemanager.Client +} + +func NewGenerateRecommendationsClientWithBaseURI(sdkApi sdkEnv.Api) (*GenerateRecommendationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "generaterecommendations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GenerateRecommendationsClient: %+v", err) + } + + return &GenerateRecommendationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation.go b/resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation.go new file mode 100644 index 00000000000..231e4469c6f --- /dev/null +++ b/resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation.go @@ -0,0 +1,121 @@ +package generaterecommendations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GenerateRecommendationId{}) +} + +var _ resourceids.ResourceId = &GenerateRecommendationId{} + +// GenerateRecommendationId is a struct representing the Resource ID for a Generate Recommendation +type GenerateRecommendationId struct { + SubscriptionId string + OperationId string +} + +// NewGenerateRecommendationID returns a new GenerateRecommendationId struct +func NewGenerateRecommendationID(subscriptionId string, operationId string) GenerateRecommendationId { + return GenerateRecommendationId{ + SubscriptionId: subscriptionId, + OperationId: operationId, + } +} + +// ParseGenerateRecommendationID parses 'input' into a GenerateRecommendationId +func ParseGenerateRecommendationID(input string) (*GenerateRecommendationId, error) { + parser := resourceids.NewParserFromResourceIdType(&GenerateRecommendationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GenerateRecommendationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGenerateRecommendationIDInsensitively parses 'input' case-insensitively into a GenerateRecommendationId +// note: this method should only be used for API response data and not user input +func ParseGenerateRecommendationIDInsensitively(input string) (*GenerateRecommendationId, error) { + parser := resourceids.NewParserFromResourceIdType(&GenerateRecommendationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GenerateRecommendationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GenerateRecommendationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateGenerateRecommendationID checks that 'input' can be parsed as a Generate Recommendation ID +func ValidateGenerateRecommendationID(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 := ParseGenerateRecommendationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Generate Recommendation ID +func (id GenerateRecommendationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Advisor/generateRecommendations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Generate Recommendation ID +func (id GenerateRecommendationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAdvisor", "Microsoft.Advisor", "Microsoft.Advisor"), + resourceids.StaticSegment("staticGenerateRecommendations", "generateRecommendations", "generateRecommendations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Generate Recommendation ID +func (id GenerateRecommendationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Generate Recommendation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation_test.go b/resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation_test.go new file mode 100644 index 00000000000..174b0c92d80 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/generaterecommendations/id_generaterecommendation_test.go @@ -0,0 +1,237 @@ +package generaterecommendations + +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 = &GenerateRecommendationId{} + +func TestNewGenerateRecommendationID(t *testing.T) { + id := NewGenerateRecommendationID("12345678-1234-9876-4563-123456789012", "operationId") + + 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.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatGenerateRecommendationID(t *testing.T) { + actual := NewGenerateRecommendationID("12345678-1234-9876-4563-123456789012", "operationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGenerateRecommendationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GenerateRecommendationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations/operationId", + Expected: &GenerateRecommendationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGenerateRecommendationID(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.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseGenerateRecommendationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GenerateRecommendationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr/gEnErAtErEcOmMeNdAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations/operationId", + Expected: &GenerateRecommendationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Advisor/generateRecommendations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr/gEnErAtErEcOmMeNdAtIoNs/oPeRaTiOnId", + Expected: &GenerateRecommendationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + OperationId: "oPeRaTiOnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aDvIsOr/gEnErAtErEcOmMeNdAtIoNs/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGenerateRecommendationIDInsensitively(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.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForGenerateRecommendationId(t *testing.T) { + segments := GenerateRecommendationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GenerateRecommendationId 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/advisor/2025-01-01/generaterecommendations/method_recommendationsgenerate.go b/resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgenerate.go new file mode 100644 index 00000000000..85deb80873e --- /dev/null +++ b/resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgenerate.go @@ -0,0 +1,48 @@ +package generaterecommendations + +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 RecommendationsGenerateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RecommendationsGenerate ... +func (c GenerateRecommendationsClient) RecommendationsGenerate(ctx context.Context, id commonids.SubscriptionId) (result RecommendationsGenerateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/generateRecommendations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgetgeneratestatus.go b/resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgetgeneratestatus.go new file mode 100644 index 00000000000..eee0c8406d3 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/generaterecommendations/method_recommendationsgetgeneratestatus.go @@ -0,0 +1,47 @@ +package generaterecommendations + +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 RecommendationsGetGenerateStatusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RecommendationsGetGenerateStatus ... +func (c GenerateRecommendationsClient) RecommendationsGetGenerateStatus(ctx context.Context, id GenerateRecommendationId) (result RecommendationsGetGenerateStatusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + 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 + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/generaterecommendations/version.go b/resource-manager/advisor/2025-01-01/generaterecommendations/version.go new file mode 100644 index 00000000000..a2715b002a0 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/generaterecommendations/version.go @@ -0,0 +1,10 @@ +package generaterecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/generaterecommendations/2025-01-01" +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/README.md b/resource-manager/advisor/2025-01-01/getrecommendations/README.md new file mode 100644 index 00000000000..4f02f7ac023 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/getrecommendations` Documentation + +The `getrecommendations` SDK allows for interaction with Azure Resource Manager `advisor` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/getrecommendations" +``` + + +### Client Initialization + +```go +client := getrecommendations.NewGetRecommendationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GetRecommendationsClient.RecommendationsGet` + +```go +ctx := context.TODO() +id := getrecommendations.NewScopedRecommendationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId") + +read, err := client.RecommendationsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GetRecommendationsClient.RecommendationsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.RecommendationsList(ctx, id, getrecommendations.DefaultRecommendationsListOperationOptions())` can be used to do batched pagination +items, err := client.RecommendationsListComplete(ctx, id, getrecommendations.DefaultRecommendationsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/client.go b/resource-manager/advisor/2025-01-01/getrecommendations/client.go new file mode 100644 index 00000000000..47fd270e5d3 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/client.go @@ -0,0 +1,26 @@ +package getrecommendations + +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 GetRecommendationsClient struct { + Client *resourcemanager.Client +} + +func NewGetRecommendationsClientWithBaseURI(sdkApi sdkEnv.Api) (*GetRecommendationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "getrecommendations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GetRecommendationsClient: %+v", err) + } + + return &GetRecommendationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/constants.go b/resource-manager/advisor/2025-01-01/getrecommendations/constants.go new file mode 100644 index 00000000000..5de5f1f06aa --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/constants.go @@ -0,0 +1,210 @@ +package getrecommendations + +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 Category string + +const ( + CategoryCost Category = "Cost" + CategoryHighAvailability Category = "HighAvailability" + CategoryOperationalExcellence Category = "OperationalExcellence" + CategoryPerformance Category = "Performance" + CategorySecurity Category = "Security" +) + +func PossibleValuesForCategory() []string { + return []string{ + string(CategoryCost), + string(CategoryHighAvailability), + string(CategoryOperationalExcellence), + string(CategoryPerformance), + string(CategorySecurity), + } +} + +func (s *Category) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCategory(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCategory(input string) (*Category, error) { + vals := map[string]Category{ + "cost": CategoryCost, + "highavailability": CategoryHighAvailability, + "operationalexcellence": CategoryOperationalExcellence, + "performance": CategoryPerformance, + "security": CategorySecurity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Category(input) + return &out, nil +} + +type Control string + +const ( + ControlBusinessContinuity Control = "BusinessContinuity" + ControlDisasterRecovery Control = "DisasterRecovery" + ControlHighAvailability Control = "HighAvailability" + ControlMonitoringAndAlerting Control = "MonitoringAndAlerting" + ControlOther Control = "Other" + ControlPersonalized Control = "Personalized" + ControlPrioritizedRecommendations Control = "PrioritizedRecommendations" + ControlScalability Control = "Scalability" + ControlServiceUpgradeAndRetirement Control = "ServiceUpgradeAndRetirement" +) + +func PossibleValuesForControl() []string { + return []string{ + string(ControlBusinessContinuity), + string(ControlDisasterRecovery), + string(ControlHighAvailability), + string(ControlMonitoringAndAlerting), + string(ControlOther), + string(ControlPersonalized), + string(ControlPrioritizedRecommendations), + string(ControlScalability), + string(ControlServiceUpgradeAndRetirement), + } +} + +func (s *Control) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseControl(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseControl(input string) (*Control, error) { + vals := map[string]Control{ + "businesscontinuity": ControlBusinessContinuity, + "disasterrecovery": ControlDisasterRecovery, + "highavailability": ControlHighAvailability, + "monitoringandalerting": ControlMonitoringAndAlerting, + "other": ControlOther, + "personalized": ControlPersonalized, + "prioritizedrecommendations": ControlPrioritizedRecommendations, + "scalability": ControlScalability, + "serviceupgradeandretirement": ControlServiceUpgradeAndRetirement, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Control(input) + return &out, nil +} + +type Impact string + +const ( + ImpactHigh Impact = "High" + ImpactLow Impact = "Low" + ImpactMedium Impact = "Medium" +) + +func PossibleValuesForImpact() []string { + return []string{ + string(ImpactHigh), + string(ImpactLow), + string(ImpactMedium), + } +} + +func (s *Impact) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImpact(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImpact(input string) (*Impact, error) { + vals := map[string]Impact{ + "high": ImpactHigh, + "low": ImpactLow, + "medium": ImpactMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Impact(input) + return &out, nil +} + +type Risk string + +const ( + RiskError Risk = "Error" + RiskNone Risk = "None" + RiskWarning Risk = "Warning" +) + +func PossibleValuesForRisk() []string { + return []string{ + string(RiskError), + string(RiskNone), + string(RiskWarning), + } +} + +func (s *Risk) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRisk(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRisk(input string) (*Risk, error) { + vals := map[string]Risk{ + "error": RiskError, + "none": RiskNone, + "warning": RiskWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Risk(input) + return &out, nil +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation.go b/resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation.go new file mode 100644 index 00000000000..5a00b3f7c31 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation.go @@ -0,0 +1,120 @@ +package getrecommendations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedRecommendationId{}) +} + +var _ resourceids.ResourceId = &ScopedRecommendationId{} + +// ScopedRecommendationId is a struct representing the Resource ID for a Scoped Recommendation +type ScopedRecommendationId struct { + ResourceUri string + RecommendationId string +} + +// NewScopedRecommendationID returns a new ScopedRecommendationId struct +func NewScopedRecommendationID(resourceUri string, recommendationId string) ScopedRecommendationId { + return ScopedRecommendationId{ + ResourceUri: resourceUri, + RecommendationId: recommendationId, + } +} + +// ParseScopedRecommendationID parses 'input' into a ScopedRecommendationId +func ParseScopedRecommendationID(input string) (*ScopedRecommendationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedRecommendationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedRecommendationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedRecommendationIDInsensitively parses 'input' case-insensitively into a ScopedRecommendationId +// note: this method should only be used for API response data and not user input +func ParseScopedRecommendationIDInsensitively(input string) (*ScopedRecommendationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedRecommendationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedRecommendationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedRecommendationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ResourceUri, ok = input.Parsed["resourceUri"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceUri", input) + } + + if id.RecommendationId, ok = input.Parsed["recommendationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recommendationId", input) + } + + return nil +} + +// ValidateScopedRecommendationID checks that 'input' can be parsed as a Scoped Recommendation ID +func ValidateScopedRecommendationID(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 := ParseScopedRecommendationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Recommendation ID +func (id ScopedRecommendationId) ID() string { + fmtString := "/%s/providers/Microsoft.Advisor/recommendations/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.ResourceUri, "/"), id.RecommendationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Recommendation ID +func (id ScopedRecommendationId) 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("staticMicrosoftAdvisor", "Microsoft.Advisor", "Microsoft.Advisor"), + resourceids.StaticSegment("staticRecommendations", "recommendations", "recommendations"), + resourceids.UserSpecifiedSegment("recommendationId", "recommendationId"), + } +} + +// String returns a human-readable description of this Scoped Recommendation ID +func (id ScopedRecommendationId) String() string { + components := []string{ + fmt.Sprintf("Resource Uri: %q", id.ResourceUri), + fmt.Sprintf("Recommendation: %q", id.RecommendationId), + } + return fmt.Sprintf("Scoped Recommendation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation_test.go b/resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation_test.go new file mode 100644 index 00000000000..d5d0b1ff516 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/id_scopedrecommendation_test.go @@ -0,0 +1,222 @@ +package getrecommendations + +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 = &ScopedRecommendationId{} + +func TestNewScopedRecommendationID(t *testing.T) { + id := NewScopedRecommendationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId") + + 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.RecommendationId != "recommendationId" { + t.Fatalf("Expected %q but got %q for Segment 'RecommendationId'", id.RecommendationId, "recommendationId") + } +} + +func TestFormatScopedRecommendationID(t *testing.T) { + actual := NewScopedRecommendationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedRecommendationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedRecommendationId + }{ + { + // 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.Advisor", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId", + Expected: &ScopedRecommendationId{ + ResourceUri: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + RecommendationId: "recommendationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedRecommendationID(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.RecommendationId != v.Expected.RecommendationId { + t.Fatalf("Expected %q but got %q for RecommendationId", v.Expected.RecommendationId, actual.RecommendationId) + } + + } +} + +func TestParseScopedRecommendationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedRecommendationId + }{ + { + // 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.Advisor", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr/rEcOmMeNdAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId", + Expected: &ScopedRecommendationId{ + ResourceUri: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + RecommendationId: "recommendationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr/rEcOmMeNdAtIoNs/rEcOmMeNdAtIoNiD", + Expected: &ScopedRecommendationId{ + ResourceUri: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + RecommendationId: "rEcOmMeNdAtIoNiD", + }, + }, + { + // 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.aDvIsOr/rEcOmMeNdAtIoNs/rEcOmMeNdAtIoNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedRecommendationIDInsensitively(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.RecommendationId != v.Expected.RecommendationId { + t.Fatalf("Expected %q but got %q for RecommendationId", v.Expected.RecommendationId, actual.RecommendationId) + } + + } +} + +func TestSegmentsForScopedRecommendationId(t *testing.T) { + segments := ScopedRecommendationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedRecommendationId 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/advisor/2025-01-01/getrecommendations/method_recommendationsget.go b/resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationsget.go new file mode 100644 index 00000000000..d10071892c4 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationsget.go @@ -0,0 +1,53 @@ +package getrecommendations + +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 RecommendationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceRecommendationBase +} + +// RecommendationsGet ... +func (c GetRecommendationsClient) RecommendationsGet(ctx context.Context, id ScopedRecommendationId) (result RecommendationsGetOperationResponse, 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 ResourceRecommendationBase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationslist.go b/resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationslist.go new file mode 100644 index 00000000000..4ab343130b8 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/method_recommendationslist.go @@ -0,0 +1,139 @@ +package getrecommendations + +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 RecommendationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceRecommendationBase +} + +type RecommendationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceRecommendationBase +} + +type RecommendationsListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultRecommendationsListOperationOptions() RecommendationsListOperationOptions { + return RecommendationsListOperationOptions{} +} + +func (o RecommendationsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o RecommendationsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o RecommendationsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type RecommendationsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *RecommendationsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// RecommendationsList ... +func (c GetRecommendationsClient) RecommendationsList(ctx context.Context, id commonids.SubscriptionId, options RecommendationsListOperationOptions) (result RecommendationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &RecommendationsListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/recommendations", 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 *[]ResourceRecommendationBase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// RecommendationsListComplete retrieves all the results into a single object +func (c GetRecommendationsClient) RecommendationsListComplete(ctx context.Context, id commonids.SubscriptionId, options RecommendationsListOperationOptions) (RecommendationsListCompleteResult, error) { + return c.RecommendationsListCompleteMatchingPredicate(ctx, id, options, ResourceRecommendationBaseOperationPredicate{}) +} + +// RecommendationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GetRecommendationsClient) RecommendationsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options RecommendationsListOperationOptions, predicate ResourceRecommendationBaseOperationPredicate) (result RecommendationsListCompleteResult, err error) { + items := make([]ResourceRecommendationBase, 0) + + resp, err := c.RecommendationsList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = RecommendationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/model_recommendationproperties.go b/resource-manager/advisor/2025-01-01/getrecommendations/model_recommendationproperties.go new file mode 100644 index 00000000000..af8187a00eb --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/model_recommendationproperties.go @@ -0,0 +1,45 @@ +package getrecommendations + +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 RecommendationProperties struct { + Actions *[]map[string]interface{} `json:"actions,omitempty"` + Category *Category `json:"category,omitempty"` + Control *Control `json:"control,omitempty"` + Description *string `json:"description,omitempty"` + ExposedMetadataProperties *map[string]interface{} `json:"exposedMetadataProperties,omitempty"` + ExtendedProperties *map[string]string `json:"extendedProperties,omitempty"` + Impact *Impact `json:"impact,omitempty"` + ImpactedField *string `json:"impactedField,omitempty"` + ImpactedValue *string `json:"impactedValue,omitempty"` + Label *string `json:"label,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + LearnMoreLink *string `json:"learnMoreLink,omitempty"` + Metadata *map[string]interface{} `json:"metadata,omitempty"` + PotentialBenefits *string `json:"potentialBenefits,omitempty"` + RecommendationTypeId *string `json:"recommendationTypeId,omitempty"` + Remediation *map[string]interface{} `json:"remediation,omitempty"` + ResourceMetadata *ResourceMetadata `json:"resourceMetadata,omitempty"` + Risk *Risk `json:"risk,omitempty"` + ShortDescription *ShortDescription `json:"shortDescription,omitempty"` + SuppressionIds *[]string `json:"suppressionIds,omitempty"` +} + +func (o *RecommendationProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendationProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/model_resourcemetadata.go b/resource-manager/advisor/2025-01-01/getrecommendations/model_resourcemetadata.go new file mode 100644 index 00000000000..2676e7c0df9 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/model_resourcemetadata.go @@ -0,0 +1,12 @@ +package getrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceMetadata struct { + Action *map[string]interface{} `json:"action,omitempty"` + Plural *string `json:"plural,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + Singular *string `json:"singular,omitempty"` + Source *string `json:"source,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/model_resourcerecommendationbase.go b/resource-manager/advisor/2025-01-01/getrecommendations/model_resourcerecommendationbase.go new file mode 100644 index 00000000000..d24d3e1593b --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/model_resourcerecommendationbase.go @@ -0,0 +1,16 @@ +package getrecommendations + +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 ResourceRecommendationBase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/model_shortdescription.go b/resource-manager/advisor/2025-01-01/getrecommendations/model_shortdescription.go new file mode 100644 index 00000000000..85121edfbf2 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/model_shortdescription.go @@ -0,0 +1,9 @@ +package getrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShortDescription struct { + Problem *string `json:"problem,omitempty"` + Solution *string `json:"solution,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/getrecommendations/predicates.go b/resource-manager/advisor/2025-01-01/getrecommendations/predicates.go new file mode 100644 index 00000000000..a958f48fae1 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/predicates.go @@ -0,0 +1,27 @@ +package getrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceRecommendationBaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceRecommendationBaseOperationPredicate) Matches(input ResourceRecommendationBase) 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/advisor/2025-01-01/getrecommendations/version.go b/resource-manager/advisor/2025-01-01/getrecommendations/version.go new file mode 100644 index 00000000000..71082adc4e5 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/getrecommendations/version.go @@ -0,0 +1,10 @@ +package getrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/getrecommendations/2025-01-01" +} diff --git a/resource-manager/advisor/2025-01-01/metadata/README.md b/resource-manager/advisor/2025-01-01/metadata/README.md new file mode 100644 index 00000000000..d4b4533bcec --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/metadata` Documentation + +The `metadata` SDK allows for interaction with Azure Resource Manager `advisor` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/metadata" +``` + + +### Client Initialization + +```go +client := metadata.NewMetadataClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MetadataClient.RecommendationMetadataGet` + +```go +ctx := context.TODO() +id := metadata.NewMetadataID("metadataName") + +read, err := client.RecommendationMetadataGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MetadataClient.RecommendationMetadataList` + +```go +ctx := context.TODO() + + +// alternatively `client.RecommendationMetadataList(ctx, metadata.DefaultRecommendationMetadataListOperationOptions())` can be used to do batched pagination +items, err := client.RecommendationMetadataListComplete(ctx, metadata.DefaultRecommendationMetadataListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/advisor/2025-01-01/metadata/client.go b/resource-manager/advisor/2025-01-01/metadata/client.go new file mode 100644 index 00000000000..2f569e1f755 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/client.go @@ -0,0 +1,26 @@ +package metadata + +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 MetadataClient struct { + Client *resourcemanager.Client +} + +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) + } + + return &MetadataClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/metadata/constants.go b/resource-manager/advisor/2025-01-01/metadata/constants.go new file mode 100644 index 00000000000..2e4b4a2351f --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/constants.go @@ -0,0 +1,48 @@ +package metadata + +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 Scenario string + +const ( + ScenarioAlerts Scenario = "Alerts" +) + +func PossibleValuesForScenario() []string { + return []string{ + string(ScenarioAlerts), + } +} + +func (s *Scenario) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScenario(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScenario(input string) (*Scenario, error) { + vals := map[string]Scenario{ + "alerts": ScenarioAlerts, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Scenario(input) + return &out, nil +} diff --git a/resource-manager/advisor/2025-01-01/metadata/id_metadata.go b/resource-manager/advisor/2025-01-01/metadata/id_metadata.go new file mode 100644 index 00000000000..f79d74f3a16 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/id_metadata.go @@ -0,0 +1,112 @@ +package metadata + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MetadataId{}) +} + +var _ resourceids.ResourceId = &MetadataId{} + +// MetadataId is a struct representing the Resource ID for a Metadata +type MetadataId struct { + MetadataName string +} + +// NewMetadataID returns a new MetadataId struct +func NewMetadataID(metadataName string) MetadataId { + return MetadataId{ + MetadataName: metadataName, + } +} + +// ParseMetadataID parses 'input' into a MetadataId +func ParseMetadataID(input string) (*MetadataId, error) { + parser := resourceids.NewParserFromResourceIdType(&MetadataId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MetadataId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMetadataIDInsensitively parses 'input' case-insensitively into a MetadataId +// note: this method should only be used for API response data and not user input +func ParseMetadataIDInsensitively(input string) (*MetadataId, error) { + parser := resourceids.NewParserFromResourceIdType(&MetadataId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MetadataId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MetadataId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.MetadataName, ok = input.Parsed["metadataName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "metadataName", input) + } + + return nil +} + +// ValidateMetadataID checks that 'input' can be parsed as a Metadata ID +func ValidateMetadataID(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 := ParseMetadataID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Metadata ID +func (id MetadataId) ID() string { + fmtString := "/providers/Microsoft.Advisor/metadata/%s" + return fmt.Sprintf(fmtString, id.MetadataName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Metadata ID +func (id MetadataId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAdvisor", "Microsoft.Advisor", "Microsoft.Advisor"), + resourceids.StaticSegment("staticMetadata", "metadata", "metadata"), + resourceids.UserSpecifiedSegment("metadataName", "metadataName"), + } +} + +// String returns a human-readable description of this Metadata ID +func (id MetadataId) String() string { + components := []string{ + fmt.Sprintf("Metadata Name: %q", id.MetadataName), + } + return fmt.Sprintf("Metadata (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/advisor/2025-01-01/metadata/id_metadata_test.go b/resource-manager/advisor/2025-01-01/metadata/id_metadata_test.go new file mode 100644 index 00000000000..e96a849a3a1 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/id_metadata_test.go @@ -0,0 +1,192 @@ +package metadata + +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 = &MetadataId{} + +func TestNewMetadataID(t *testing.T) { + id := NewMetadataID("metadataName") + + if id.MetadataName != "metadataName" { + t.Fatalf("Expected %q but got %q for Segment 'MetadataName'", id.MetadataName, "metadataName") + } +} + +func TestFormatMetadataID(t *testing.T) { + actual := NewMetadataID("metadataName").ID() + expected := "/providers/Microsoft.Advisor/metadata/metadataName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMetadataID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MetadataId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Advisor", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Advisor/metadata", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Advisor/metadata/metadataName", + Expected: &MetadataId{ + MetadataName: "metadataName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Advisor/metadata/metadataName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMetadataID(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.MetadataName != v.Expected.MetadataName { + t.Fatalf("Expected %q but got %q for MetadataName", v.Expected.MetadataName, actual.MetadataName) + } + + } +} + +func TestParseMetadataIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MetadataId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Advisor", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.aDvIsOr", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Advisor/metadata", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.aDvIsOr/mEtAdAtA", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Advisor/metadata/metadataName", + Expected: &MetadataId{ + MetadataName: "metadataName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Advisor/metadata/metadataName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.aDvIsOr/mEtAdAtA/mEtAdAtAnAmE", + Expected: &MetadataId{ + MetadataName: "mEtAdAtAnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.aDvIsOr/mEtAdAtA/mEtAdAtAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMetadataIDInsensitively(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.MetadataName != v.Expected.MetadataName { + t.Fatalf("Expected %q but got %q for MetadataName", v.Expected.MetadataName, actual.MetadataName) + } + + } +} + +func TestSegmentsForMetadataId(t *testing.T) { + segments := MetadataId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MetadataId 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/advisor/2025-01-01/metadata/method_recommendationmetadataget.go b/resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadataget.go new file mode 100644 index 00000000000..8c71567d2be --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadataget.go @@ -0,0 +1,53 @@ +package metadata + +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 RecommendationMetadataGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataEntity +} + +// RecommendationMetadataGet ... +func (c MetadataClient) RecommendationMetadataGet(ctx context.Context, id MetadataId) (result RecommendationMetadataGetOperationResponse, 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 MetadataEntity + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadatalist.go b/resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadatalist.go new file mode 100644 index 00000000000..e2cb5f9bf27 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/method_recommendationmetadatalist.go @@ -0,0 +1,134 @@ +package metadata + +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 RecommendationMetadataListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataEntity +} + +type RecommendationMetadataListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataEntity +} + +type RecommendationMetadataListOperationOptions struct { + Filter *string +} + +func DefaultRecommendationMetadataListOperationOptions() RecommendationMetadataListOperationOptions { + return RecommendationMetadataListOperationOptions{} +} + +func (o RecommendationMetadataListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o RecommendationMetadataListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o RecommendationMetadataListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type RecommendationMetadataListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *RecommendationMetadataListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// RecommendationMetadataList ... +func (c MetadataClient) RecommendationMetadataList(ctx context.Context, options RecommendationMetadataListOperationOptions) (result RecommendationMetadataListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &RecommendationMetadataListCustomPager{}, + Path: "/providers/Microsoft.Advisor/metadata", + } + + 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 *[]MetadataEntity `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// RecommendationMetadataListComplete retrieves all the results into a single object +func (c MetadataClient) RecommendationMetadataListComplete(ctx context.Context, options RecommendationMetadataListOperationOptions) (RecommendationMetadataListCompleteResult, error) { + return c.RecommendationMetadataListCompleteMatchingPredicate(ctx, options, MetadataEntityOperationPredicate{}) +} + +// RecommendationMetadataListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) RecommendationMetadataListCompleteMatchingPredicate(ctx context.Context, options RecommendationMetadataListOperationOptions, predicate MetadataEntityOperationPredicate) (result RecommendationMetadataListCompleteResult, err error) { + items := make([]MetadataEntity, 0) + + resp, err := c.RecommendationMetadataList(ctx, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = RecommendationMetadataListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/advisor/2025-01-01/metadata/model_metadataentity.go b/resource-manager/advisor/2025-01-01/metadata/model_metadataentity.go new file mode 100644 index 00000000000..3b6723a36da --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/model_metadataentity.go @@ -0,0 +1,11 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataEntity struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MetadataEntityProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/metadata/model_metadataentityproperties.go b/resource-manager/advisor/2025-01-01/metadata/model_metadataentityproperties.go new file mode 100644 index 00000000000..d6b9ce7f77a --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/model_metadataentityproperties.go @@ -0,0 +1,11 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataEntityProperties struct { + ApplicableScenarios *[]Scenario `json:"applicableScenarios,omitempty"` + DependsOn *[]string `json:"dependsOn,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + SupportedValues *[]MetadataSupportedValueDetail `json:"supportedValues,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/metadata/model_metadatasupportedvaluedetail.go b/resource-manager/advisor/2025-01-01/metadata/model_metadatasupportedvaluedetail.go new file mode 100644 index 00000000000..df6339db7c2 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/model_metadatasupportedvaluedetail.go @@ -0,0 +1,9 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSupportedValueDetail struct { + DisplayName *string `json:"displayName,omitempty"` + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/metadata/predicates.go b/resource-manager/advisor/2025-01-01/metadata/predicates.go new file mode 100644 index 00000000000..f30d9dc7b97 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/predicates.go @@ -0,0 +1,27 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataEntityOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p MetadataEntityOperationPredicate) Matches(input MetadataEntity) 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/advisor/2025-01-01/metadata/version.go b/resource-manager/advisor/2025-01-01/metadata/version.go new file mode 100644 index 00000000000..33f4ebfbdc9 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/metadata/version.go @@ -0,0 +1,10 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/metadata/2025-01-01" +} diff --git a/resource-manager/advisor/2025-01-01/prediction/README.md b/resource-manager/advisor/2025-01-01/prediction/README.md new file mode 100644 index 00000000000..ff4565bb95d --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/prediction` Documentation + +The `prediction` SDK allows for interaction with Azure Resource Manager `advisor` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/prediction" +``` + + +### Client Initialization + +```go +client := prediction.NewPredictionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PredictionClient.Predict` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := prediction.PredictionRequest{ + // ... +} + + +read, err := client.Predict(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/advisor/2025-01-01/prediction/client.go b/resource-manager/advisor/2025-01-01/prediction/client.go new file mode 100644 index 00000000000..8287c65b0ea --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/client.go @@ -0,0 +1,26 @@ +package prediction + +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 PredictionClient struct { + Client *resourcemanager.Client +} + +func NewPredictionClientWithBaseURI(sdkApi sdkEnv.Api) (*PredictionClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "prediction", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PredictionClient: %+v", err) + } + + return &PredictionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/prediction/constants.go b/resource-manager/advisor/2025-01-01/prediction/constants.go new file mode 100644 index 00000000000..870cb715960 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/constants.go @@ -0,0 +1,142 @@ +package prediction + +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 Category string + +const ( + CategoryCost Category = "Cost" + CategoryHighAvailability Category = "HighAvailability" + CategoryOperationalExcellence Category = "OperationalExcellence" + CategoryPerformance Category = "Performance" + CategorySecurity Category = "Security" +) + +func PossibleValuesForCategory() []string { + return []string{ + string(CategoryCost), + string(CategoryHighAvailability), + string(CategoryOperationalExcellence), + string(CategoryPerformance), + string(CategorySecurity), + } +} + +func (s *Category) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCategory(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCategory(input string) (*Category, error) { + vals := map[string]Category{ + "cost": CategoryCost, + "highavailability": CategoryHighAvailability, + "operationalexcellence": CategoryOperationalExcellence, + "performance": CategoryPerformance, + "security": CategorySecurity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Category(input) + return &out, nil +} + +type Impact string + +const ( + ImpactHigh Impact = "High" + ImpactLow Impact = "Low" + ImpactMedium Impact = "Medium" +) + +func PossibleValuesForImpact() []string { + return []string{ + string(ImpactHigh), + string(ImpactLow), + string(ImpactMedium), + } +} + +func (s *Impact) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImpact(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImpact(input string) (*Impact, error) { + vals := map[string]Impact{ + "high": ImpactHigh, + "low": ImpactLow, + "medium": ImpactMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Impact(input) + return &out, nil +} + +type PredictionType string + +const ( + PredictionTypePredictiveRightsizing PredictionType = "PredictiveRightsizing" +) + +func PossibleValuesForPredictionType() []string { + return []string{ + string(PredictionTypePredictiveRightsizing), + } +} + +func (s *PredictionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePredictionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePredictionType(input string) (*PredictionType, error) { + vals := map[string]PredictionType{ + "predictiverightsizing": PredictionTypePredictiveRightsizing, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PredictionType(input) + return &out, nil +} diff --git a/resource-manager/advisor/2025-01-01/prediction/method_predict.go b/resource-manager/advisor/2025-01-01/prediction/method_predict.go new file mode 100644 index 00000000000..5b146f363e4 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/method_predict.go @@ -0,0 +1,59 @@ +package prediction + +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 PredictOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PredictionResponse +} + +// Predict ... +func (c PredictionClient) Predict(ctx context.Context, id commonids.SubscriptionId, input PredictionRequest) (result PredictOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/predict", 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 PredictionResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/prediction/model_predictionrequest.go b/resource-manager/advisor/2025-01-01/prediction/model_predictionrequest.go new file mode 100644 index 00000000000..f5c32494189 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/model_predictionrequest.go @@ -0,0 +1,8 @@ +package prediction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PredictionRequest struct { + Properties *PredictionRequestProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/prediction/model_predictionrequestproperties.go b/resource-manager/advisor/2025-01-01/prediction/model_predictionrequestproperties.go new file mode 100644 index 00000000000..352b7b0bfc3 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/model_predictionrequestproperties.go @@ -0,0 +1,9 @@ +package prediction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PredictionRequestProperties struct { + ExtendedProperties *interface{} `json:"extendedProperties,omitempty"` + PredictionType *PredictionType `json:"predictionType,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/prediction/model_predictionresponse.go b/resource-manager/advisor/2025-01-01/prediction/model_predictionresponse.go new file mode 100644 index 00000000000..fca3b275b1d --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/model_predictionresponse.go @@ -0,0 +1,8 @@ +package prediction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PredictionResponse struct { + Properties *PredictionResponseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/prediction/model_predictionresponseproperties.go b/resource-manager/advisor/2025-01-01/prediction/model_predictionresponseproperties.go new file mode 100644 index 00000000000..8a53b82c160 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/model_predictionresponseproperties.go @@ -0,0 +1,32 @@ +package prediction + +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 PredictionResponseProperties struct { + Category *Category `json:"category,omitempty"` + ExtendedProperties *interface{} `json:"extendedProperties,omitempty"` + Impact *Impact `json:"impact,omitempty"` + ImpactedField *string `json:"impactedField,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + PredictionType *PredictionType `json:"predictionType,omitempty"` + ShortDescription *ShortDescription `json:"shortDescription,omitempty"` +} + +func (o *PredictionResponseProperties) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *PredictionResponseProperties) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} diff --git a/resource-manager/advisor/2025-01-01/prediction/model_shortdescription.go b/resource-manager/advisor/2025-01-01/prediction/model_shortdescription.go new file mode 100644 index 00000000000..484b5e4bb42 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/model_shortdescription.go @@ -0,0 +1,9 @@ +package prediction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ShortDescription struct { + Problem *string `json:"problem,omitempty"` + Solution *string `json:"solution,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/prediction/version.go b/resource-manager/advisor/2025-01-01/prediction/version.go new file mode 100644 index 00000000000..b19736fcd80 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/prediction/version.go @@ -0,0 +1,10 @@ +package prediction + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/prediction/2025-01-01" +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/README.md b/resource-manager/advisor/2025-01-01/suppressions/README.md new file mode 100644 index 00000000000..d76be0e74f2 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/suppressions` Documentation + +The `suppressions` SDK allows for interaction with Azure Resource Manager `advisor` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/advisor/2025-01-01/suppressions" +``` + + +### Client Initialization + +```go +client := suppressions.NewSuppressionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SuppressionsClient.Create` + +```go +ctx := context.TODO() +id := suppressions.NewScopedSuppressionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId", "suppressionName") + +payload := suppressions.SuppressionContract{ + // ... +} + + +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: `SuppressionsClient.Delete` + +```go +ctx := context.TODO() +id := suppressions.NewScopedSuppressionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId", "suppressionName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SuppressionsClient.Get` + +```go +ctx := context.TODO() +id := suppressions.NewScopedSuppressionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId", "suppressionName") + +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: `SuppressionsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, suppressions.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, suppressions.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/advisor/2025-01-01/suppressions/client.go b/resource-manager/advisor/2025-01-01/suppressions/client.go new file mode 100644 index 00000000000..720ea7878d6 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/client.go @@ -0,0 +1,26 @@ +package suppressions + +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 SuppressionsClient struct { + Client *resourcemanager.Client +} + +func NewSuppressionsClientWithBaseURI(sdkApi sdkEnv.Api) (*SuppressionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "suppressions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SuppressionsClient: %+v", err) + } + + return &SuppressionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression.go b/resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression.go new file mode 100644 index 00000000000..767e49954a1 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression.go @@ -0,0 +1,129 @@ +package suppressions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedSuppressionId{}) +} + +var _ resourceids.ResourceId = &ScopedSuppressionId{} + +// ScopedSuppressionId is a struct representing the Resource ID for a Scoped Suppression +type ScopedSuppressionId struct { + ResourceUri string + RecommendationId string + SuppressionName string +} + +// NewScopedSuppressionID returns a new ScopedSuppressionId struct +func NewScopedSuppressionID(resourceUri string, recommendationId string, suppressionName string) ScopedSuppressionId { + return ScopedSuppressionId{ + ResourceUri: resourceUri, + RecommendationId: recommendationId, + SuppressionName: suppressionName, + } +} + +// ParseScopedSuppressionID parses 'input' into a ScopedSuppressionId +func ParseScopedSuppressionID(input string) (*ScopedSuppressionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedSuppressionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedSuppressionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedSuppressionIDInsensitively parses 'input' case-insensitively into a ScopedSuppressionId +// note: this method should only be used for API response data and not user input +func ParseScopedSuppressionIDInsensitively(input string) (*ScopedSuppressionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedSuppressionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedSuppressionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedSuppressionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ResourceUri, ok = input.Parsed["resourceUri"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceUri", input) + } + + if id.RecommendationId, ok = input.Parsed["recommendationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recommendationId", input) + } + + if id.SuppressionName, ok = input.Parsed["suppressionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "suppressionName", input) + } + + return nil +} + +// ValidateScopedSuppressionID checks that 'input' can be parsed as a Scoped Suppression ID +func ValidateScopedSuppressionID(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 := ParseScopedSuppressionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Suppression ID +func (id ScopedSuppressionId) ID() string { + fmtString := "/%s/providers/Microsoft.Advisor/recommendations/%s/suppressions/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.ResourceUri, "/"), id.RecommendationId, id.SuppressionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Suppression ID +func (id ScopedSuppressionId) 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("staticMicrosoftAdvisor", "Microsoft.Advisor", "Microsoft.Advisor"), + resourceids.StaticSegment("staticRecommendations", "recommendations", "recommendations"), + resourceids.UserSpecifiedSegment("recommendationId", "recommendationId"), + resourceids.StaticSegment("staticSuppressions", "suppressions", "suppressions"), + resourceids.UserSpecifiedSegment("suppressionName", "suppressionName"), + } +} + +// String returns a human-readable description of this Scoped Suppression ID +func (id ScopedSuppressionId) String() string { + components := []string{ + fmt.Sprintf("Resource Uri: %q", id.ResourceUri), + fmt.Sprintf("Recommendation: %q", id.RecommendationId), + fmt.Sprintf("Suppression Name: %q", id.SuppressionName), + } + return fmt.Sprintf("Scoped Suppression (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression_test.go b/resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression_test.go new file mode 100644 index 00000000000..c6f003ef45b --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/id_scopedsuppression_test.go @@ -0,0 +1,267 @@ +package suppressions + +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 = &ScopedSuppressionId{} + +func TestNewScopedSuppressionID(t *testing.T) { + id := NewScopedSuppressionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId", "suppressionName") + + 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.RecommendationId != "recommendationId" { + t.Fatalf("Expected %q but got %q for Segment 'RecommendationId'", id.RecommendationId, "recommendationId") + } + + if id.SuppressionName != "suppressionName" { + t.Fatalf("Expected %q but got %q for Segment 'SuppressionName'", id.SuppressionName, "suppressionName") + } +} + +func TestFormatScopedSuppressionID(t *testing.T) { + actual := NewScopedSuppressionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "recommendationId", "suppressionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions/suppressionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedSuppressionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedSuppressionId + }{ + { + // 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.Advisor", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions/suppressionName", + Expected: &ScopedSuppressionId{ + ResourceUri: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + RecommendationId: "recommendationId", + SuppressionName: "suppressionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions/suppressionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedSuppressionID(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.RecommendationId != v.Expected.RecommendationId { + t.Fatalf("Expected %q but got %q for RecommendationId", v.Expected.RecommendationId, actual.RecommendationId) + } + + if actual.SuppressionName != v.Expected.SuppressionName { + t.Fatalf("Expected %q but got %q for SuppressionName", v.Expected.SuppressionName, actual.SuppressionName) + } + + } +} + +func TestParseScopedSuppressionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedSuppressionId + }{ + { + // 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.Advisor", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr/rEcOmMeNdAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr/rEcOmMeNdAtIoNs/rEcOmMeNdAtIoNiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr/rEcOmMeNdAtIoNs/rEcOmMeNdAtIoNiD/sUpPrEsSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions/suppressionName", + Expected: &ScopedSuppressionId{ + ResourceUri: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + RecommendationId: "recommendationId", + SuppressionName: "suppressionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Advisor/recommendations/recommendationId/suppressions/suppressionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aDvIsOr/rEcOmMeNdAtIoNs/rEcOmMeNdAtIoNiD/sUpPrEsSiOnS/sUpPrEsSiOnNaMe", + Expected: &ScopedSuppressionId{ + ResourceUri: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + RecommendationId: "rEcOmMeNdAtIoNiD", + SuppressionName: "sUpPrEsSiOnNaMe", + }, + }, + { + // 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.aDvIsOr/rEcOmMeNdAtIoNs/rEcOmMeNdAtIoNiD/sUpPrEsSiOnS/sUpPrEsSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedSuppressionIDInsensitively(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.RecommendationId != v.Expected.RecommendationId { + t.Fatalf("Expected %q but got %q for RecommendationId", v.Expected.RecommendationId, actual.RecommendationId) + } + + if actual.SuppressionName != v.Expected.SuppressionName { + t.Fatalf("Expected %q but got %q for SuppressionName", v.Expected.SuppressionName, actual.SuppressionName) + } + + } +} + +func TestSegmentsForScopedSuppressionId(t *testing.T) { + segments := ScopedSuppressionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedSuppressionId 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/advisor/2025-01-01/suppressions/method_create.go b/resource-manager/advisor/2025-01-01/suppressions/method_create.go new file mode 100644 index 00000000000..ce2fa152458 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/method_create.go @@ -0,0 +1,57 @@ +package suppressions + +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 *SuppressionContract +} + +// Create ... +func (c SuppressionsClient) Create(ctx context.Context, id ScopedSuppressionId, input SuppressionContract) (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 SuppressionContract + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/method_delete.go b/resource-manager/advisor/2025-01-01/suppressions/method_delete.go new file mode 100644 index 00000000000..2b8f8994350 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/method_delete.go @@ -0,0 +1,46 @@ +package suppressions + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SuppressionsClient) Delete(ctx context.Context, id ScopedSuppressionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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 + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/method_get.go b/resource-manager/advisor/2025-01-01/suppressions/method_get.go new file mode 100644 index 00000000000..0b1fccc5e52 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/method_get.go @@ -0,0 +1,53 @@ +package suppressions + +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 *SuppressionContract +} + +// Get ... +func (c SuppressionsClient) Get(ctx context.Context, id ScopedSuppressionId) (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 SuppressionContract + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/method_list.go b/resource-manager/advisor/2025-01-01/suppressions/method_list.go new file mode 100644 index 00000000000..94de20a6809 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/method_list.go @@ -0,0 +1,135 @@ +package suppressions + +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 *[]SuppressionContract +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SuppressionContract +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c SuppressionsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Advisor/suppressions", 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 *[]SuppressionContract `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 SuppressionsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, SuppressionContractOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SuppressionsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate SuppressionContractOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SuppressionContract, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/model_suppressioncontract.go b/resource-manager/advisor/2025-01-01/suppressions/model_suppressioncontract.go new file mode 100644 index 00000000000..3941e882d35 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/model_suppressioncontract.go @@ -0,0 +1,16 @@ +package suppressions + +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 SuppressionContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SuppressionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/model_suppressionproperties.go b/resource-manager/advisor/2025-01-01/suppressions/model_suppressionproperties.go new file mode 100644 index 00000000000..f7bebedb504 --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/model_suppressionproperties.go @@ -0,0 +1,28 @@ +package suppressions + +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 SuppressionProperties struct { + ExpirationTimeStamp *string `json:"expirationTimeStamp,omitempty"` + SuppressionId *string `json:"suppressionId,omitempty"` + Ttl *string `json:"ttl,omitempty"` +} + +func (o *SuppressionProperties) GetExpirationTimeStampAsTime() (*time.Time, error) { + if o.ExpirationTimeStamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeStamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *SuppressionProperties) SetExpirationTimeStampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeStamp = &formatted +} diff --git a/resource-manager/advisor/2025-01-01/suppressions/predicates.go b/resource-manager/advisor/2025-01-01/suppressions/predicates.go new file mode 100644 index 00000000000..4e0826acb8d --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/predicates.go @@ -0,0 +1,27 @@ +package suppressions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SuppressionContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SuppressionContractOperationPredicate) Matches(input SuppressionContract) 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/advisor/2025-01-01/suppressions/version.go b/resource-manager/advisor/2025-01-01/suppressions/version.go new file mode 100644 index 00000000000..4ed7c2c281f --- /dev/null +++ b/resource-manager/advisor/2025-01-01/suppressions/version.go @@ -0,0 +1,10 @@ +package suppressions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/suppressions/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/README.md b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/README.md new file mode 100644 index 00000000000..6d8bae4bc51 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/availableworkloadprofiles` Documentation + +The `availableworkloadprofiles` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/availableworkloadprofiles" +``` + + +### Client Initialization + +```go +client := availableworkloadprofiles.NewAvailableWorkloadProfilesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AvailableWorkloadProfilesClient.Get` + +```go +ctx := context.TODO() +id := availableworkloadprofiles.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.Get(ctx, id)` can be used to do batched pagination +items, err := client.GetComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/client.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/client.go new file mode 100644 index 00000000000..997a05c7055 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/client.go @@ -0,0 +1,26 @@ +package availableworkloadprofiles + +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 AvailableWorkloadProfilesClient struct { + Client *resourcemanager.Client +} + +func NewAvailableWorkloadProfilesClientWithBaseURI(sdkApi sdkEnv.Api) (*AvailableWorkloadProfilesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "availableworkloadprofiles", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AvailableWorkloadProfilesClient: %+v", err) + } + + return &AvailableWorkloadProfilesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/constants.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/constants.go new file mode 100644 index 00000000000..5001f6a5eda --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/constants.go @@ -0,0 +1,51 @@ +package availableworkloadprofiles + +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 Applicability string + +const ( + ApplicabilityCustom Applicability = "Custom" + ApplicabilityLocationDefault Applicability = "LocationDefault" +) + +func PossibleValuesForApplicability() []string { + return []string{ + string(ApplicabilityCustom), + string(ApplicabilityLocationDefault), + } +} + +func (s *Applicability) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseApplicability(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseApplicability(input string) (*Applicability, error) { + vals := map[string]Applicability{ + "custom": ApplicabilityCustom, + "locationdefault": ApplicabilityLocationDefault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Applicability(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location.go new file mode 100644 index 00000000000..dacc92090d2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location.go @@ -0,0 +1,121 @@ +package availableworkloadprofiles + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.App/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location_test.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location_test.go new file mode 100644 index 00000000000..bcbd5a2d787 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/id_location_test.go @@ -0,0 +1,237 @@ +package availableworkloadprofiles + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/containerapps/2025-01-01/availableworkloadprofiles/method_get.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/method_get.go new file mode 100644 index 00000000000..c7880a83d42 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/method_get.go @@ -0,0 +1,105 @@ +package availableworkloadprofiles + +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 *[]AvailableWorkloadProfile +} + +type GetCompleteResult struct { + LatestHttpResponse *http.Response + Items []AvailableWorkloadProfile +} + +type GetCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// Get ... +func (c AvailableWorkloadProfilesClient) Get(ctx context.Context, id LocationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetCustomPager{}, + Path: fmt.Sprintf("%s/availableManagedEnvironmentsWorkloadProfileTypes", 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 *[]AvailableWorkloadProfile `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetComplete retrieves all the results into a single object +func (c AvailableWorkloadProfilesClient) GetComplete(ctx context.Context, id LocationId) (GetCompleteResult, error) { + return c.GetCompleteMatchingPredicate(ctx, id, AvailableWorkloadProfileOperationPredicate{}) +} + +// GetCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AvailableWorkloadProfilesClient) GetCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate AvailableWorkloadProfileOperationPredicate) (result GetCompleteResult, err error) { + items := make([]AvailableWorkloadProfile, 0) + + resp, err := c.Get(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofile.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofile.go new file mode 100644 index 00000000000..1e3982c9a81 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofile.go @@ -0,0 +1,17 @@ +package availableworkloadprofiles + +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 AvailableWorkloadProfile struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AvailableWorkloadProfileProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofileproperties.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofileproperties.go new file mode 100644 index 00000000000..598ff5684f4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/model_availableworkloadprofileproperties.go @@ -0,0 +1,13 @@ +package availableworkloadprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableWorkloadProfileProperties struct { + Applicability *Applicability `json:"applicability,omitempty"` + Category *string `json:"category,omitempty"` + Cores *int64 `json:"cores,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Gpus *int64 `json:"gpus,omitempty"` + MemoryGiB *int64 `json:"memoryGiB,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/predicates.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/predicates.go new file mode 100644 index 00000000000..1639daf5d8b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/predicates.go @@ -0,0 +1,32 @@ +package availableworkloadprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableWorkloadProfileOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p AvailableWorkloadProfileOperationPredicate) Matches(input AvailableWorkloadProfile) 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/containerapps/2025-01-01/availableworkloadprofiles/version.go b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/version.go new file mode 100644 index 00000000000..c65bbf18372 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/availableworkloadprofiles/version.go @@ -0,0 +1,10 @@ +package availableworkloadprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/availableworkloadprofiles/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/README.md b/resource-manager/containerapps/2025-01-01/billingmeters/README.md new file mode 100644 index 00000000000..2e591221c97 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/billingmeters` Documentation + +The `billingmeters` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/billingmeters" +``` + + +### Client Initialization + +```go +client := billingmeters.NewBillingMetersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BillingMetersClient.Get` + +```go +ctx := context.TODO() +id := billingmeters.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +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 +} +``` diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/client.go b/resource-manager/containerapps/2025-01-01/billingmeters/client.go new file mode 100644 index 00000000000..3c07a1d5967 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/client.go @@ -0,0 +1,26 @@ +package billingmeters + +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 BillingMetersClient struct { + Client *resourcemanager.Client +} + +func NewBillingMetersClientWithBaseURI(sdkApi sdkEnv.Api) (*BillingMetersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "billingmeters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BillingMetersClient: %+v", err) + } + + return &BillingMetersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/id_location.go b/resource-manager/containerapps/2025-01-01/billingmeters/id_location.go new file mode 100644 index 00000000000..67dfea3ecfc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/id_location.go @@ -0,0 +1,121 @@ +package billingmeters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.App/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/id_location_test.go b/resource-manager/containerapps/2025-01-01/billingmeters/id_location_test.go new file mode 100644 index 00000000000..80dbf95c7f3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/id_location_test.go @@ -0,0 +1,237 @@ +package billingmeters + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/containerapps/2025-01-01/billingmeters/method_get.go b/resource-manager/containerapps/2025-01-01/billingmeters/method_get.go new file mode 100644 index 00000000000..126e6134bc5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/method_get.go @@ -0,0 +1,54 @@ +package billingmeters + +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 *BillingMeterCollection +} + +// Get ... +func (c BillingMetersClient) Get(ctx context.Context, id LocationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/billingMeters", 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 BillingMeterCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeter.go b/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeter.go new file mode 100644 index 00000000000..78fd132ca4f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeter.go @@ -0,0 +1,17 @@ +package billingmeters + +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 BillingMeter struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BillingMeterProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmetercollection.go b/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmetercollection.go new file mode 100644 index 00000000000..d8d25b43e79 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmetercollection.go @@ -0,0 +1,8 @@ +package billingmeters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingMeterCollection struct { + Value []BillingMeter `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeterproperties.go b/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeterproperties.go new file mode 100644 index 00000000000..21df49710dc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/model_billingmeterproperties.go @@ -0,0 +1,10 @@ +package billingmeters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingMeterProperties struct { + Category *string `json:"category,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + MeterType *string `json:"meterType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/billingmeters/version.go b/resource-manager/containerapps/2025-01-01/billingmeters/version.go new file mode 100644 index 00000000000..a5548868437 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/billingmeters/version.go @@ -0,0 +1,10 @@ +package billingmeters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/billingmeters/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/README.md b/resource-manager/containerapps/2025-01-01/certificates/README.md new file mode 100644 index 00000000000..b62f4ace324 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/README.md @@ -0,0 +1,202 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/certificates` Documentation + +The `certificates` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/certificates" +``` + + +### Client Initialization + +```go +client := certificates.NewCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CertificatesClient.ConnectedEnvironmentsCertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := certificates.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +payload := certificates.Certificate{ + // ... +} + + +read, err := client.ConnectedEnvironmentsCertificatesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificatesClient.ConnectedEnvironmentsCertificatesDelete` + +```go +ctx := context.TODO() +id := certificates.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +read, err := client.ConnectedEnvironmentsCertificatesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificatesClient.ConnectedEnvironmentsCertificatesGet` + +```go +ctx := context.TODO() +id := certificates.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +read, err := client.ConnectedEnvironmentsCertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificatesClient.ConnectedEnvironmentsCertificatesList` + +```go +ctx := context.TODO() +id := certificates.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +// alternatively `client.ConnectedEnvironmentsCertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.ConnectedEnvironmentsCertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CertificatesClient.ConnectedEnvironmentsCertificatesUpdate` + +```go +ctx := context.TODO() +id := certificates.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +payload := certificates.CertificatePatch{ + // ... +} + + +read, err := client.ConnectedEnvironmentsCertificatesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificatesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := certificates.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +payload := certificates.Certificate{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificatesClient.Delete` + +```go +ctx := context.TODO() +id := certificates.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CertificatesClient.Get` + +```go +ctx := context.TODO() +id := certificates.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +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: `CertificatesClient.List` + +```go +ctx := context.TODO() +id := certificates.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// 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: `CertificatesClient.Update` + +```go +ctx := context.TODO() +id := certificates.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +payload := certificates.CertificatePatch{ + // ... +} + + +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/containerapps/2025-01-01/certificates/client.go b/resource-manager/containerapps/2025-01-01/certificates/client.go new file mode 100644 index 00000000000..f045f1b9265 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/client.go @@ -0,0 +1,26 @@ +package certificates + +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 CertificatesClient struct { + Client *resourcemanager.Client +} + +func NewCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*CertificatesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "certificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CertificatesClient: %+v", err) + } + + return &CertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/constants.go b/resource-manager/containerapps/2025-01-01/certificates/constants.go new file mode 100644 index 00000000000..bf939247fa5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/constants.go @@ -0,0 +1,60 @@ +package certificates + +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 CertificateProvisioningState string + +const ( + CertificateProvisioningStateCanceled CertificateProvisioningState = "Canceled" + CertificateProvisioningStateDeleteFailed CertificateProvisioningState = "DeleteFailed" + CertificateProvisioningStateFailed CertificateProvisioningState = "Failed" + CertificateProvisioningStatePending CertificateProvisioningState = "Pending" + CertificateProvisioningStateSucceeded CertificateProvisioningState = "Succeeded" +) + +func PossibleValuesForCertificateProvisioningState() []string { + return []string{ + string(CertificateProvisioningStateCanceled), + string(CertificateProvisioningStateDeleteFailed), + string(CertificateProvisioningStateFailed), + string(CertificateProvisioningStatePending), + string(CertificateProvisioningStateSucceeded), + } +} + +func (s *CertificateProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateProvisioningState(input string) (*CertificateProvisioningState, error) { + vals := map[string]CertificateProvisioningState{ + "canceled": CertificateProvisioningStateCanceled, + "deletefailed": CertificateProvisioningStateDeleteFailed, + "failed": CertificateProvisioningStateFailed, + "pending": CertificateProvisioningStatePending, + "succeeded": CertificateProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/id_certificate.go b/resource-manager/containerapps/2025-01-01/certificates/id_certificate.go new file mode 100644 index 00000000000..7832b378511 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_certificate.go @@ -0,0 +1,139 @@ +package certificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CertificateId{}) +} + +var _ resourceids.ResourceId = &CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CertificateId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.CertificateName, ok = input.Parsed["certificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateName", input) + } + + return nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(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 := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateName"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/id_certificate_test.go b/resource-manager/containerapps/2025-01-01/certificates/id_certificate_test.go new file mode 100644 index 00000000000..10cb10f8fee --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_certificate_test.go @@ -0,0 +1,327 @@ +package certificates + +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 = &CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.CertificateName != "certificateName" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateName") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + CertificateName: "cErTiFiCaTeNaMe", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId 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/containerapps/2025-01-01/certificates/id_connectedenvironment.go b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment.go new file mode 100644 index 00000000000..7043d3dc6e6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment.go @@ -0,0 +1,130 @@ +package certificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentId{} + +// ConnectedEnvironmentId is a struct representing the Resource ID for a Connected Environment +type ConnectedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string +} + +// NewConnectedEnvironmentID returns a new ConnectedEnvironmentId struct +func NewConnectedEnvironmentID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string) ConnectedEnvironmentId { + return ConnectedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + } +} + +// ParseConnectedEnvironmentID parses 'input' into a ConnectedEnvironmentId +func ParseConnectedEnvironmentID(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentIDInsensitively(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentID checks that 'input' can be parsed as a Connected Environment ID +func ValidateConnectedEnvironmentID(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 := ParseConnectedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment ID +func (id ConnectedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment ID +func (id ConnectedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + } +} + +// String returns a human-readable description of this Connected Environment ID +func (id ConnectedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + } + return fmt.Sprintf("Connected Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment_test.go b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment_test.go new file mode 100644 index 00000000000..e0bfa2bcf21 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironment_test.go @@ -0,0 +1,282 @@ +package certificates + +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 = &ConnectedEnvironmentId{} + +func TestNewConnectedEnvironmentID(t *testing.T) { + id := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } +} + +func TestFormatConnectedEnvironmentID(t *testing.T) { + actual := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestParseConnectedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentId(t *testing.T) { + segments := ConnectedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentId 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/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate.go b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate.go new file mode 100644 index 00000000000..e1333d52532 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate.go @@ -0,0 +1,139 @@ +package certificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentCertificateId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentCertificateId{} + +// ConnectedEnvironmentCertificateId is a struct representing the Resource ID for a Connected Environment Certificate +type ConnectedEnvironmentCertificateId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string + CertificateName string +} + +// NewConnectedEnvironmentCertificateID returns a new ConnectedEnvironmentCertificateId struct +func NewConnectedEnvironmentCertificateID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string, certificateName string) ConnectedEnvironmentCertificateId { + return ConnectedEnvironmentCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + CertificateName: certificateName, + } +} + +// ParseConnectedEnvironmentCertificateID parses 'input' into a ConnectedEnvironmentCertificateId +func ParseConnectedEnvironmentCertificateID(input string) (*ConnectedEnvironmentCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentCertificateIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentCertificateId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentCertificateIDInsensitively(input string) (*ConnectedEnvironmentCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentCertificateId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + if id.CertificateName, ok = input.Parsed["certificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentCertificateID checks that 'input' can be parsed as a Connected Environment Certificate ID +func ValidateConnectedEnvironmentCertificateID(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 := ParseConnectedEnvironmentCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment Certificate ID +func (id ConnectedEnvironmentCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment Certificate ID +func (id ConnectedEnvironmentCertificateId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateName"), + } +} + +// String returns a human-readable description of this Connected Environment Certificate ID +func (id ConnectedEnvironmentCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Connected Environment Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate_test.go b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate_test.go new file mode 100644 index 00000000000..ffd5cd8dc56 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_connectedenvironmentcertificate_test.go @@ -0,0 +1,327 @@ +package certificates + +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 = &ConnectedEnvironmentCertificateId{} + +func TestNewConnectedEnvironmentCertificateID(t *testing.T) { + id := NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } + + if id.CertificateName != "certificateName" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateName") + } +} + +func TestFormatConnectedEnvironmentCertificateID(t *testing.T) { + actual := NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName", + Expected: &ConnectedEnvironmentCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentCertificateID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseConnectedEnvironmentCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName", + Expected: &ConnectedEnvironmentCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe", + Expected: &ConnectedEnvironmentCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + CertificateName: "cErTiFiCaTeNaMe", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentCertificateIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentCertificateId(t *testing.T) { + segments := ConnectedEnvironmentCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentCertificateId 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/containerapps/2025-01-01/certificates/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment.go new file mode 100644 index 00000000000..8f1175a170e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment.go @@ -0,0 +1,130 @@ +package certificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment_test.go new file mode 100644 index 00000000000..cc957bf2b81 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package certificates + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatescreateorupdate.go b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatescreateorupdate.go new file mode 100644 index 00000000000..2af96101d74 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatescreateorupdate.go @@ -0,0 +1,57 @@ +package certificates + +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 ConnectedEnvironmentsCertificatesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// ConnectedEnvironmentsCertificatesCreateOrUpdate ... +func (c CertificatesClient) ConnectedEnvironmentsCertificatesCreateOrUpdate(ctx context.Context, id ConnectedEnvironmentCertificateId, input Certificate) (result ConnectedEnvironmentsCertificatesCreateOrUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesdelete.go b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesdelete.go new file mode 100644 index 00000000000..7dae77f3c1f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesdelete.go @@ -0,0 +1,47 @@ +package certificates + +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 ConnectedEnvironmentsCertificatesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ConnectedEnvironmentsCertificatesDelete ... +func (c CertificatesClient) ConnectedEnvironmentsCertificatesDelete(ctx context.Context, id ConnectedEnvironmentCertificateId) (result ConnectedEnvironmentsCertificatesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesget.go b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesget.go new file mode 100644 index 00000000000..9f597b7931b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesget.go @@ -0,0 +1,53 @@ +package certificates + +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 ConnectedEnvironmentsCertificatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// ConnectedEnvironmentsCertificatesGet ... +func (c CertificatesClient) ConnectedEnvironmentsCertificatesGet(ctx context.Context, id ConnectedEnvironmentCertificateId) (result ConnectedEnvironmentsCertificatesGetOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificateslist.go b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificateslist.go new file mode 100644 index 00000000000..1e365b2daa4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificateslist.go @@ -0,0 +1,105 @@ +package certificates + +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 ConnectedEnvironmentsCertificatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Certificate +} + +type ConnectedEnvironmentsCertificatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Certificate +} + +type ConnectedEnvironmentsCertificatesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ConnectedEnvironmentsCertificatesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ConnectedEnvironmentsCertificatesList ... +func (c CertificatesClient) ConnectedEnvironmentsCertificatesList(ctx context.Context, id ConnectedEnvironmentId) (result ConnectedEnvironmentsCertificatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ConnectedEnvironmentsCertificatesListCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]Certificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ConnectedEnvironmentsCertificatesListComplete retrieves all the results into a single object +func (c CertificatesClient) ConnectedEnvironmentsCertificatesListComplete(ctx context.Context, id ConnectedEnvironmentId) (ConnectedEnvironmentsCertificatesListCompleteResult, error) { + return c.ConnectedEnvironmentsCertificatesListCompleteMatchingPredicate(ctx, id, CertificateOperationPredicate{}) +} + +// ConnectedEnvironmentsCertificatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CertificatesClient) ConnectedEnvironmentsCertificatesListCompleteMatchingPredicate(ctx context.Context, id ConnectedEnvironmentId, predicate CertificateOperationPredicate) (result ConnectedEnvironmentsCertificatesListCompleteResult, err error) { + items := make([]Certificate, 0) + + resp, err := c.ConnectedEnvironmentsCertificatesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ConnectedEnvironmentsCertificatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesupdate.go b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesupdate.go new file mode 100644 index 00000000000..e0a4b47cbf2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_connectedenvironmentscertificatesupdate.go @@ -0,0 +1,57 @@ +package certificates + +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 ConnectedEnvironmentsCertificatesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// ConnectedEnvironmentsCertificatesUpdate ... +func (c CertificatesClient) ConnectedEnvironmentsCertificatesUpdate(ctx context.Context, id ConnectedEnvironmentCertificateId, input CertificatePatch) (result ConnectedEnvironmentsCertificatesUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/certificates/method_createorupdate.go new file mode 100644 index 00000000000..ef3ac53ed39 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_createorupdate.go @@ -0,0 +1,57 @@ +package certificates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CreateOrUpdate ... +func (c CertificatesClient) CreateOrUpdate(ctx context.Context, id CertificateId, input Certificate) (result CreateOrUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_delete.go b/resource-manager/containerapps/2025-01-01/certificates/method_delete.go new file mode 100644 index 00000000000..6f676ff9031 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_delete.go @@ -0,0 +1,47 @@ +package certificates + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c CertificatesClient) Delete(ctx context.Context, id CertificateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_get.go b/resource-manager/containerapps/2025-01-01/certificates/method_get.go new file mode 100644 index 00000000000..50817117dad --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_get.go @@ -0,0 +1,53 @@ +package certificates + +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 *Certificate +} + +// Get ... +func (c CertificatesClient) Get(ctx context.Context, id CertificateId) (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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_list.go b/resource-manager/containerapps/2025-01-01/certificates/method_list.go new file mode 100644 index 00000000000..5e49c826299 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_list.go @@ -0,0 +1,105 @@ +package certificates + +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 *[]Certificate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Certificate +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c CertificatesClient) List(ctx context.Context, id ManagedEnvironmentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]Certificate `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 CertificatesClient) ListComplete(ctx context.Context, id ManagedEnvironmentId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, CertificateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CertificatesClient) ListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate CertificateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Certificate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/method_update.go b/resource-manager/containerapps/2025-01-01/certificates/method_update.go new file mode 100644 index 00000000000..a7cab2abe04 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/method_update.go @@ -0,0 +1,57 @@ +package certificates + +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 *Certificate +} + +// Update ... +func (c CertificatesClient) Update(ctx context.Context, id CertificateId, input CertificatePatch) (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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/model_certificate.go b/resource-manager/containerapps/2025-01-01/certificates/model_certificate.go new file mode 100644 index 00000000000..9d2ab626ff9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/model_certificate.go @@ -0,0 +1,18 @@ +package certificates + +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 Certificate struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *CertificateProperties `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/containerapps/2025-01-01/certificates/model_certificatekeyvaultproperties.go b/resource-manager/containerapps/2025-01-01/certificates/model_certificatekeyvaultproperties.go new file mode 100644 index 00000000000..c52073f7abe --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/model_certificatekeyvaultproperties.go @@ -0,0 +1,9 @@ +package certificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateKeyVaultProperties struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/model_certificatepatch.go b/resource-manager/containerapps/2025-01-01/certificates/model_certificatepatch.go new file mode 100644 index 00000000000..8fb7a984a1b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/model_certificatepatch.go @@ -0,0 +1,8 @@ +package certificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificatePatch struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/model_certificateproperties.go b/resource-manager/containerapps/2025-01-01/certificates/model_certificateproperties.go new file mode 100644 index 00000000000..2f7f6163327 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/model_certificateproperties.go @@ -0,0 +1,49 @@ +package certificates + +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 CertificateProperties struct { + CertificateKeyVaultProperties *CertificateKeyVaultProperties `json:"certificateKeyVaultProperties,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + IssueDate *string `json:"issueDate,omitempty"` + Issuer *string `json:"issuer,omitempty"` + Password *string `json:"password,omitempty"` + ProvisioningState *CertificateProvisioningState `json:"provisioningState,omitempty"` + PublicKeyHash *string `json:"publicKeyHash,omitempty"` + SubjectAlternativeNames *[]string `json:"subjectAlternativeNames,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Valid *bool `json:"valid,omitempty"` + Value *string `json:"value,omitempty"` +} + +func (o *CertificateProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} + +func (o *CertificateProperties) GetIssueDateAsTime() (*time.Time, error) { + if o.IssueDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.IssueDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateProperties) SetIssueDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.IssueDate = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/certificates/predicates.go b/resource-manager/containerapps/2025-01-01/certificates/predicates.go new file mode 100644 index 00000000000..2264c7e5419 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/predicates.go @@ -0,0 +1,32 @@ +package certificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p CertificateOperationPredicate) Matches(input Certificate) 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/containerapps/2025-01-01/certificates/version.go b/resource-manager/containerapps/2025-01-01/certificates/version.go new file mode 100644 index 00000000000..4bd534a8405 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/certificates/version.go @@ -0,0 +1,10 @@ +package certificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/certificates/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/client.go b/resource-manager/containerapps/2025-01-01/client.go new file mode 100644 index 00000000000..f5d04b95c4c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/client.go @@ -0,0 +1,199 @@ +package v2025_01_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/availableworkloadprofiles" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/billingmeters" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/certificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/connectedenvironments" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerapps" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsauthconfigs" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsrevisions" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappssessionpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappssourcecontrols" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/daprcomponents" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/diagnostics" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/javacomponents" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/jobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedcertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironments" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/subscriptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/usages" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AvailableWorkloadProfiles *availableworkloadprofiles.AvailableWorkloadProfilesClient + BillingMeters *billingmeters.BillingMetersClient + Certificates *certificates.CertificatesClient + ConnectedEnvironments *connectedenvironments.ConnectedEnvironmentsClient + ConnectedEnvironmentsStorages *connectedenvironmentsstorages.ConnectedEnvironmentsStoragesClient + ContainerApps *containerapps.ContainerAppsClient + ContainerAppsAuthConfigs *containerappsauthconfigs.ContainerAppsAuthConfigsClient + ContainerAppsRevisionReplicas *containerappsrevisionreplicas.ContainerAppsRevisionReplicasClient + ContainerAppsRevisions *containerappsrevisions.ContainerAppsRevisionsClient + ContainerAppsSessionPools *containerappssessionpools.ContainerAppsSessionPoolsClient + ContainerAppsSourceControls *containerappssourcecontrols.ContainerAppsSourceControlsClient + DaprComponents *daprcomponents.DaprComponentsClient + Diagnostics *diagnostics.DiagnosticsClient + JavaComponents *javacomponents.JavaComponentsClient + Jobs *jobs.JobsClient + ManagedCertificates *managedcertificates.ManagedCertificatesClient + ManagedEnvironments *managedenvironments.ManagedEnvironmentsClient + ManagedEnvironmentsStorages *managedenvironmentsstorages.ManagedEnvironmentsStoragesClient + Subscriptions *subscriptions.SubscriptionsClient + Usages *usages.UsagesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + availableWorkloadProfilesClient, err := availableworkloadprofiles.NewAvailableWorkloadProfilesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AvailableWorkloadProfiles client: %+v", err) + } + configureFunc(availableWorkloadProfilesClient.Client) + + billingMetersClient, err := billingmeters.NewBillingMetersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BillingMeters client: %+v", err) + } + configureFunc(billingMetersClient.Client) + + certificatesClient, err := certificates.NewCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Certificates client: %+v", err) + } + configureFunc(certificatesClient.Client) + + connectedEnvironmentsClient, err := connectedenvironments.NewConnectedEnvironmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ConnectedEnvironments client: %+v", err) + } + configureFunc(connectedEnvironmentsClient.Client) + + connectedEnvironmentsStoragesClient, err := connectedenvironmentsstorages.NewConnectedEnvironmentsStoragesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ConnectedEnvironmentsStorages client: %+v", err) + } + configureFunc(connectedEnvironmentsStoragesClient.Client) + + containerAppsAuthConfigsClient, err := containerappsauthconfigs.NewContainerAppsAuthConfigsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContainerAppsAuthConfigs client: %+v", err) + } + configureFunc(containerAppsAuthConfigsClient.Client) + + containerAppsClient, err := containerapps.NewContainerAppsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContainerApps client: %+v", err) + } + configureFunc(containerAppsClient.Client) + + containerAppsRevisionReplicasClient, err := containerappsrevisionreplicas.NewContainerAppsRevisionReplicasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContainerAppsRevisionReplicas client: %+v", err) + } + configureFunc(containerAppsRevisionReplicasClient.Client) + + containerAppsRevisionsClient, err := containerappsrevisions.NewContainerAppsRevisionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContainerAppsRevisions client: %+v", err) + } + configureFunc(containerAppsRevisionsClient.Client) + + containerAppsSessionPoolsClient, err := containerappssessionpools.NewContainerAppsSessionPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContainerAppsSessionPools client: %+v", err) + } + configureFunc(containerAppsSessionPoolsClient.Client) + + containerAppsSourceControlsClient, err := containerappssourcecontrols.NewContainerAppsSourceControlsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContainerAppsSourceControls client: %+v", err) + } + configureFunc(containerAppsSourceControlsClient.Client) + + daprComponentsClient, err := daprcomponents.NewDaprComponentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DaprComponents client: %+v", err) + } + configureFunc(daprComponentsClient.Client) + + diagnosticsClient, err := diagnostics.NewDiagnosticsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Diagnostics client: %+v", err) + } + configureFunc(diagnosticsClient.Client) + + javaComponentsClient, err := javacomponents.NewJavaComponentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JavaComponents client: %+v", err) + } + configureFunc(javaComponentsClient.Client) + + jobsClient, err := jobs.NewJobsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Jobs client: %+v", err) + } + configureFunc(jobsClient.Client) + + managedCertificatesClient, err := managedcertificates.NewManagedCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedCertificates client: %+v", err) + } + configureFunc(managedCertificatesClient.Client) + + managedEnvironmentsClient, err := managedenvironments.NewManagedEnvironmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedEnvironments client: %+v", err) + } + configureFunc(managedEnvironmentsClient.Client) + + managedEnvironmentsStoragesClient, err := managedenvironmentsstorages.NewManagedEnvironmentsStoragesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedEnvironmentsStorages client: %+v", err) + } + configureFunc(managedEnvironmentsStoragesClient.Client) + + subscriptionsClient, err := subscriptions.NewSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Subscriptions client: %+v", err) + } + configureFunc(subscriptionsClient.Client) + + usagesClient, err := usages.NewUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Usages client: %+v", err) + } + configureFunc(usagesClient.Client) + + return &Client{ + AvailableWorkloadProfiles: availableWorkloadProfilesClient, + BillingMeters: billingMetersClient, + Certificates: certificatesClient, + ConnectedEnvironments: connectedEnvironmentsClient, + ConnectedEnvironmentsStorages: connectedEnvironmentsStoragesClient, + ContainerApps: containerAppsClient, + ContainerAppsAuthConfigs: containerAppsAuthConfigsClient, + ContainerAppsRevisionReplicas: containerAppsRevisionReplicasClient, + ContainerAppsRevisions: containerAppsRevisionsClient, + ContainerAppsSessionPools: containerAppsSessionPoolsClient, + ContainerAppsSourceControls: containerAppsSourceControlsClient, + DaprComponents: daprComponentsClient, + Diagnostics: diagnosticsClient, + JavaComponents: javaComponentsClient, + Jobs: jobsClient, + ManagedCertificates: managedCertificatesClient, + ManagedEnvironments: managedEnvironmentsClient, + ManagedEnvironmentsStorages: managedEnvironmentsStoragesClient, + Subscriptions: subscriptionsClient, + Usages: usagesClient, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/README.md b/resource-manager/containerapps/2025-01-01/connectedenvironments/README.md new file mode 100644 index 00000000000..c972a4c5794 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/README.md @@ -0,0 +1,228 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/connectedenvironments` Documentation + +The `connectedenvironments` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/connectedenvironments" +``` + + +### Client Initialization + +```go +client := connectedenvironments.NewConnectedEnvironmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +payload := connectedenvironments.Certificate{ + // ... +} + + +read, err := client.CertificatesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CertificatesDelete` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +read, err := client.CertificatesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CertificatesGet` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +read, err := client.CertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CertificatesList` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +// alternatively `client.CertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.CertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CertificatesUpdate` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + +payload := connectedenvironments.CertificatePatch{ + // ... +} + + +read, err := client.CertificatesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +payload := connectedenvironments.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +payload := connectedenvironments.ConnectedEnvironment{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.Delete` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedEnvironmentsClient.Get` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +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: `ConnectedEnvironmentsClient.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: `ConnectedEnvironmentsClient.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: `ConnectedEnvironmentsClient.Update` + +```go +ctx := context.TODO() +id := connectedenvironments.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +read, err := client.Update(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/client.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/client.go new file mode 100644 index 00000000000..cef1faa8988 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/client.go @@ -0,0 +1,26 @@ +package connectedenvironments + +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 ConnectedEnvironmentsClient struct { + Client *resourcemanager.Client +} + +func NewConnectedEnvironmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*ConnectedEnvironmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "connectedenvironments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ConnectedEnvironmentsClient: %+v", err) + } + + return &ConnectedEnvironmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/constants.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/constants.go new file mode 100644 index 00000000000..651bf31cb00 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/constants.go @@ -0,0 +1,198 @@ +package connectedenvironments + +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 CertificateProvisioningState string + +const ( + CertificateProvisioningStateCanceled CertificateProvisioningState = "Canceled" + CertificateProvisioningStateDeleteFailed CertificateProvisioningState = "DeleteFailed" + CertificateProvisioningStateFailed CertificateProvisioningState = "Failed" + CertificateProvisioningStatePending CertificateProvisioningState = "Pending" + CertificateProvisioningStateSucceeded CertificateProvisioningState = "Succeeded" +) + +func PossibleValuesForCertificateProvisioningState() []string { + return []string{ + string(CertificateProvisioningStateCanceled), + string(CertificateProvisioningStateDeleteFailed), + string(CertificateProvisioningStateFailed), + string(CertificateProvisioningStatePending), + string(CertificateProvisioningStateSucceeded), + } +} + +func (s *CertificateProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateProvisioningState(input string) (*CertificateProvisioningState, error) { + vals := map[string]CertificateProvisioningState{ + "canceled": CertificateProvisioningStateCanceled, + "deletefailed": CertificateProvisioningStateDeleteFailed, + "failed": CertificateProvisioningStateFailed, + "pending": CertificateProvisioningStatePending, + "succeeded": CertificateProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateProvisioningState(input) + return &out, nil +} + +type CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} + +type ConnectedEnvironmentProvisioningState string + +const ( + ConnectedEnvironmentProvisioningStateCanceled ConnectedEnvironmentProvisioningState = "Canceled" + ConnectedEnvironmentProvisioningStateFailed ConnectedEnvironmentProvisioningState = "Failed" + ConnectedEnvironmentProvisioningStateInfrastructureSetupComplete ConnectedEnvironmentProvisioningState = "InfrastructureSetupComplete" + ConnectedEnvironmentProvisioningStateInfrastructureSetupInProgress ConnectedEnvironmentProvisioningState = "InfrastructureSetupInProgress" + ConnectedEnvironmentProvisioningStateInitializationInProgress ConnectedEnvironmentProvisioningState = "InitializationInProgress" + ConnectedEnvironmentProvisioningStateScheduledForDelete ConnectedEnvironmentProvisioningState = "ScheduledForDelete" + ConnectedEnvironmentProvisioningStateSucceeded ConnectedEnvironmentProvisioningState = "Succeeded" + ConnectedEnvironmentProvisioningStateWaiting ConnectedEnvironmentProvisioningState = "Waiting" +) + +func PossibleValuesForConnectedEnvironmentProvisioningState() []string { + return []string{ + string(ConnectedEnvironmentProvisioningStateCanceled), + string(ConnectedEnvironmentProvisioningStateFailed), + string(ConnectedEnvironmentProvisioningStateInfrastructureSetupComplete), + string(ConnectedEnvironmentProvisioningStateInfrastructureSetupInProgress), + string(ConnectedEnvironmentProvisioningStateInitializationInProgress), + string(ConnectedEnvironmentProvisioningStateScheduledForDelete), + string(ConnectedEnvironmentProvisioningStateSucceeded), + string(ConnectedEnvironmentProvisioningStateWaiting), + } +} + +func (s *ConnectedEnvironmentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectedEnvironmentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectedEnvironmentProvisioningState(input string) (*ConnectedEnvironmentProvisioningState, error) { + vals := map[string]ConnectedEnvironmentProvisioningState{ + "canceled": ConnectedEnvironmentProvisioningStateCanceled, + "failed": ConnectedEnvironmentProvisioningStateFailed, + "infrastructuresetupcomplete": ConnectedEnvironmentProvisioningStateInfrastructureSetupComplete, + "infrastructuresetupinprogress": ConnectedEnvironmentProvisioningStateInfrastructureSetupInProgress, + "initializationinprogress": ConnectedEnvironmentProvisioningStateInitializationInProgress, + "scheduledfordelete": ConnectedEnvironmentProvisioningStateScheduledForDelete, + "succeeded": ConnectedEnvironmentProvisioningStateSucceeded, + "waiting": ConnectedEnvironmentProvisioningStateWaiting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectedEnvironmentProvisioningState(input) + return &out, nil +} + +type ExtendedLocationTypes string + +const ( + ExtendedLocationTypesCustomLocation ExtendedLocationTypes = "CustomLocation" +) + +func PossibleValuesForExtendedLocationTypes() []string { + return []string{ + string(ExtendedLocationTypesCustomLocation), + } +} + +func (s *ExtendedLocationTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtendedLocationTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtendedLocationTypes(input string) (*ExtendedLocationTypes, error) { + vals := map[string]ExtendedLocationTypes{ + "customlocation": ExtendedLocationTypesCustomLocation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtendedLocationTypes(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment.go new file mode 100644 index 00000000000..84c08ab1f60 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment.go @@ -0,0 +1,130 @@ +package connectedenvironments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentId{} + +// ConnectedEnvironmentId is a struct representing the Resource ID for a Connected Environment +type ConnectedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string +} + +// NewConnectedEnvironmentID returns a new ConnectedEnvironmentId struct +func NewConnectedEnvironmentID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string) ConnectedEnvironmentId { + return ConnectedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + } +} + +// ParseConnectedEnvironmentID parses 'input' into a ConnectedEnvironmentId +func ParseConnectedEnvironmentID(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentIDInsensitively(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentID checks that 'input' can be parsed as a Connected Environment ID +func ValidateConnectedEnvironmentID(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 := ParseConnectedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment ID +func (id ConnectedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment ID +func (id ConnectedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + } +} + +// String returns a human-readable description of this Connected Environment ID +func (id ConnectedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + } + return fmt.Sprintf("Connected Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment_test.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment_test.go new file mode 100644 index 00000000000..98625d04c55 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironment_test.go @@ -0,0 +1,282 @@ +package connectedenvironments + +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 = &ConnectedEnvironmentId{} + +func TestNewConnectedEnvironmentID(t *testing.T) { + id := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } +} + +func TestFormatConnectedEnvironmentID(t *testing.T) { + actual := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestParseConnectedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentId(t *testing.T) { + segments := ConnectedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentId 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/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate.go new file mode 100644 index 00000000000..9a67ee9b09b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate.go @@ -0,0 +1,139 @@ +package connectedenvironments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentCertificateId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentCertificateId{} + +// ConnectedEnvironmentCertificateId is a struct representing the Resource ID for a Connected Environment Certificate +type ConnectedEnvironmentCertificateId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string + CertificateName string +} + +// NewConnectedEnvironmentCertificateID returns a new ConnectedEnvironmentCertificateId struct +func NewConnectedEnvironmentCertificateID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string, certificateName string) ConnectedEnvironmentCertificateId { + return ConnectedEnvironmentCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + CertificateName: certificateName, + } +} + +// ParseConnectedEnvironmentCertificateID parses 'input' into a ConnectedEnvironmentCertificateId +func ParseConnectedEnvironmentCertificateID(input string) (*ConnectedEnvironmentCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentCertificateIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentCertificateId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentCertificateIDInsensitively(input string) (*ConnectedEnvironmentCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentCertificateId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + if id.CertificateName, ok = input.Parsed["certificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentCertificateID checks that 'input' can be parsed as a Connected Environment Certificate ID +func ValidateConnectedEnvironmentCertificateID(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 := ParseConnectedEnvironmentCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment Certificate ID +func (id ConnectedEnvironmentCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment Certificate ID +func (id ConnectedEnvironmentCertificateId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateName"), + } +} + +// String returns a human-readable description of this Connected Environment Certificate ID +func (id ConnectedEnvironmentCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Connected Environment Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate_test.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate_test.go new file mode 100644 index 00000000000..391cea47aae --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/id_connectedenvironmentcertificate_test.go @@ -0,0 +1,327 @@ +package connectedenvironments + +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 = &ConnectedEnvironmentCertificateId{} + +func TestNewConnectedEnvironmentCertificateID(t *testing.T) { + id := NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } + + if id.CertificateName != "certificateName" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateName") + } +} + +func TestFormatConnectedEnvironmentCertificateID(t *testing.T) { + actual := NewConnectedEnvironmentCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "certificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName", + Expected: &ConnectedEnvironmentCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentCertificateID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseConnectedEnvironmentCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName", + Expected: &ConnectedEnvironmentCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe", + Expected: &ConnectedEnvironmentCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + CertificateName: "cErTiFiCaTeNaMe", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentCertificateIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentCertificateId(t *testing.T) { + segments := ConnectedEnvironmentCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentCertificateId 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/containerapps/2025-01-01/connectedenvironments/method_certificatescreateorupdate.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatescreateorupdate.go new file mode 100644 index 00000000000..3d22a251dc9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatescreateorupdate.go @@ -0,0 +1,57 @@ +package connectedenvironments + +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 CertificatesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CertificatesCreateOrUpdate ... +func (c ConnectedEnvironmentsClient) CertificatesCreateOrUpdate(ctx context.Context, id ConnectedEnvironmentCertificateId, input Certificate) (result CertificatesCreateOrUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesdelete.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesdelete.go new file mode 100644 index 00000000000..09af06779f6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesdelete.go @@ -0,0 +1,47 @@ +package connectedenvironments + +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 CertificatesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CertificatesDelete ... +func (c ConnectedEnvironmentsClient) CertificatesDelete(ctx context.Context, id ConnectedEnvironmentCertificateId) (result CertificatesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesget.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesget.go new file mode 100644 index 00000000000..966a4a27ff3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesget.go @@ -0,0 +1,53 @@ +package connectedenvironments + +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 CertificatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CertificatesGet ... +func (c ConnectedEnvironmentsClient) CertificatesGet(ctx context.Context, id ConnectedEnvironmentCertificateId) (result CertificatesGetOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificateslist.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificateslist.go new file mode 100644 index 00000000000..e19892bc42c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificateslist.go @@ -0,0 +1,105 @@ +package connectedenvironments + +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 CertificatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Certificate +} + +type CertificatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Certificate +} + +type CertificatesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *CertificatesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// CertificatesList ... +func (c ConnectedEnvironmentsClient) CertificatesList(ctx context.Context, id ConnectedEnvironmentId) (result CertificatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &CertificatesListCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]Certificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CertificatesListComplete retrieves all the results into a single object +func (c ConnectedEnvironmentsClient) CertificatesListComplete(ctx context.Context, id ConnectedEnvironmentId) (CertificatesListCompleteResult, error) { + return c.CertificatesListCompleteMatchingPredicate(ctx, id, CertificateOperationPredicate{}) +} + +// CertificatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ConnectedEnvironmentsClient) CertificatesListCompleteMatchingPredicate(ctx context.Context, id ConnectedEnvironmentId, predicate CertificateOperationPredicate) (result CertificatesListCompleteResult, err error) { + items := make([]Certificate, 0) + + resp, err := c.CertificatesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = CertificatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesupdate.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesupdate.go new file mode 100644 index 00000000000..e4c28cc87b2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_certificatesupdate.go @@ -0,0 +1,57 @@ +package connectedenvironments + +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 CertificatesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CertificatesUpdate ... +func (c ConnectedEnvironmentsClient) CertificatesUpdate(ctx context.Context, id ConnectedEnvironmentCertificateId, input CertificatePatch) (result CertificatesUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_checknameavailability.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_checknameavailability.go new file mode 100644 index 00000000000..59402ea647f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_checknameavailability.go @@ -0,0 +1,58 @@ +package connectedenvironments + +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 CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// CheckNameAvailability ... +func (c ConnectedEnvironmentsClient) CheckNameAvailability(ctx context.Context, id ConnectedEnvironmentId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_createorupdate.go new file mode 100644 index 00000000000..1653c1913bc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_createorupdate.go @@ -0,0 +1,75 @@ +package connectedenvironments + +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 *ConnectedEnvironment +} + +// CreateOrUpdate ... +func (c ConnectedEnvironmentsClient) CreateOrUpdate(ctx context.Context, id ConnectedEnvironmentId, input ConnectedEnvironment) (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 ConnectedEnvironmentsClient) CreateOrUpdateThenPoll(ctx context.Context, id ConnectedEnvironmentId, input ConnectedEnvironment) 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/containerapps/2025-01-01/connectedenvironments/method_delete.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_delete.go new file mode 100644 index 00000000000..394b82bf66c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_delete.go @@ -0,0 +1,71 @@ +package connectedenvironments + +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 ConnectedEnvironmentsClient) Delete(ctx context.Context, id ConnectedEnvironmentId) (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 ConnectedEnvironmentsClient) DeleteThenPoll(ctx context.Context, id ConnectedEnvironmentId) 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/containerapps/2025-01-01/connectedenvironments/method_get.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_get.go new file mode 100644 index 00000000000..b1fb378276d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_get.go @@ -0,0 +1,53 @@ +package connectedenvironments + +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 *ConnectedEnvironment +} + +// Get ... +func (c ConnectedEnvironmentsClient) Get(ctx context.Context, id ConnectedEnvironmentId) (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 ConnectedEnvironment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbyresourcegroup.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbyresourcegroup.go new file mode 100644 index 00000000000..28e1ba40913 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package connectedenvironments + +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 *[]ConnectedEnvironment +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ConnectedEnvironment +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ConnectedEnvironmentsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/connectedEnvironments", 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 *[]ConnectedEnvironment `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 ConnectedEnvironmentsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ConnectedEnvironmentOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ConnectedEnvironmentsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConnectedEnvironmentOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ConnectedEnvironment, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbysubscription.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbysubscription.go new file mode 100644 index 00000000000..2ad0dd55aa9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_listbysubscription.go @@ -0,0 +1,106 @@ +package connectedenvironments + +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 *[]ConnectedEnvironment +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ConnectedEnvironment +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ConnectedEnvironmentsClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/connectedEnvironments", 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 *[]ConnectedEnvironment `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 ConnectedEnvironmentsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ConnectedEnvironmentOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ConnectedEnvironmentsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConnectedEnvironmentOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]ConnectedEnvironment, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/method_update.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_update.go new file mode 100644 index 00000000000..d9e7ed00759 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/method_update.go @@ -0,0 +1,53 @@ +package connectedenvironments + +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 *ConnectedEnvironment +} + +// Update ... +func (c ConnectedEnvironmentsClient) Update(ctx context.Context, id ConnectedEnvironmentId) (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 + } + + 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 ConnectedEnvironment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificate.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificate.go new file mode 100644 index 00000000000..e669656d0d5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificate.go @@ -0,0 +1,18 @@ +package connectedenvironments + +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 Certificate struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *CertificateProperties `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/containerapps/2025-01-01/connectedenvironments/model_certificatekeyvaultproperties.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatekeyvaultproperties.go new file mode 100644 index 00000000000..9ae11b726c2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatekeyvaultproperties.go @@ -0,0 +1,9 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateKeyVaultProperties struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatepatch.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatepatch.go new file mode 100644 index 00000000000..bde3c7a1618 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificatepatch.go @@ -0,0 +1,8 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificatePatch struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificateproperties.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificateproperties.go new file mode 100644 index 00000000000..650f8930d1f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_certificateproperties.go @@ -0,0 +1,49 @@ +package connectedenvironments + +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 CertificateProperties struct { + CertificateKeyVaultProperties *CertificateKeyVaultProperties `json:"certificateKeyVaultProperties,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + IssueDate *string `json:"issueDate,omitempty"` + Issuer *string `json:"issuer,omitempty"` + Password *string `json:"password,omitempty"` + ProvisioningState *CertificateProvisioningState `json:"provisioningState,omitempty"` + PublicKeyHash *string `json:"publicKeyHash,omitempty"` + SubjectAlternativeNames *[]string `json:"subjectAlternativeNames,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Valid *bool `json:"valid,omitempty"` + Value *string `json:"value,omitempty"` +} + +func (o *CertificateProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} + +func (o *CertificateProperties) GetIssueDateAsTime() (*time.Time, error) { + if o.IssueDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.IssueDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateProperties) SetIssueDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.IssueDate = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityrequest.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..909f61a23c8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityresponse.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..93c8f443a29 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironment.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironment.go new file mode 100644 index 00000000000..fb933c13075 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironment.go @@ -0,0 +1,19 @@ +package connectedenvironments + +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 ConnectedEnvironment struct { + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ConnectedEnvironmentProperties `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/containerapps/2025-01-01/connectedenvironments/model_connectedenvironmentproperties.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironmentproperties.go new file mode 100644 index 00000000000..0804343a48a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_connectedenvironmentproperties.go @@ -0,0 +1,13 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedEnvironmentProperties struct { + CustomDomainConfiguration *CustomDomainConfiguration `json:"customDomainConfiguration,omitempty"` + DaprAIConnectionString *string `json:"daprAIConnectionString,omitempty"` + DefaultDomain *string `json:"defaultDomain,omitempty"` + DeploymentErrors *string `json:"deploymentErrors,omitempty"` + ProvisioningState *ConnectedEnvironmentProvisioningState `json:"provisioningState,omitempty"` + StaticIP *string `json:"staticIp,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_customdomainconfiguration.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_customdomainconfiguration.go new file mode 100644 index 00000000000..f27509460a1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_customdomainconfiguration.go @@ -0,0 +1,33 @@ +package connectedenvironments + +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 CustomDomainConfiguration struct { + CertificateKeyVaultProperties *CertificateKeyVaultProperties `json:"certificateKeyVaultProperties,omitempty"` + CertificatePassword *string `json:"certificatePassword,omitempty"` + CertificateValue *string `json:"certificateValue,omitempty"` + CustomDomainVerificationId *string `json:"customDomainVerificationId,omitempty"` + DnsSuffix *string `json:"dnsSuffix,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` +} + +func (o *CustomDomainConfiguration) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CustomDomainConfiguration) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/model_extendedlocation.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_extendedlocation.go new file mode 100644 index 00000000000..afe4338077a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/model_extendedlocation.go @@ -0,0 +1,9 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *ExtendedLocationTypes `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironments/predicates.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/predicates.go new file mode 100644 index 00000000000..56ab893afdf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/predicates.go @@ -0,0 +1,60 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p CertificateOperationPredicate) Matches(input Certificate) 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 +} + +type ConnectedEnvironmentOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ConnectedEnvironmentOperationPredicate) Matches(input ConnectedEnvironment) 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/containerapps/2025-01-01/connectedenvironments/version.go b/resource-manager/containerapps/2025-01-01/connectedenvironments/version.go new file mode 100644 index 00000000000..c555fd43dd2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironments/version.go @@ -0,0 +1,10 @@ +package connectedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/connectedenvironments/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/README.md b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/README.md new file mode 100644 index 00000000000..20c6868b4f5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages` Documentation + +The `connectedenvironmentsstorages` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages" +``` + + +### Client Initialization + +```go +client := connectedenvironmentsstorages.NewConnectedEnvironmentsStoragesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConnectedEnvironmentsStoragesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := connectedenvironmentsstorages.NewConnectedEnvironmentStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "storageName") + +payload := connectedenvironmentsstorages.ConnectedEnvironmentStorage{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsStoragesClient.Delete` + +```go +ctx := context.TODO() +id := connectedenvironmentsstorages.NewConnectedEnvironmentStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "storageName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedEnvironmentsStoragesClient.Get` + +```go +ctx := context.TODO() +id := connectedenvironmentsstorages.NewConnectedEnvironmentStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "storageName") + +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: `ConnectedEnvironmentsStoragesClient.List` + +```go +ctx := context.TODO() +id := connectedenvironmentsstorages.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/client.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/client.go new file mode 100644 index 00000000000..a93c2290a8e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/client.go @@ -0,0 +1,26 @@ +package connectedenvironmentsstorages + +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 ConnectedEnvironmentsStoragesClient struct { + Client *resourcemanager.Client +} + +func NewConnectedEnvironmentsStoragesClientWithBaseURI(sdkApi sdkEnv.Api) (*ConnectedEnvironmentsStoragesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "connectedenvironmentsstorages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ConnectedEnvironmentsStoragesClient: %+v", err) + } + + return &ConnectedEnvironmentsStoragesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/constants.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/constants.go new file mode 100644 index 00000000000..fd1b71dbed2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/constants.go @@ -0,0 +1,51 @@ +package connectedenvironmentsstorages + +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 AccessMode string + +const ( + AccessModeReadOnly AccessMode = "ReadOnly" + AccessModeReadWrite AccessMode = "ReadWrite" +) + +func PossibleValuesForAccessMode() []string { + return []string{ + string(AccessModeReadOnly), + string(AccessModeReadWrite), + } +} + +func (s *AccessMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessMode(input string) (*AccessMode, error) { + vals := map[string]AccessMode{ + "readonly": AccessModeReadOnly, + "readwrite": AccessModeReadWrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessMode(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment.go new file mode 100644 index 00000000000..27ae75ace9b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment.go @@ -0,0 +1,130 @@ +package connectedenvironmentsstorages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentId{} + +// ConnectedEnvironmentId is a struct representing the Resource ID for a Connected Environment +type ConnectedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string +} + +// NewConnectedEnvironmentID returns a new ConnectedEnvironmentId struct +func NewConnectedEnvironmentID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string) ConnectedEnvironmentId { + return ConnectedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + } +} + +// ParseConnectedEnvironmentID parses 'input' into a ConnectedEnvironmentId +func ParseConnectedEnvironmentID(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentIDInsensitively(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentID checks that 'input' can be parsed as a Connected Environment ID +func ValidateConnectedEnvironmentID(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 := ParseConnectedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment ID +func (id ConnectedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment ID +func (id ConnectedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + } +} + +// String returns a human-readable description of this Connected Environment ID +func (id ConnectedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + } + return fmt.Sprintf("Connected Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment_test.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment_test.go new file mode 100644 index 00000000000..31cf85ccb5b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironment_test.go @@ -0,0 +1,282 @@ +package connectedenvironmentsstorages + +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 = &ConnectedEnvironmentId{} + +func TestNewConnectedEnvironmentID(t *testing.T) { + id := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } +} + +func TestFormatConnectedEnvironmentID(t *testing.T) { + actual := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestParseConnectedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentId(t *testing.T) { + segments := ConnectedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentId 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/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage.go new file mode 100644 index 00000000000..bc6e3402627 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage.go @@ -0,0 +1,139 @@ +package connectedenvironmentsstorages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentStorageId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentStorageId{} + +// ConnectedEnvironmentStorageId is a struct representing the Resource ID for a Connected Environment Storage +type ConnectedEnvironmentStorageId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string + StorageName string +} + +// NewConnectedEnvironmentStorageID returns a new ConnectedEnvironmentStorageId struct +func NewConnectedEnvironmentStorageID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string, storageName string) ConnectedEnvironmentStorageId { + return ConnectedEnvironmentStorageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + StorageName: storageName, + } +} + +// ParseConnectedEnvironmentStorageID parses 'input' into a ConnectedEnvironmentStorageId +func ParseConnectedEnvironmentStorageID(input string) (*ConnectedEnvironmentStorageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentStorageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentStorageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentStorageIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentStorageId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentStorageIDInsensitively(input string) (*ConnectedEnvironmentStorageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentStorageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentStorageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentStorageId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + if id.StorageName, ok = input.Parsed["storageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "storageName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentStorageID checks that 'input' can be parsed as a Connected Environment Storage ID +func ValidateConnectedEnvironmentStorageID(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 := ParseConnectedEnvironmentStorageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment Storage ID +func (id ConnectedEnvironmentStorageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s/storages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName, id.StorageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment Storage ID +func (id ConnectedEnvironmentStorageId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + resourceids.StaticSegment("staticStorages", "storages", "storages"), + resourceids.UserSpecifiedSegment("storageName", "storageName"), + } +} + +// String returns a human-readable description of this Connected Environment Storage ID +func (id ConnectedEnvironmentStorageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + fmt.Sprintf("Storage Name: %q", id.StorageName), + } + return fmt.Sprintf("Connected Environment Storage (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage_test.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage_test.go new file mode 100644 index 00000000000..e1f33341c34 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/id_connectedenvironmentstorage_test.go @@ -0,0 +1,327 @@ +package connectedenvironmentsstorages + +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 = &ConnectedEnvironmentStorageId{} + +func TestNewConnectedEnvironmentStorageID(t *testing.T) { + id := NewConnectedEnvironmentStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "storageName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } + + if id.StorageName != "storageName" { + t.Fatalf("Expected %q but got %q for Segment 'StorageName'", id.StorageName, "storageName") + } +} + +func TestFormatConnectedEnvironmentStorageID(t *testing.T) { + actual := NewConnectedEnvironmentStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "storageName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages/storageName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentStorageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentStorageId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages/storageName", + Expected: &ConnectedEnvironmentStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + StorageName: "storageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages/storageName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentStorageID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.StorageName != v.Expected.StorageName { + t.Fatalf("Expected %q but got %q for StorageName", v.Expected.StorageName, actual.StorageName) + } + + } +} + +func TestParseConnectedEnvironmentStorageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentStorageId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/sToRaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages/storageName", + Expected: &ConnectedEnvironmentStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + StorageName: "storageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/storages/storageName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/sToRaGeS/sToRaGeNaMe", + Expected: &ConnectedEnvironmentStorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + StorageName: "sToRaGeNaMe", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/sToRaGeS/sToRaGeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentStorageIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.StorageName != v.Expected.StorageName { + t.Fatalf("Expected %q but got %q for StorageName", v.Expected.StorageName, actual.StorageName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentStorageId(t *testing.T) { + segments := ConnectedEnvironmentStorageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentStorageId 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/containerapps/2025-01-01/connectedenvironmentsstorages/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_createorupdate.go new file mode 100644 index 00000000000..b15be5ee53c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_createorupdate.go @@ -0,0 +1,57 @@ +package connectedenvironmentsstorages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ConnectedEnvironmentStorage +} + +// CreateOrUpdate ... +func (c ConnectedEnvironmentsStoragesClient) CreateOrUpdate(ctx context.Context, id ConnectedEnvironmentStorageId, input ConnectedEnvironmentStorage) (result CreateOrUpdateOperationResponse, 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 ConnectedEnvironmentStorage + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_delete.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_delete.go new file mode 100644 index 00000000000..f3ac6d8b309 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_delete.go @@ -0,0 +1,47 @@ +package connectedenvironmentsstorages + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ConnectedEnvironmentsStoragesClient) Delete(ctx context.Context, id ConnectedEnvironmentStorageId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_get.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_get.go new file mode 100644 index 00000000000..926b8eeba69 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_get.go @@ -0,0 +1,53 @@ +package connectedenvironmentsstorages + +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 *ConnectedEnvironmentStorage +} + +// Get ... +func (c ConnectedEnvironmentsStoragesClient) Get(ctx context.Context, id ConnectedEnvironmentStorageId) (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 ConnectedEnvironmentStorage + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_list.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_list.go new file mode 100644 index 00000000000..b661d7781ac --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/method_list.go @@ -0,0 +1,54 @@ +package connectedenvironmentsstorages + +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 *ConnectedEnvironmentStoragesCollection +} + +// List ... +func (c ConnectedEnvironmentsStoragesClient) List(ctx context.Context, id ConnectedEnvironmentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/storages", 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 ConnectedEnvironmentStoragesCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_azurefileproperties.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_azurefileproperties.go new file mode 100644 index 00000000000..1aafd335320 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_azurefileproperties.go @@ -0,0 +1,11 @@ +package connectedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureFileProperties struct { + AccessMode *AccessMode `json:"accessMode,omitempty"` + AccountKey *string `json:"accountKey,omitempty"` + AccountName *string `json:"accountName,omitempty"` + ShareName *string `json:"shareName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorage.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorage.go new file mode 100644 index 00000000000..35a00599e24 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorage.go @@ -0,0 +1,16 @@ +package connectedenvironmentsstorages + +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 ConnectedEnvironmentStorage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ConnectedEnvironmentStorageProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorageproperties.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorageproperties.go new file mode 100644 index 00000000000..e9150596c08 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstorageproperties.go @@ -0,0 +1,8 @@ +package connectedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedEnvironmentStorageProperties struct { + AzureFile *AzureFileProperties `json:"azureFile,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstoragescollection.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstoragescollection.go new file mode 100644 index 00000000000..a17921d81b7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/model_connectedenvironmentstoragescollection.go @@ -0,0 +1,8 @@ +package connectedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedEnvironmentStoragesCollection struct { + Value []ConnectedEnvironmentStorage `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/version.go b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/version.go new file mode 100644 index 00000000000..a1a03fadc45 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/connectedenvironmentsstorages/version.go @@ -0,0 +1,10 @@ +package connectedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/connectedenvironmentsstorages/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/README.md b/resource-manager/containerapps/2025-01-01/containerapps/README.md new file mode 100644 index 00000000000..9e5c7ba1809 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/README.md @@ -0,0 +1,271 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerapps` Documentation + +The `containerapps` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerapps" +``` + + +### Client Initialization + +```go +client := containerapps.NewContainerAppsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContainerAppsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +payload := containerapps.ContainerApp{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsClient.Delete` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsClient.DiagnosticsGetDetector` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "detectorName") + +read, err := client.DiagnosticsGetDetector(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsClient.DiagnosticsGetRevision` + +```go +ctx := context.TODO() +id := containerapps.NewRevisionsApiRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.DiagnosticsGetRevision(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsClient.DiagnosticsGetRoot` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +read, err := client.DiagnosticsGetRoot(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsClient.DiagnosticsListDetectors` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.DiagnosticsListDetectors(ctx, id)` can be used to do batched pagination +items, err := client.DiagnosticsListDetectorsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ContainerAppsClient.DiagnosticsListRevisions` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.DiagnosticsListRevisions(ctx, id, containerapps.DefaultDiagnosticsListRevisionsOperationOptions())` can be used to do batched pagination +items, err := client.DiagnosticsListRevisionsComplete(ctx, id, containerapps.DefaultDiagnosticsListRevisionsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ContainerAppsClient.Get` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +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: `ContainerAppsClient.GetAuthToken` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +read, err := client.GetAuthToken(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsClient.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: `ContainerAppsClient.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: `ContainerAppsClient.ListCustomHostNameAnalysis` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +read, err := client.ListCustomHostNameAnalysis(ctx, id, containerapps.DefaultListCustomHostNameAnalysisOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsClient.ListSecrets` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsClient.Start` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +if err := client.StartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsClient.Stop` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +if err := client.StopThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsClient.Update` + +```go +ctx := context.TODO() +id := containerapps.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +payload := containerapps.ContainerApp{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerapps/2025-01-01/containerapps/client.go b/resource-manager/containerapps/2025-01-01/containerapps/client.go new file mode 100644 index 00000000000..aed3cca9efb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/client.go @@ -0,0 +1,26 @@ +package containerapps + +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 ContainerAppsClient struct { + Client *resourcemanager.Client +} + +func NewContainerAppsClientWithBaseURI(sdkApi sdkEnv.Api) (*ContainerAppsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "containerapps", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContainerAppsClient: %+v", err) + } + + return &ContainerAppsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/constants.go b/resource-manager/containerapps/2025-01-01/containerapps/constants.go new file mode 100644 index 00000000000..b2004875a25 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/constants.go @@ -0,0 +1,861 @@ +package containerapps + +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 Action string + +const ( + ActionAllow Action = "Allow" + ActionDeny Action = "Deny" +) + +func PossibleValuesForAction() []string { + return []string{ + string(ActionAllow), + string(ActionDeny), + } +} + +func (s *Action) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAction(input string) (*Action, error) { + vals := map[string]Action{ + "allow": ActionAllow, + "deny": ActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Action(input) + return &out, nil +} + +type ActiveRevisionsMode string + +const ( + ActiveRevisionsModeMultiple ActiveRevisionsMode = "Multiple" + ActiveRevisionsModeSingle ActiveRevisionsMode = "Single" +) + +func PossibleValuesForActiveRevisionsMode() []string { + return []string{ + string(ActiveRevisionsModeMultiple), + string(ActiveRevisionsModeSingle), + } +} + +func (s *ActiveRevisionsMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActiveRevisionsMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActiveRevisionsMode(input string) (*ActiveRevisionsMode, error) { + vals := map[string]ActiveRevisionsMode{ + "multiple": ActiveRevisionsModeMultiple, + "single": ActiveRevisionsModeSingle, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActiveRevisionsMode(input) + return &out, nil +} + +type Affinity string + +const ( + AffinityNone Affinity = "none" + AffinitySticky Affinity = "sticky" +) + +func PossibleValuesForAffinity() []string { + return []string{ + string(AffinityNone), + string(AffinitySticky), + } +} + +func (s *Affinity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAffinity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAffinity(input string) (*Affinity, error) { + vals := map[string]Affinity{ + "none": AffinityNone, + "sticky": AffinitySticky, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Affinity(input) + return &out, nil +} + +type AppProtocol string + +const ( + AppProtocolGrpc AppProtocol = "grpc" + AppProtocolHTTP AppProtocol = "http" +) + +func PossibleValuesForAppProtocol() []string { + return []string{ + string(AppProtocolGrpc), + string(AppProtocolHTTP), + } +} + +func (s *AppProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAppProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAppProtocol(input string) (*AppProtocol, error) { + vals := map[string]AppProtocol{ + "grpc": AppProtocolGrpc, + "http": AppProtocolHTTP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AppProtocol(input) + return &out, nil +} + +type BindingType string + +const ( + BindingTypeDisabled BindingType = "Disabled" + BindingTypeSniEnabled BindingType = "SniEnabled" +) + +func PossibleValuesForBindingType() []string { + return []string{ + string(BindingTypeDisabled), + string(BindingTypeSniEnabled), + } +} + +func (s *BindingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBindingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBindingType(input string) (*BindingType, error) { + vals := map[string]BindingType{ + "disabled": BindingTypeDisabled, + "snienabled": BindingTypeSniEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BindingType(input) + return &out, nil +} + +type ContainerAppProvisioningState string + +const ( + ContainerAppProvisioningStateCanceled ContainerAppProvisioningState = "Canceled" + ContainerAppProvisioningStateDeleting ContainerAppProvisioningState = "Deleting" + ContainerAppProvisioningStateFailed ContainerAppProvisioningState = "Failed" + ContainerAppProvisioningStateInProgress ContainerAppProvisioningState = "InProgress" + ContainerAppProvisioningStateSucceeded ContainerAppProvisioningState = "Succeeded" +) + +func PossibleValuesForContainerAppProvisioningState() []string { + return []string{ + string(ContainerAppProvisioningStateCanceled), + string(ContainerAppProvisioningStateDeleting), + string(ContainerAppProvisioningStateFailed), + string(ContainerAppProvisioningStateInProgress), + string(ContainerAppProvisioningStateSucceeded), + } +} + +func (s *ContainerAppProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerAppProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerAppProvisioningState(input string) (*ContainerAppProvisioningState, error) { + vals := map[string]ContainerAppProvisioningState{ + "canceled": ContainerAppProvisioningStateCanceled, + "deleting": ContainerAppProvisioningStateDeleting, + "failed": ContainerAppProvisioningStateFailed, + "inprogress": ContainerAppProvisioningStateInProgress, + "succeeded": ContainerAppProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerAppProvisioningState(input) + return &out, nil +} + +type ContainerAppRunningStatus string + +const ( + ContainerAppRunningStatusProgressing ContainerAppRunningStatus = "Progressing" + ContainerAppRunningStatusReady ContainerAppRunningStatus = "Ready" + ContainerAppRunningStatusRunning ContainerAppRunningStatus = "Running" + ContainerAppRunningStatusStopped ContainerAppRunningStatus = "Stopped" + ContainerAppRunningStatusSuspended ContainerAppRunningStatus = "Suspended" +) + +func PossibleValuesForContainerAppRunningStatus() []string { + return []string{ + string(ContainerAppRunningStatusProgressing), + string(ContainerAppRunningStatusReady), + string(ContainerAppRunningStatusRunning), + string(ContainerAppRunningStatusStopped), + string(ContainerAppRunningStatusSuspended), + } +} + +func (s *ContainerAppRunningStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerAppRunningStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerAppRunningStatus(input string) (*ContainerAppRunningStatus, error) { + vals := map[string]ContainerAppRunningStatus{ + "progressing": ContainerAppRunningStatusProgressing, + "ready": ContainerAppRunningStatusReady, + "running": ContainerAppRunningStatusRunning, + "stopped": ContainerAppRunningStatusStopped, + "suspended": ContainerAppRunningStatusSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerAppRunningStatus(input) + return &out, nil +} + +type DnsVerificationTestResult string + +const ( + DnsVerificationTestResultFailed DnsVerificationTestResult = "Failed" + DnsVerificationTestResultPassed DnsVerificationTestResult = "Passed" + DnsVerificationTestResultSkipped DnsVerificationTestResult = "Skipped" +) + +func PossibleValuesForDnsVerificationTestResult() []string { + return []string{ + string(DnsVerificationTestResultFailed), + string(DnsVerificationTestResultPassed), + string(DnsVerificationTestResultSkipped), + } +} + +func (s *DnsVerificationTestResult) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDnsVerificationTestResult(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDnsVerificationTestResult(input string) (*DnsVerificationTestResult, error) { + vals := map[string]DnsVerificationTestResult{ + "failed": DnsVerificationTestResultFailed, + "passed": DnsVerificationTestResultPassed, + "skipped": DnsVerificationTestResultSkipped, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DnsVerificationTestResult(input) + return &out, nil +} + +type ExtendedLocationTypes string + +const ( + ExtendedLocationTypesCustomLocation ExtendedLocationTypes = "CustomLocation" +) + +func PossibleValuesForExtendedLocationTypes() []string { + return []string{ + string(ExtendedLocationTypesCustomLocation), + } +} + +func (s *ExtendedLocationTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtendedLocationTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtendedLocationTypes(input string) (*ExtendedLocationTypes, error) { + vals := map[string]ExtendedLocationTypes{ + "customlocation": ExtendedLocationTypesCustomLocation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtendedLocationTypes(input) + return &out, nil +} + +type IdentitySettingsLifeCycle string + +const ( + IdentitySettingsLifeCycleAll IdentitySettingsLifeCycle = "All" + IdentitySettingsLifeCycleInit IdentitySettingsLifeCycle = "Init" + IdentitySettingsLifeCycleMain IdentitySettingsLifeCycle = "Main" + IdentitySettingsLifeCycleNone IdentitySettingsLifeCycle = "None" +) + +func PossibleValuesForIdentitySettingsLifeCycle() []string { + return []string{ + string(IdentitySettingsLifeCycleAll), + string(IdentitySettingsLifeCycleInit), + string(IdentitySettingsLifeCycleMain), + string(IdentitySettingsLifeCycleNone), + } +} + +func (s *IdentitySettingsLifeCycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentitySettingsLifeCycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentitySettingsLifeCycle(input string) (*IdentitySettingsLifeCycle, error) { + vals := map[string]IdentitySettingsLifeCycle{ + "all": IdentitySettingsLifeCycleAll, + "init": IdentitySettingsLifeCycleInit, + "main": IdentitySettingsLifeCycleMain, + "none": IdentitySettingsLifeCycleNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentitySettingsLifeCycle(input) + return &out, nil +} + +type IngressClientCertificateMode string + +const ( + IngressClientCertificateModeAccept IngressClientCertificateMode = "accept" + IngressClientCertificateModeIgnore IngressClientCertificateMode = "ignore" + IngressClientCertificateModeRequire IngressClientCertificateMode = "require" +) + +func PossibleValuesForIngressClientCertificateMode() []string { + return []string{ + string(IngressClientCertificateModeAccept), + string(IngressClientCertificateModeIgnore), + string(IngressClientCertificateModeRequire), + } +} + +func (s *IngressClientCertificateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIngressClientCertificateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIngressClientCertificateMode(input string) (*IngressClientCertificateMode, error) { + vals := map[string]IngressClientCertificateMode{ + "accept": IngressClientCertificateModeAccept, + "ignore": IngressClientCertificateModeIgnore, + "require": IngressClientCertificateModeRequire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IngressClientCertificateMode(input) + return &out, nil +} + +type IngressTransportMethod string + +const ( + IngressTransportMethodAuto IngressTransportMethod = "auto" + IngressTransportMethodHTTP IngressTransportMethod = "http" + IngressTransportMethodHTTPTwo IngressTransportMethod = "http2" + IngressTransportMethodTcp IngressTransportMethod = "tcp" +) + +func PossibleValuesForIngressTransportMethod() []string { + return []string{ + string(IngressTransportMethodAuto), + string(IngressTransportMethodHTTP), + string(IngressTransportMethodHTTPTwo), + string(IngressTransportMethodTcp), + } +} + +func (s *IngressTransportMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIngressTransportMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIngressTransportMethod(input string) (*IngressTransportMethod, error) { + vals := map[string]IngressTransportMethod{ + "auto": IngressTransportMethodAuto, + "http": IngressTransportMethodHTTP, + "http2": IngressTransportMethodHTTPTwo, + "tcp": IngressTransportMethodTcp, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IngressTransportMethod(input) + return &out, nil +} + +type LogLevel string + +const ( + LogLevelDebug LogLevel = "debug" + LogLevelError LogLevel = "error" + LogLevelInfo LogLevel = "info" + LogLevelWarn LogLevel = "warn" +) + +func PossibleValuesForLogLevel() []string { + return []string{ + string(LogLevelDebug), + string(LogLevelError), + string(LogLevelInfo), + string(LogLevelWarn), + } +} + +func (s *LogLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLogLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLogLevel(input string) (*LogLevel, error) { + vals := map[string]LogLevel{ + "debug": LogLevelDebug, + "error": LogLevelError, + "info": LogLevelInfo, + "warn": LogLevelWarn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LogLevel(input) + return &out, nil +} + +type RevisionHealthState string + +const ( + RevisionHealthStateHealthy RevisionHealthState = "Healthy" + RevisionHealthStateNone RevisionHealthState = "None" + RevisionHealthStateUnhealthy RevisionHealthState = "Unhealthy" +) + +func PossibleValuesForRevisionHealthState() []string { + return []string{ + string(RevisionHealthStateHealthy), + string(RevisionHealthStateNone), + string(RevisionHealthStateUnhealthy), + } +} + +func (s *RevisionHealthState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionHealthState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionHealthState(input string) (*RevisionHealthState, error) { + vals := map[string]RevisionHealthState{ + "healthy": RevisionHealthStateHealthy, + "none": RevisionHealthStateNone, + "unhealthy": RevisionHealthStateUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionHealthState(input) + return &out, nil +} + +type RevisionProvisioningState string + +const ( + RevisionProvisioningStateDeprovisioned RevisionProvisioningState = "Deprovisioned" + RevisionProvisioningStateDeprovisioning RevisionProvisioningState = "Deprovisioning" + RevisionProvisioningStateFailed RevisionProvisioningState = "Failed" + RevisionProvisioningStateProvisioned RevisionProvisioningState = "Provisioned" + RevisionProvisioningStateProvisioning RevisionProvisioningState = "Provisioning" +) + +func PossibleValuesForRevisionProvisioningState() []string { + return []string{ + string(RevisionProvisioningStateDeprovisioned), + string(RevisionProvisioningStateDeprovisioning), + string(RevisionProvisioningStateFailed), + string(RevisionProvisioningStateProvisioned), + string(RevisionProvisioningStateProvisioning), + } +} + +func (s *RevisionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionProvisioningState(input string) (*RevisionProvisioningState, error) { + vals := map[string]RevisionProvisioningState{ + "deprovisioned": RevisionProvisioningStateDeprovisioned, + "deprovisioning": RevisionProvisioningStateDeprovisioning, + "failed": RevisionProvisioningStateFailed, + "provisioned": RevisionProvisioningStateProvisioned, + "provisioning": RevisionProvisioningStateProvisioning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionProvisioningState(input) + return &out, nil +} + +type RevisionRunningState string + +const ( + RevisionRunningStateDegraded RevisionRunningState = "Degraded" + RevisionRunningStateFailed RevisionRunningState = "Failed" + RevisionRunningStateProcessing RevisionRunningState = "Processing" + RevisionRunningStateRunning RevisionRunningState = "Running" + RevisionRunningStateStopped RevisionRunningState = "Stopped" + RevisionRunningStateUnknown RevisionRunningState = "Unknown" +) + +func PossibleValuesForRevisionRunningState() []string { + return []string{ + string(RevisionRunningStateDegraded), + string(RevisionRunningStateFailed), + string(RevisionRunningStateProcessing), + string(RevisionRunningStateRunning), + string(RevisionRunningStateStopped), + string(RevisionRunningStateUnknown), + } +} + +func (s *RevisionRunningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionRunningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionRunningState(input string) (*RevisionRunningState, error) { + vals := map[string]RevisionRunningState{ + "degraded": RevisionRunningStateDegraded, + "failed": RevisionRunningStateFailed, + "processing": RevisionRunningStateProcessing, + "running": RevisionRunningStateRunning, + "stopped": RevisionRunningStateStopped, + "unknown": RevisionRunningStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionRunningState(input) + return &out, nil +} + +type Scheme string + +const ( + SchemeHTTP Scheme = "HTTP" + SchemeHTTPS Scheme = "HTTPS" +) + +func PossibleValuesForScheme() []string { + return []string{ + string(SchemeHTTP), + string(SchemeHTTPS), + } +} + +func (s *Scheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheme(input string) (*Scheme, error) { + vals := map[string]Scheme{ + "http": SchemeHTTP, + "https": SchemeHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Scheme(input) + return &out, nil +} + +type StorageType string + +const ( + StorageTypeAzureFile StorageType = "AzureFile" + StorageTypeEmptyDir StorageType = "EmptyDir" + StorageTypeNfsAzureFile StorageType = "NfsAzureFile" + StorageTypeSecret StorageType = "Secret" +) + +func PossibleValuesForStorageType() []string { + return []string{ + string(StorageTypeAzureFile), + string(StorageTypeEmptyDir), + string(StorageTypeNfsAzureFile), + string(StorageTypeSecret), + } +} + +func (s *StorageType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageType(input string) (*StorageType, error) { + vals := map[string]StorageType{ + "azurefile": StorageTypeAzureFile, + "emptydir": StorageTypeEmptyDir, + "nfsazurefile": StorageTypeNfsAzureFile, + "secret": StorageTypeSecret, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageType(input) + return &out, nil +} + +type Type string + +const ( + TypeLiveness Type = "Liveness" + TypeReadiness Type = "Readiness" + TypeStartup Type = "Startup" +) + +func PossibleValuesForType() []string { + return []string{ + string(TypeLiveness), + string(TypeReadiness), + string(TypeStartup), + } +} + +func (s *Type) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseType(input string) (*Type, error) { + vals := map[string]Type{ + "liveness": TypeLiveness, + "readiness": TypeReadiness, + "startup": TypeStartup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Type(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/id_containerapp.go b/resource-manager/containerapps/2025-01-01/containerapps/id_containerapp.go new file mode 100644 index 00000000000..fcbbf0087d6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/id_containerapp.go @@ -0,0 +1,130 @@ +package containerapps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppId{}) +} + +var _ resourceids.ResourceId = &ContainerAppId{} + +// ContainerAppId is a struct representing the Resource ID for a Container App +type ContainerAppId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string +} + +// NewContainerAppID returns a new ContainerAppId struct +func NewContainerAppID(subscriptionId string, resourceGroupName string, containerAppName string) ContainerAppId { + return ContainerAppId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + } +} + +// ParseContainerAppID parses 'input' into a ContainerAppId +func ParseContainerAppID(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppIDInsensitively parses 'input' case-insensitively into a ContainerAppId +// note: this method should only be used for API response data and not user input +func ParseContainerAppIDInsensitively(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + return nil +} + +// ValidateContainerAppID checks that 'input' can be parsed as a Container App ID +func ValidateContainerAppID(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 := ParseContainerAppID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App ID +func (id ContainerAppId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App ID +func (id ContainerAppId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + } +} + +// String returns a human-readable description of this Container App ID +func (id ContainerAppId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + } + return fmt.Sprintf("Container App (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/id_containerapp_test.go b/resource-manager/containerapps/2025-01-01/containerapps/id_containerapp_test.go new file mode 100644 index 00000000000..3a29171b576 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/id_containerapp_test.go @@ -0,0 +1,282 @@ +package containerapps + +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 = &ContainerAppId{} + +func TestNewContainerAppID(t *testing.T) { + id := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } +} + +func TestFormatContainerAppID(t *testing.T) { + actual := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestParseContainerAppIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestSegmentsForContainerAppId(t *testing.T) { + segments := ContainerAppId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppId 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/containerapps/2025-01-01/containerapps/id_containerappdetector.go b/resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector.go new file mode 100644 index 00000000000..e44277b4baf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector.go @@ -0,0 +1,139 @@ +package containerapps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppDetectorId{}) +} + +var _ resourceids.ResourceId = &ContainerAppDetectorId{} + +// ContainerAppDetectorId is a struct representing the Resource ID for a Container App Detector +type ContainerAppDetectorId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + DetectorName string +} + +// NewContainerAppDetectorID returns a new ContainerAppDetectorId struct +func NewContainerAppDetectorID(subscriptionId string, resourceGroupName string, containerAppName string, detectorName string) ContainerAppDetectorId { + return ContainerAppDetectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + DetectorName: detectorName, + } +} + +// ParseContainerAppDetectorID parses 'input' into a ContainerAppDetectorId +func ParseContainerAppDetectorID(input string) (*ContainerAppDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppDetectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppDetectorIDInsensitively parses 'input' case-insensitively into a ContainerAppDetectorId +// note: this method should only be used for API response data and not user input +func ParseContainerAppDetectorIDInsensitively(input string) (*ContainerAppDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppDetectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppDetectorId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.DetectorName, ok = input.Parsed["detectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorName", input) + } + + return nil +} + +// ValidateContainerAppDetectorID checks that 'input' can be parsed as a Container App Detector ID +func ValidateContainerAppDetectorID(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 := ParseContainerAppDetectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App Detector ID +func (id ContainerAppDetectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/detectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.DetectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App Detector ID +func (id ContainerAppDetectorId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticDetectors", "detectors", "detectors"), + resourceids.UserSpecifiedSegment("detectorName", "detectorName"), + } +} + +// String returns a human-readable description of this Container App Detector ID +func (id ContainerAppDetectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Detector Name: %q", id.DetectorName), + } + return fmt.Sprintf("Container App Detector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector_test.go b/resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector_test.go new file mode 100644 index 00000000000..fb138a9681f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/id_containerappdetector_test.go @@ -0,0 +1,327 @@ +package containerapps + +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 = &ContainerAppDetectorId{} + +func TestNewContainerAppDetectorID(t *testing.T) { + id := NewContainerAppDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "detectorName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.DetectorName != "detectorName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorName'", id.DetectorName, "detectorName") + } +} + +func TestFormatContainerAppDetectorID(t *testing.T) { + actual := NewContainerAppDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "detectorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppDetectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName", + Expected: &ContainerAppDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppDetectorID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestParseContainerAppDetectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName", + Expected: &ContainerAppDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRs/dEtEcToRnAmE", + Expected: &ContainerAppDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + DetectorName: "dEtEcToRnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRs/dEtEcToRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppDetectorIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestSegmentsForContainerAppDetectorId(t *testing.T) { + segments := ContainerAppDetectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppDetectorId 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/containerapps/2025-01-01/containerapps/id_revisionsapirevision.go b/resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision.go new file mode 100644 index 00000000000..6597dd0e46a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision.go @@ -0,0 +1,141 @@ +package containerapps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RevisionsApiRevisionId{}) +} + +var _ resourceids.ResourceId = &RevisionsApiRevisionId{} + +// RevisionsApiRevisionId is a struct representing the Resource ID for a Revisions Api Revision +type RevisionsApiRevisionId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + RevisionName string +} + +// NewRevisionsApiRevisionID returns a new RevisionsApiRevisionId struct +func NewRevisionsApiRevisionID(subscriptionId string, resourceGroupName string, containerAppName string, revisionName string) RevisionsApiRevisionId { + return RevisionsApiRevisionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + RevisionName: revisionName, + } +} + +// ParseRevisionsApiRevisionID parses 'input' into a RevisionsApiRevisionId +func ParseRevisionsApiRevisionID(input string) (*RevisionsApiRevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionsApiRevisionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionsApiRevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRevisionsApiRevisionIDInsensitively parses 'input' case-insensitively into a RevisionsApiRevisionId +// note: this method should only be used for API response data and not user input +func ParseRevisionsApiRevisionIDInsensitively(input string) (*RevisionsApiRevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionsApiRevisionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionsApiRevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RevisionsApiRevisionId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.RevisionName, ok = input.Parsed["revisionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "revisionName", input) + } + + return nil +} + +// ValidateRevisionsApiRevisionID checks that 'input' can be parsed as a Revisions Api Revision ID +func ValidateRevisionsApiRevisionID(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 := ParseRevisionsApiRevisionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Revisions Api Revision ID +func (id RevisionsApiRevisionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/detectorProperties/revisionsApi/revisions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.RevisionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Revisions Api Revision ID +func (id RevisionsApiRevisionId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticDetectorProperties", "detectorProperties", "detectorProperties"), + resourceids.StaticSegment("staticRevisionsApi", "revisionsApi", "revisionsApi"), + resourceids.StaticSegment("staticRevisions", "revisions", "revisions"), + resourceids.UserSpecifiedSegment("revisionName", "revisionName"), + } +} + +// String returns a human-readable description of this Revisions Api Revision ID +func (id RevisionsApiRevisionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Revision Name: %q", id.RevisionName), + } + return fmt.Sprintf("Revisions Api Revision (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision_test.go b/resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision_test.go new file mode 100644 index 00000000000..4fde474ee6c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/id_revisionsapirevision_test.go @@ -0,0 +1,357 @@ +package containerapps + +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 = &RevisionsApiRevisionId{} + +func TestNewRevisionsApiRevisionID(t *testing.T) { + id := NewRevisionsApiRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.RevisionName != "revisionName" { + t.Fatalf("Expected %q but got %q for Segment 'RevisionName'", id.RevisionName, "revisionName") + } +} + +func TestFormatRevisionsApiRevisionID(t *testing.T) { + actual := NewRevisionsApiRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRevisionsApiRevisionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionsApiRevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName", + Expected: &RevisionsApiRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionsApiRevisionID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestParseRevisionsApiRevisionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionsApiRevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI/rEvIsIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName", + Expected: &RevisionsApiRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI/rEvIsIoNs/rEvIsIoNnAmE", + Expected: &RevisionsApiRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + RevisionName: "rEvIsIoNnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI/rEvIsIoNs/rEvIsIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionsApiRevisionIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestSegmentsForRevisionsApiRevisionId(t *testing.T) { + segments := RevisionsApiRevisionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RevisionsApiRevisionId 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/containerapps/2025-01-01/containerapps/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/containerapps/method_createorupdate.go new file mode 100644 index 00000000000..5db04646129 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_createorupdate.go @@ -0,0 +1,75 @@ +package containerapps + +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 *ContainerApp +} + +// CreateOrUpdate ... +func (c ContainerAppsClient) CreateOrUpdate(ctx context.Context, id ContainerAppId, input ContainerApp) (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 ContainerAppsClient) CreateOrUpdateThenPoll(ctx context.Context, id ContainerAppId, input ContainerApp) 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/containerapps/2025-01-01/containerapps/method_delete.go b/resource-manager/containerapps/2025-01-01/containerapps/method_delete.go new file mode 100644 index 00000000000..049bcddb705 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_delete.go @@ -0,0 +1,71 @@ +package containerapps + +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 ContainerAppsClient) Delete(ctx context.Context, id ContainerAppId) (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 ContainerAppsClient) DeleteThenPoll(ctx context.Context, id ContainerAppId) 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/containerapps/2025-01-01/containerapps/method_diagnosticsgetdetector.go b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetdetector.go new file mode 100644 index 00000000000..0a9e86c2cd6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetdetector.go @@ -0,0 +1,53 @@ +package containerapps + +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 DiagnosticsGetDetectorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Diagnostics +} + +// DiagnosticsGetDetector ... +func (c ContainerAppsClient) DiagnosticsGetDetector(ctx context.Context, id ContainerAppDetectorId) (result DiagnosticsGetDetectorOperationResponse, 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 Diagnostics + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetrevision.go b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetrevision.go new file mode 100644 index 00000000000..968db6baceb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetrevision.go @@ -0,0 +1,53 @@ +package containerapps + +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 DiagnosticsGetRevisionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Revision +} + +// DiagnosticsGetRevision ... +func (c ContainerAppsClient) DiagnosticsGetRevision(ctx context.Context, id RevisionsApiRevisionId) (result DiagnosticsGetRevisionOperationResponse, 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 Revision + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetroot.go b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetroot.go new file mode 100644 index 00000000000..8c9904e5395 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticsgetroot.go @@ -0,0 +1,54 @@ +package containerapps + +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 DiagnosticsGetRootOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContainerApp +} + +// DiagnosticsGetRoot ... +func (c ContainerAppsClient) DiagnosticsGetRoot(ctx context.Context, id ContainerAppId) (result DiagnosticsGetRootOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/detectorProperties/rootApi", 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 ContainerApp + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistdetectors.go b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistdetectors.go new file mode 100644 index 00000000000..987ae49a3b1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistdetectors.go @@ -0,0 +1,105 @@ +package containerapps + +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 DiagnosticsListDetectorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Diagnostics +} + +type DiagnosticsListDetectorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Diagnostics +} + +type DiagnosticsListDetectorsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DiagnosticsListDetectorsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DiagnosticsListDetectors ... +func (c ContainerAppsClient) DiagnosticsListDetectors(ctx context.Context, id ContainerAppId) (result DiagnosticsListDetectorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DiagnosticsListDetectorsCustomPager{}, + Path: fmt.Sprintf("%s/detectors", 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 *[]Diagnostics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DiagnosticsListDetectorsComplete retrieves all the results into a single object +func (c ContainerAppsClient) DiagnosticsListDetectorsComplete(ctx context.Context, id ContainerAppId) (DiagnosticsListDetectorsCompleteResult, error) { + return c.DiagnosticsListDetectorsCompleteMatchingPredicate(ctx, id, DiagnosticsOperationPredicate{}) +} + +// DiagnosticsListDetectorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsClient) DiagnosticsListDetectorsCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, predicate DiagnosticsOperationPredicate) (result DiagnosticsListDetectorsCompleteResult, err error) { + items := make([]Diagnostics, 0) + + resp, err := c.DiagnosticsListDetectors(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DiagnosticsListDetectorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistrevisions.go b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistrevisions.go new file mode 100644 index 00000000000..6d8d5523fbd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_diagnosticslistrevisions.go @@ -0,0 +1,134 @@ +package containerapps + +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 DiagnosticsListRevisionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Revision +} + +type DiagnosticsListRevisionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Revision +} + +type DiagnosticsListRevisionsOperationOptions struct { + Filter *string +} + +func DefaultDiagnosticsListRevisionsOperationOptions() DiagnosticsListRevisionsOperationOptions { + return DiagnosticsListRevisionsOperationOptions{} +} + +func (o DiagnosticsListRevisionsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DiagnosticsListRevisionsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DiagnosticsListRevisionsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type DiagnosticsListRevisionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DiagnosticsListRevisionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DiagnosticsListRevisions ... +func (c ContainerAppsClient) DiagnosticsListRevisions(ctx context.Context, id ContainerAppId, options DiagnosticsListRevisionsOperationOptions) (result DiagnosticsListRevisionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &DiagnosticsListRevisionsCustomPager{}, + Path: fmt.Sprintf("%s/detectorProperties/revisionsApi/revisions", 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 *[]Revision `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DiagnosticsListRevisionsComplete retrieves all the results into a single object +func (c ContainerAppsClient) DiagnosticsListRevisionsComplete(ctx context.Context, id ContainerAppId, options DiagnosticsListRevisionsOperationOptions) (DiagnosticsListRevisionsCompleteResult, error) { + return c.DiagnosticsListRevisionsCompleteMatchingPredicate(ctx, id, options, RevisionOperationPredicate{}) +} + +// DiagnosticsListRevisionsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsClient) DiagnosticsListRevisionsCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, options DiagnosticsListRevisionsOperationOptions, predicate RevisionOperationPredicate) (result DiagnosticsListRevisionsCompleteResult, err error) { + items := make([]Revision, 0) + + resp, err := c.DiagnosticsListRevisions(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DiagnosticsListRevisionsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_get.go b/resource-manager/containerapps/2025-01-01/containerapps/method_get.go new file mode 100644 index 00000000000..b17e455e923 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_get.go @@ -0,0 +1,53 @@ +package containerapps + +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 *ContainerApp +} + +// Get ... +func (c ContainerAppsClient) Get(ctx context.Context, id ContainerAppId) (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 ContainerApp + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_getauthtoken.go b/resource-manager/containerapps/2025-01-01/containerapps/method_getauthtoken.go new file mode 100644 index 00000000000..7203313fe74 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_getauthtoken.go @@ -0,0 +1,54 @@ +package containerapps + +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 GetAuthTokenOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContainerAppAuthToken +} + +// GetAuthToken ... +func (c ContainerAppsClient) GetAuthToken(ctx context.Context, id ContainerAppId) (result GetAuthTokenOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getAuthtoken", 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 ContainerAppAuthToken + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_listbyresourcegroup.go b/resource-manager/containerapps/2025-01-01/containerapps/method_listbyresourcegroup.go new file mode 100644 index 00000000000..1b2010cc343 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package containerapps + +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 *[]ContainerApp +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ContainerApp +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ContainerAppsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/containerApps", 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 *[]ContainerApp `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 ContainerAppsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ContainerAppOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ContainerAppOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ContainerApp, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_listbysubscription.go b/resource-manager/containerapps/2025-01-01/containerapps/method_listbysubscription.go new file mode 100644 index 00000000000..e80ef0ec67e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_listbysubscription.go @@ -0,0 +1,106 @@ +package containerapps + +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 *[]ContainerApp +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ContainerApp +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ContainerAppsClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/containerApps", 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 *[]ContainerApp `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 ContainerAppsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ContainerAppOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ContainerAppOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]ContainerApp, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_listcustomhostnameanalysis.go b/resource-manager/containerapps/2025-01-01/containerapps/method_listcustomhostnameanalysis.go new file mode 100644 index 00000000000..17119ef149e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_listcustomhostnameanalysis.go @@ -0,0 +1,83 @@ +package containerapps + +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 ListCustomHostNameAnalysisOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CustomHostnameAnalysisResult +} + +type ListCustomHostNameAnalysisOperationOptions struct { + CustomHostname *string +} + +func DefaultListCustomHostNameAnalysisOperationOptions() ListCustomHostNameAnalysisOperationOptions { + return ListCustomHostNameAnalysisOperationOptions{} +} + +func (o ListCustomHostNameAnalysisOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListCustomHostNameAnalysisOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListCustomHostNameAnalysisOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CustomHostname != nil { + out.Append("customHostname", fmt.Sprintf("%v", *o.CustomHostname)) + } + return &out +} + +// ListCustomHostNameAnalysis ... +func (c ContainerAppsClient) ListCustomHostNameAnalysis(ctx context.Context, id ContainerAppId, options ListCustomHostNameAnalysisOperationOptions) (result ListCustomHostNameAnalysisOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/listCustomHostNameAnalysis", 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 CustomHostnameAnalysisResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_listsecrets.go b/resource-manager/containerapps/2025-01-01/containerapps/method_listsecrets.go new file mode 100644 index 00000000000..8c35814e73f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_listsecrets.go @@ -0,0 +1,54 @@ +package containerapps + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecretsCollection +} + +// ListSecrets ... +func (c ContainerAppsClient) ListSecrets(ctx context.Context, id ContainerAppId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 SecretsCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_start.go b/resource-manager/containerapps/2025-01-01/containerapps/method_start.go new file mode 100644 index 00000000000..5e3e3cd7b7e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_start.go @@ -0,0 +1,71 @@ +package containerapps + +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 StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ContainerApp +} + +// Start ... +func (c ContainerAppsClient) Start(ctx context.Context, id ContainerAppId) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 +} + +// StartThenPoll performs Start then polls until it's completed +func (c ContainerAppsClient) StartThenPoll(ctx context.Context, id ContainerAppId) error { + result, err := c.Start(ctx, id) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_stop.go b/resource-manager/containerapps/2025-01-01/containerapps/method_stop.go new file mode 100644 index 00000000000..7b29fa28f8e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_stop.go @@ -0,0 +1,71 @@ +package containerapps + +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 StopOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ContainerApp +} + +// Stop ... +func (c ContainerAppsClient) Stop(ctx context.Context, id ContainerAppId) (result StopOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", 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 +} + +// StopThenPoll performs Stop then polls until it's completed +func (c ContainerAppsClient) StopThenPoll(ctx context.Context, id ContainerAppId) error { + result, err := c.Stop(ctx, id) + if err != nil { + return fmt.Errorf("performing Stop: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Stop: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/method_update.go b/resource-manager/containerapps/2025-01-01/containerapps/method_update.go new file mode 100644 index 00000000000..4b197837332 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/method_update.go @@ -0,0 +1,75 @@ +package containerapps + +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 *ContainerApp +} + +// Update ... +func (c ContainerAppsClient) Update(ctx context.Context, id ContainerAppId, input ContainerApp) (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 ContainerAppsClient) UpdateThenPoll(ctx context.Context, id ContainerAppId, input ContainerApp) 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/containerapps/2025-01-01/containerapps/model_basecontainer.go b/resource-manager/containerapps/2025-01-01/containerapps/model_basecontainer.go new file mode 100644 index 00000000000..3190b1630ca --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_basecontainer.go @@ -0,0 +1,14 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseContainer struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_configuration.go b/resource-manager/containerapps/2025-01-01/containerapps/model_configuration.go new file mode 100644 index 00000000000..33dfc262a4b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_configuration.go @@ -0,0 +1,16 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Configuration struct { + ActiveRevisionsMode *ActiveRevisionsMode `json:"activeRevisionsMode,omitempty"` + Dapr *Dapr `json:"dapr,omitempty"` + IdentitySettings *[]IdentitySettings `json:"identitySettings,omitempty"` + Ingress *Ingress `json:"ingress,omitempty"` + MaxInactiveRevisions *int64 `json:"maxInactiveRevisions,omitempty"` + Registries *[]RegistryCredentials `json:"registries,omitempty"` + Runtime *Runtime `json:"runtime,omitempty"` + Secrets *[]Secret `json:"secrets,omitempty"` + Service *Service `json:"service,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_container.go b/resource-manager/containerapps/2025-01-01/containerapps/model_container.go new file mode 100644 index 00000000000..eacb62148fd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_container.go @@ -0,0 +1,15 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Container struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Probes *[]ContainerAppProbe `json:"probes,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerapp.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerapp.go new file mode 100644 index 00000000000..0c382ed5867 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerapp.go @@ -0,0 +1,22 @@ +package containerapps + +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 ContainerApp struct { + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ContainerAppProperties `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/containerapps/2025-01-01/containerapps/model_containerappauthtoken.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappauthtoken.go new file mode 100644 index 00000000000..89b63f9e369 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappauthtoken.go @@ -0,0 +1,18 @@ +package containerapps + +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 ContainerAppAuthToken struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ContainerAppAuthTokenProperties `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/containerapps/2025-01-01/containerapps/model_containerappauthtokenproperties.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappauthtokenproperties.go new file mode 100644 index 00000000000..243fce5c07e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappauthtokenproperties.go @@ -0,0 +1,27 @@ +package containerapps + +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 ContainerAppAuthTokenProperties struct { + Expires *string `json:"expires,omitempty"` + Token *string `json:"token,omitempty"` +} + +func (o *ContainerAppAuthTokenProperties) GetExpiresAsTime() (*time.Time, error) { + if o.Expires == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expires, "2006-01-02T15:04:05Z07:00") +} + +func (o *ContainerAppAuthTokenProperties) SetExpiresAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expires = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobe.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobe.go new file mode 100644 index 00000000000..a704b4ab897 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobe.go @@ -0,0 +1,16 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbe struct { + FailureThreshold *int64 `json:"failureThreshold,omitempty"` + HTTPGet *ContainerAppProbeHTTPGet `json:"httpGet,omitempty"` + InitialDelaySeconds *int64 `json:"initialDelaySeconds,omitempty"` + PeriodSeconds *int64 `json:"periodSeconds,omitempty"` + SuccessThreshold *int64 `json:"successThreshold,omitempty"` + TcpSocket *ContainerAppProbeTcpSocket `json:"tcpSocket,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"` + Type *Type `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpget.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpget.go new file mode 100644 index 00000000000..7f78b0e6271 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpget.go @@ -0,0 +1,12 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGet struct { + HTTPHeaders *[]ContainerAppProbeHTTPGetHTTPHeadersInlined `json:"httpHeaders,omitempty"` + Host *string `json:"host,omitempty"` + Path *string `json:"path,omitempty"` + Port int64 `json:"port"` + Scheme *Scheme `json:"scheme,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpgethttpheadersinlined.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpgethttpheadersinlined.go new file mode 100644 index 00000000000..d97ce91ffab --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobehttpgethttpheadersinlined.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGetHTTPHeadersInlined struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobetcpsocket.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobetcpsocket.go new file mode 100644 index 00000000000..94d442c5fdd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappprobetcpsocket.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeTcpSocket struct { + Host *string `json:"host,omitempty"` + Port int64 `json:"port"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerappproperties.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappproperties.go new file mode 100644 index 00000000000..be9db397b5e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappproperties.go @@ -0,0 +1,20 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProperties struct { + Configuration *Configuration `json:"configuration,omitempty"` + CustomDomainVerificationId *string `json:"customDomainVerificationId,omitempty"` + EnvironmentId *string `json:"environmentId,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + LatestReadyRevisionName *string `json:"latestReadyRevisionName,omitempty"` + LatestRevisionFqdn *string `json:"latestRevisionFqdn,omitempty"` + LatestRevisionName *string `json:"latestRevisionName,omitempty"` + ManagedEnvironmentId *string `json:"managedEnvironmentId,omitempty"` + OutboundIPAddresses *[]string `json:"outboundIpAddresses,omitempty"` + ProvisioningState *ContainerAppProvisioningState `json:"provisioningState,omitempty"` + RunningStatus *ContainerAppRunningStatus `json:"runningStatus,omitempty"` + Template *Template `json:"template,omitempty"` + WorkloadProfileName *string `json:"workloadProfileName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerappsecret.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappsecret.go new file mode 100644 index 00000000000..757144a4dab --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerappsecret.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppSecret struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_containerresources.go b/resource-manager/containerapps/2025-01-01/containerapps/model_containerresources.go new file mode 100644 index 00000000000..3d55e9ef422 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_containerresources.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerResources struct { + Cpu *float64 `json:"cpu,omitempty"` + EphemeralStorage *string `json:"ephemeralStorage,omitempty"` + Memory *string `json:"memory,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_corspolicy.go b/resource-manager/containerapps/2025-01-01/containerapps/model_corspolicy.go new file mode 100644 index 00000000000..414eae00470 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_corspolicy.go @@ -0,0 +1,13 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CorsPolicy struct { + AllowCredentials *bool `json:"allowCredentials,omitempty"` + AllowedHeaders *[]string `json:"allowedHeaders,omitempty"` + AllowedMethods *[]string `json:"allowedMethods,omitempty"` + AllowedOrigins []string `json:"allowedOrigins"` + ExposeHeaders *[]string `json:"exposeHeaders,omitempty"` + MaxAge *int64 `json:"maxAge,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_customdomain.go b/resource-manager/containerapps/2025-01-01/containerapps/model_customdomain.go new file mode 100644 index 00000000000..aeab69111fc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_customdomain.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomain struct { + BindingType *BindingType `json:"bindingType,omitempty"` + CertificateId *string `json:"certificateId,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresult.go b/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresult.go new file mode 100644 index 00000000000..e6108a84148 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresult.go @@ -0,0 +1,19 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomHostnameAnalysisResult struct { + ARecords *[]string `json:"aRecords,omitempty"` + AlternateCNameRecords *[]string `json:"alternateCNameRecords,omitempty"` + AlternateTxtRecords *[]string `json:"alternateTxtRecords,omitempty"` + CNameRecords *[]string `json:"cNameRecords,omitempty"` + ConflictWithEnvironmentCustomDomain *bool `json:"conflictWithEnvironmentCustomDomain,omitempty"` + ConflictingContainerAppResourceId *string `json:"conflictingContainerAppResourceId,omitempty"` + CustomDomainVerificationFailureInfo *CustomHostnameAnalysisResultCustomDomainVerificationFailureInfo `json:"customDomainVerificationFailureInfo,omitempty"` + CustomDomainVerificationTest *DnsVerificationTestResult `json:"customDomainVerificationTest,omitempty"` + HasConflictOnManagedEnvironment *bool `json:"hasConflictOnManagedEnvironment,omitempty"` + HostName *string `json:"hostName,omitempty"` + IsHostnameAlreadyVerified *bool `json:"isHostnameAlreadyVerified,omitempty"` + TxtRecords *[]string `json:"txtRecords,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfo.go b/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfo.go new file mode 100644 index 00000000000..490a78264ab --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfo.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomHostnameAnalysisResultCustomDomainVerificationFailureInfo struct { + Code *string `json:"code,omitempty"` + Details *[]CustomHostnameAnalysisResultCustomDomainVerificationFailureInfoDetailsInlined `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfodetailsinlined.go b/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfodetailsinlined.go new file mode 100644 index 00000000000..1a9643ffafa --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_customhostnameanalysisresultcustomdomainverificationfailureinfodetailsinlined.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomHostnameAnalysisResultCustomDomainVerificationFailureInfoDetailsInlined struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_customscalerule.go b/resource-manager/containerapps/2025-01-01/containerapps/model_customscalerule.go new file mode 100644 index 00000000000..a7fb9071b8f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_customscalerule.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_dapr.go b/resource-manager/containerapps/2025-01-01/containerapps/model_dapr.go new file mode 100644 index 00000000000..be3e090812b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_dapr.go @@ -0,0 +1,15 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Dapr struct { + AppId *string `json:"appId,omitempty"` + AppPort *int64 `json:"appPort,omitempty"` + AppProtocol *AppProtocol `json:"appProtocol,omitempty"` + EnableApiLogging *bool `json:"enableApiLogging,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + HTTPMaxRequestSize *int64 `json:"httpMaxRequestSize,omitempty"` + HTTPReadBufferSize *int64 `json:"httpReadBufferSize,omitempty"` + LogLevel *LogLevel `json:"logLevel,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadata.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadata.go new file mode 100644 index 00000000000..4f49cfc1268 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadata.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadata struct { + PropertyBag *[]DiagnosticDataProviderMetadataPropertyBagInlined `json:"propertyBag,omitempty"` + ProviderName *string `json:"providerName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadatapropertybaginlined.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadatapropertybaginlined.go new file mode 100644 index 00000000000..bb3c8371f29 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdataprovidermetadatapropertybaginlined.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadataPropertyBagInlined struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponsecolumn.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponsecolumn.go new file mode 100644 index 00000000000..f0da0d4af5a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponsecolumn.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseColumn struct { + ColumnName *string `json:"columnName,omitempty"` + ColumnType *string `json:"columnType,omitempty"` + DataType *string `json:"dataType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponseobject.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponseobject.go new file mode 100644 index 00000000000..f5ab6cef03a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticdatatableresponseobject.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseObject struct { + Columns *[]DiagnosticDataTableResponseColumn `json:"columns,omitempty"` + Rows *[]interface{} `json:"rows,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticrendering.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticrendering.go new file mode 100644 index 00000000000..febf8f4bc44 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticrendering.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticRendering struct { + Description *string `json:"description,omitempty"` + IsVisible *bool `json:"isVisible,omitempty"` + Title *string `json:"title,omitempty"` + Type *int64 `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnostics.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnostics.go new file mode 100644 index 00000000000..332b9e6e8a7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnostics.go @@ -0,0 +1,16 @@ +package containerapps + +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 Diagnostics struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdataapiresponse.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdataapiresponse.go new file mode 100644 index 00000000000..8a4e162a0f1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdataapiresponse.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDataApiResponse struct { + RenderingProperties *DiagnosticRendering `json:"renderingProperties,omitempty"` + Table *DiagnosticDataTableResponseObject `json:"table,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdefinition.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdefinition.go new file mode 100644 index 00000000000..01d57bd28c2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsdefinition.go @@ -0,0 +1,16 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDefinition struct { + AnalysisTypes *[]string `json:"analysisTypes,omitempty"` + Author *string `json:"author,omitempty"` + Category *string `json:"category,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Score *float64 `json:"score,omitempty"` + SupportTopicList *[]DiagnosticSupportTopic `json:"supportTopicList,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsproperties.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsproperties.go new file mode 100644 index 00000000000..5606b01916e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsproperties.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsProperties struct { + DataProviderMetadata *DiagnosticDataProviderMetadata `json:"dataProviderMetadata,omitempty"` + Dataset *[]DiagnosticsDataApiResponse `json:"dataset,omitempty"` + Metadata *DiagnosticsDefinition `json:"metadata,omitempty"` + Status *DiagnosticsStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsstatus.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsstatus.go new file mode 100644 index 00000000000..ff2dafc6e9e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsstatus.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsStatus struct { + Message *string `json:"message,omitempty"` + StatusId *int64 `json:"statusId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsupporttopic.go b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsupporttopic.go new file mode 100644 index 00000000000..36d9fb7fe24 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_diagnosticsupporttopic.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSupportTopic struct { + Id *string `json:"id,omitempty"` + PesId *string `json:"pesId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_environmentvar.go b/resource-manager/containerapps/2025-01-01/containerapps/model_environmentvar.go new file mode 100644 index 00000000000..e25ec6c8bc8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_environmentvar.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentVar struct { + Name *string `json:"name,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_extendedlocation.go b/resource-manager/containerapps/2025-01-01/containerapps/model_extendedlocation.go new file mode 100644 index 00000000000..20073b0ba29 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_extendedlocation.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *ExtendedLocationTypes `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_httpscalerule.go b/resource-manager/containerapps/2025-01-01/containerapps/model_httpscalerule.go new file mode 100644 index 00000000000..d64fa4db093 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_httpscalerule.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_identitysettings.go b/resource-manager/containerapps/2025-01-01/containerapps/model_identitysettings.go new file mode 100644 index 00000000000..0f5d0193908 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_identitysettings.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentitySettings struct { + Identity string `json:"identity"` + Lifecycle *IdentitySettingsLifeCycle `json:"lifecycle,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_ingress.go b/resource-manager/containerapps/2025-01-01/containerapps/model_ingress.go new file mode 100644 index 00000000000..8b20fd57cf7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_ingress.go @@ -0,0 +1,20 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Ingress struct { + AdditionalPortMappings *[]IngressPortMapping `json:"additionalPortMappings,omitempty"` + AllowInsecure *bool `json:"allowInsecure,omitempty"` + ClientCertificateMode *IngressClientCertificateMode `json:"clientCertificateMode,omitempty"` + CorsPolicy *CorsPolicy `json:"corsPolicy,omitempty"` + CustomDomains *[]CustomDomain `json:"customDomains,omitempty"` + ExposedPort *int64 `json:"exposedPort,omitempty"` + External *bool `json:"external,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + IPSecurityRestrictions *[]IPSecurityRestrictionRule `json:"ipSecurityRestrictions,omitempty"` + StickySessions *IngressStickySessions `json:"stickySessions,omitempty"` + TargetPort *int64 `json:"targetPort,omitempty"` + Traffic *[]TrafficWeight `json:"traffic,omitempty"` + Transport *IngressTransportMethod `json:"transport,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_ingressportmapping.go b/resource-manager/containerapps/2025-01-01/containerapps/model_ingressportmapping.go new file mode 100644 index 00000000000..f7f84d45faa --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_ingressportmapping.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IngressPortMapping struct { + ExposedPort *int64 `json:"exposedPort,omitempty"` + External bool `json:"external"` + TargetPort int64 `json:"targetPort"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_ingressstickysessions.go b/resource-manager/containerapps/2025-01-01/containerapps/model_ingressstickysessions.go new file mode 100644 index 00000000000..48b18e0ee17 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_ingressstickysessions.go @@ -0,0 +1,8 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IngressStickySessions struct { + Affinity *Affinity `json:"affinity,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_ipsecurityrestrictionrule.go b/resource-manager/containerapps/2025-01-01/containerapps/model_ipsecurityrestrictionrule.go new file mode 100644 index 00000000000..959c43b6cbb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_ipsecurityrestrictionrule.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPSecurityRestrictionRule struct { + Action Action `json:"action"` + Description *string `json:"description,omitempty"` + IPAddressRange string `json:"ipAddressRange"` + Name string `json:"name"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_queuescalerule.go b/resource-manager/containerapps/2025-01-01/containerapps/model_queuescalerule.go new file mode 100644 index 00000000000..169d370604f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_queuescalerule.go @@ -0,0 +1,12 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueueScaleRule struct { + AccountName *string `json:"accountName,omitempty"` + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + QueueLength *int64 `json:"queueLength,omitempty"` + QueueName *string `json:"queueName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_registrycredentials.go b/resource-manager/containerapps/2025-01-01/containerapps/model_registrycredentials.go new file mode 100644 index 00000000000..bab9a7f8a4c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_registrycredentials.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryCredentials struct { + Identity *string `json:"identity,omitempty"` + PasswordSecretRef *string `json:"passwordSecretRef,omitempty"` + Server *string `json:"server,omitempty"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_revision.go b/resource-manager/containerapps/2025-01-01/containerapps/model_revision.go new file mode 100644 index 00000000000..02d41684620 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_revision.go @@ -0,0 +1,16 @@ +package containerapps + +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 Revision struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RevisionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_revisionproperties.go b/resource-manager/containerapps/2025-01-01/containerapps/model_revisionproperties.go new file mode 100644 index 00000000000..2fc409ae580 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_revisionproperties.go @@ -0,0 +1,48 @@ +package containerapps + +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 RevisionProperties struct { + Active *bool `json:"active,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + HealthState *RevisionHealthState `json:"healthState,omitempty"` + LastActiveTime *string `json:"lastActiveTime,omitempty"` + ProvisioningError *string `json:"provisioningError,omitempty"` + ProvisioningState *RevisionProvisioningState `json:"provisioningState,omitempty"` + Replicas *int64 `json:"replicas,omitempty"` + RunningState *RevisionRunningState `json:"runningState,omitempty"` + Template *Template `json:"template,omitempty"` + TrafficWeight *int64 `json:"trafficWeight,omitempty"` +} + +func (o *RevisionProperties) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RevisionProperties) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} + +func (o *RevisionProperties) GetLastActiveTimeAsTime() (*time.Time, error) { + if o.LastActiveTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastActiveTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RevisionProperties) SetLastActiveTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastActiveTime = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_runtime.go b/resource-manager/containerapps/2025-01-01/containerapps/model_runtime.go new file mode 100644 index 00000000000..66f2ba2580a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_runtime.go @@ -0,0 +1,8 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Runtime struct { + Java *RuntimeJava `json:"java,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_runtimejava.go b/resource-manager/containerapps/2025-01-01/containerapps/model_runtimejava.go new file mode 100644 index 00000000000..c4140113a60 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_runtimejava.go @@ -0,0 +1,8 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuntimeJava struct { + EnableMetrics *bool `json:"enableMetrics,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_scale.go b/resource-manager/containerapps/2025-01-01/containerapps/model_scale.go new file mode 100644 index 00000000000..347298627b5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_scale.go @@ -0,0 +1,12 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Scale struct { + CooldownPeriod *int64 `json:"cooldownPeriod,omitempty"` + MaxReplicas *int64 `json:"maxReplicas,omitempty"` + MinReplicas *int64 `json:"minReplicas,omitempty"` + PollingInterval *int64 `json:"pollingInterval,omitempty"` + Rules *[]ScaleRule `json:"rules,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_scalerule.go b/resource-manager/containerapps/2025-01-01/containerapps/model_scalerule.go new file mode 100644 index 00000000000..93c358a6fa7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_scalerule.go @@ -0,0 +1,12 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRule struct { + AzureQueue *QueueScaleRule `json:"azureQueue,omitempty"` + Custom *CustomScaleRule `json:"custom,omitempty"` + HTTP *HTTPScaleRule `json:"http,omitempty"` + Name *string `json:"name,omitempty"` + Tcp *TcpScaleRule `json:"tcp,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_scaleruleauth.go b/resource-manager/containerapps/2025-01-01/containerapps/model_scaleruleauth.go new file mode 100644 index 00000000000..46e5a92ad03 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_scaleruleauth.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRuleAuth struct { + SecretRef *string `json:"secretRef,omitempty"` + TriggerParameter *string `json:"triggerParameter,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_secret.go b/resource-manager/containerapps/2025-01-01/containerapps/model_secret.go new file mode 100644 index 00000000000..61a516725a0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_secret.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Secret struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_secretscollection.go b/resource-manager/containerapps/2025-01-01/containerapps/model_secretscollection.go new file mode 100644 index 00000000000..5244f0aabe7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_secretscollection.go @@ -0,0 +1,8 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretsCollection struct { + Value []ContainerAppSecret `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_secretvolumeitem.go b/resource-manager/containerapps/2025-01-01/containerapps/model_secretvolumeitem.go new file mode 100644 index 00000000000..09096efbdd0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_secretvolumeitem.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretVolumeItem struct { + Path *string `json:"path,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_service.go b/resource-manager/containerapps/2025-01-01/containerapps/model_service.go new file mode 100644 index 00000000000..f66b3642bfc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_service.go @@ -0,0 +1,8 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Service struct { + Type string `json:"type"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_servicebind.go b/resource-manager/containerapps/2025-01-01/containerapps/model_servicebind.go new file mode 100644 index 00000000000..29229a27ece --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_servicebind.go @@ -0,0 +1,9 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceBind struct { + Name *string `json:"name,omitempty"` + ServiceId *string `json:"serviceId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_tcpscalerule.go b/resource-manager/containerapps/2025-01-01/containerapps/model_tcpscalerule.go new file mode 100644 index 00000000000..de102218351 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_tcpscalerule.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TcpScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_template.go b/resource-manager/containerapps/2025-01-01/containerapps/model_template.go new file mode 100644 index 00000000000..03f13f07980 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_template.go @@ -0,0 +1,14 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Template struct { + Containers *[]Container `json:"containers,omitempty"` + InitContainers *[]BaseContainer `json:"initContainers,omitempty"` + RevisionSuffix *string `json:"revisionSuffix,omitempty"` + Scale *Scale `json:"scale,omitempty"` + ServiceBinds *[]ServiceBind `json:"serviceBinds,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + Volumes *[]Volume `json:"volumes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_trafficweight.go b/resource-manager/containerapps/2025-01-01/containerapps/model_trafficweight.go new file mode 100644 index 00000000000..63d06f5fdcb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_trafficweight.go @@ -0,0 +1,11 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficWeight struct { + Label *string `json:"label,omitempty"` + LatestRevision *bool `json:"latestRevision,omitempty"` + RevisionName *string `json:"revisionName,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_volume.go b/resource-manager/containerapps/2025-01-01/containerapps/model_volume.go new file mode 100644 index 00000000000..422cdf3ec3d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_volume.go @@ -0,0 +1,12 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Volume struct { + MountOptions *string `json:"mountOptions,omitempty"` + Name *string `json:"name,omitempty"` + Secrets *[]SecretVolumeItem `json:"secrets,omitempty"` + StorageName *string `json:"storageName,omitempty"` + StorageType *StorageType `json:"storageType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/model_volumemount.go b/resource-manager/containerapps/2025-01-01/containerapps/model_volumemount.go new file mode 100644 index 00000000000..c59e9fc682d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/model_volumemount.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VolumeMount struct { + MountPath *string `json:"mountPath,omitempty"` + SubPath *string `json:"subPath,omitempty"` + VolumeName *string `json:"volumeName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerapps/predicates.go b/resource-manager/containerapps/2025-01-01/containerapps/predicates.go new file mode 100644 index 00000000000..2f9822c394b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/predicates.go @@ -0,0 +1,83 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppOperationPredicate struct { + Id *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p ContainerAppOperationPredicate) Matches(input ContainerApp) 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.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type DiagnosticsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DiagnosticsOperationPredicate) Matches(input Diagnostics) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type RevisionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RevisionOperationPredicate) Matches(input Revision) 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/containerapps/2025-01-01/containerapps/version.go b/resource-manager/containerapps/2025-01-01/containerapps/version.go new file mode 100644 index 00000000000..1d1eda637de --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerapps/version.go @@ -0,0 +1,10 @@ +package containerapps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/containerapps/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/README.md b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/README.md new file mode 100644 index 00000000000..a2b561de4e7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsauthconfigs` Documentation + +The `containerappsauthconfigs` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsauthconfigs" +``` + + +### Client Initialization + +```go +client := containerappsauthconfigs.NewContainerAppsAuthConfigsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContainerAppsAuthConfigsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := containerappsauthconfigs.NewAuthConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "authConfigName") + +payload := containerappsauthconfigs.AuthConfig{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsAuthConfigsClient.Delete` + +```go +ctx := context.TODO() +id := containerappsauthconfigs.NewAuthConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "authConfigName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsAuthConfigsClient.Get` + +```go +ctx := context.TODO() +id := containerappsauthconfigs.NewAuthConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "authConfigName") + +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: `ContainerAppsAuthConfigsClient.ListByContainerApp` + +```go +ctx := context.TODO() +id := containerappsauthconfigs.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.ListByContainerApp(ctx, id)` can be used to do batched pagination +items, err := client.ListByContainerAppComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/client.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/client.go new file mode 100644 index 00000000000..b118542a497 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/client.go @@ -0,0 +1,26 @@ +package containerappsauthconfigs + +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 ContainerAppsAuthConfigsClient struct { + Client *resourcemanager.Client +} + +func NewContainerAppsAuthConfigsClientWithBaseURI(sdkApi sdkEnv.Api) (*ContainerAppsAuthConfigsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "containerappsauthconfigs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContainerAppsAuthConfigsClient: %+v", err) + } + + return &ContainerAppsAuthConfigsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/constants.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/constants.go new file mode 100644 index 00000000000..ba7b5c1fe46 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/constants.go @@ -0,0 +1,180 @@ +package containerappsauthconfigs + +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 ClientCredentialMethod string + +const ( + ClientCredentialMethodClientSecretPost ClientCredentialMethod = "ClientSecretPost" +) + +func PossibleValuesForClientCredentialMethod() []string { + return []string{ + string(ClientCredentialMethodClientSecretPost), + } +} + +func (s *ClientCredentialMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientCredentialMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientCredentialMethod(input string) (*ClientCredentialMethod, error) { + vals := map[string]ClientCredentialMethod{ + "clientsecretpost": ClientCredentialMethodClientSecretPost, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientCredentialMethod(input) + return &out, nil +} + +type CookieExpirationConvention string + +const ( + CookieExpirationConventionFixedTime CookieExpirationConvention = "FixedTime" + CookieExpirationConventionIdentityProviderDerived CookieExpirationConvention = "IdentityProviderDerived" +) + +func PossibleValuesForCookieExpirationConvention() []string { + return []string{ + string(CookieExpirationConventionFixedTime), + string(CookieExpirationConventionIdentityProviderDerived), + } +} + +func (s *CookieExpirationConvention) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCookieExpirationConvention(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCookieExpirationConvention(input string) (*CookieExpirationConvention, error) { + vals := map[string]CookieExpirationConvention{ + "fixedtime": CookieExpirationConventionFixedTime, + "identityproviderderived": CookieExpirationConventionIdentityProviderDerived, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CookieExpirationConvention(input) + return &out, nil +} + +type ForwardProxyConvention string + +const ( + ForwardProxyConventionCustom ForwardProxyConvention = "Custom" + ForwardProxyConventionNoProxy ForwardProxyConvention = "NoProxy" + ForwardProxyConventionStandard ForwardProxyConvention = "Standard" +) + +func PossibleValuesForForwardProxyConvention() []string { + return []string{ + string(ForwardProxyConventionCustom), + string(ForwardProxyConventionNoProxy), + string(ForwardProxyConventionStandard), + } +} + +func (s *ForwardProxyConvention) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForwardProxyConvention(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForwardProxyConvention(input string) (*ForwardProxyConvention, error) { + vals := map[string]ForwardProxyConvention{ + "custom": ForwardProxyConventionCustom, + "noproxy": ForwardProxyConventionNoProxy, + "standard": ForwardProxyConventionStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForwardProxyConvention(input) + return &out, nil +} + +type UnauthenticatedClientActionV2 string + +const ( + UnauthenticatedClientActionV2AllowAnonymous UnauthenticatedClientActionV2 = "AllowAnonymous" + UnauthenticatedClientActionV2RedirectToLoginPage UnauthenticatedClientActionV2 = "RedirectToLoginPage" + UnauthenticatedClientActionV2ReturnFourZeroOne UnauthenticatedClientActionV2 = "Return401" + UnauthenticatedClientActionV2ReturnFourZeroThree UnauthenticatedClientActionV2 = "Return403" +) + +func PossibleValuesForUnauthenticatedClientActionV2() []string { + return []string{ + string(UnauthenticatedClientActionV2AllowAnonymous), + string(UnauthenticatedClientActionV2RedirectToLoginPage), + string(UnauthenticatedClientActionV2ReturnFourZeroOne), + string(UnauthenticatedClientActionV2ReturnFourZeroThree), + } +} + +func (s *UnauthenticatedClientActionV2) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUnauthenticatedClientActionV2(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUnauthenticatedClientActionV2(input string) (*UnauthenticatedClientActionV2, error) { + vals := map[string]UnauthenticatedClientActionV2{ + "allowanonymous": UnauthenticatedClientActionV2AllowAnonymous, + "redirecttologinpage": UnauthenticatedClientActionV2RedirectToLoginPage, + "return401": UnauthenticatedClientActionV2ReturnFourZeroOne, + "return403": UnauthenticatedClientActionV2ReturnFourZeroThree, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UnauthenticatedClientActionV2(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig.go new file mode 100644 index 00000000000..dc5df54f390 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig.go @@ -0,0 +1,139 @@ +package containerappsauthconfigs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AuthConfigId{}) +} + +var _ resourceids.ResourceId = &AuthConfigId{} + +// AuthConfigId is a struct representing the Resource ID for a Auth Config +type AuthConfigId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + AuthConfigName string +} + +// NewAuthConfigID returns a new AuthConfigId struct +func NewAuthConfigID(subscriptionId string, resourceGroupName string, containerAppName string, authConfigName string) AuthConfigId { + return AuthConfigId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + AuthConfigName: authConfigName, + } +} + +// ParseAuthConfigID parses 'input' into a AuthConfigId +func ParseAuthConfigID(input string) (*AuthConfigId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthConfigId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthConfigId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAuthConfigIDInsensitively parses 'input' case-insensitively into a AuthConfigId +// note: this method should only be used for API response data and not user input +func ParseAuthConfigIDInsensitively(input string) (*AuthConfigId, error) { + parser := resourceids.NewParserFromResourceIdType(&AuthConfigId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AuthConfigId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AuthConfigId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.AuthConfigName, ok = input.Parsed["authConfigName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "authConfigName", input) + } + + return nil +} + +// ValidateAuthConfigID checks that 'input' can be parsed as a Auth Config ID +func ValidateAuthConfigID(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 := ParseAuthConfigID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Auth Config ID +func (id AuthConfigId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/authConfigs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.AuthConfigName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Auth Config ID +func (id AuthConfigId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticAuthConfigs", "authConfigs", "authConfigs"), + resourceids.UserSpecifiedSegment("authConfigName", "authConfigName"), + } +} + +// String returns a human-readable description of this Auth Config ID +func (id AuthConfigId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Auth Config Name: %q", id.AuthConfigName), + } + return fmt.Sprintf("Auth Config (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig_test.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig_test.go new file mode 100644 index 00000000000..3b185598bfd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_authconfig_test.go @@ -0,0 +1,327 @@ +package containerappsauthconfigs + +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 = &AuthConfigId{} + +func TestNewAuthConfigID(t *testing.T) { + id := NewAuthConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "authConfigName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.AuthConfigName != "authConfigName" { + t.Fatalf("Expected %q but got %q for Segment 'AuthConfigName'", id.AuthConfigName, "authConfigName") + } +} + +func TestFormatAuthConfigID(t *testing.T) { + actual := NewAuthConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "authConfigName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs/authConfigName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAuthConfigID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthConfigId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs/authConfigName", + Expected: &AuthConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + AuthConfigName: "authConfigName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs/authConfigName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthConfigID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.AuthConfigName != v.Expected.AuthConfigName { + t.Fatalf("Expected %q but got %q for AuthConfigName", v.Expected.AuthConfigName, actual.AuthConfigName) + } + + } +} + +func TestParseAuthConfigIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AuthConfigId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/aUtHcOnFiGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs/authConfigName", + Expected: &AuthConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + AuthConfigName: "authConfigName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/authConfigs/authConfigName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/aUtHcOnFiGs/aUtHcOnFiGnAmE", + Expected: &AuthConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + AuthConfigName: "aUtHcOnFiGnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/aUtHcOnFiGs/aUtHcOnFiGnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAuthConfigIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.AuthConfigName != v.Expected.AuthConfigName { + t.Fatalf("Expected %q but got %q for AuthConfigName", v.Expected.AuthConfigName, actual.AuthConfigName) + } + + } +} + +func TestSegmentsForAuthConfigId(t *testing.T) { + segments := AuthConfigId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AuthConfigId 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/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp.go new file mode 100644 index 00000000000..c9f7dbaa65b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp.go @@ -0,0 +1,130 @@ +package containerappsauthconfigs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppId{}) +} + +var _ resourceids.ResourceId = &ContainerAppId{} + +// ContainerAppId is a struct representing the Resource ID for a Container App +type ContainerAppId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string +} + +// NewContainerAppID returns a new ContainerAppId struct +func NewContainerAppID(subscriptionId string, resourceGroupName string, containerAppName string) ContainerAppId { + return ContainerAppId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + } +} + +// ParseContainerAppID parses 'input' into a ContainerAppId +func ParseContainerAppID(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppIDInsensitively parses 'input' case-insensitively into a ContainerAppId +// note: this method should only be used for API response data and not user input +func ParseContainerAppIDInsensitively(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + return nil +} + +// ValidateContainerAppID checks that 'input' can be parsed as a Container App ID +func ValidateContainerAppID(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 := ParseContainerAppID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App ID +func (id ContainerAppId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App ID +func (id ContainerAppId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + } +} + +// String returns a human-readable description of this Container App ID +func (id ContainerAppId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + } + return fmt.Sprintf("Container App (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp_test.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp_test.go new file mode 100644 index 00000000000..34ee6ee7456 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/id_containerapp_test.go @@ -0,0 +1,282 @@ +package containerappsauthconfigs + +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 = &ContainerAppId{} + +func TestNewContainerAppID(t *testing.T) { + id := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } +} + +func TestFormatContainerAppID(t *testing.T) { + actual := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestParseContainerAppIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestSegmentsForContainerAppId(t *testing.T) { + segments := ContainerAppId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppId 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/containerapps/2025-01-01/containerappsauthconfigs/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_createorupdate.go new file mode 100644 index 00000000000..8a74d6915bc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_createorupdate.go @@ -0,0 +1,57 @@ +package containerappsauthconfigs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AuthConfig +} + +// CreateOrUpdate ... +func (c ContainerAppsAuthConfigsClient) CreateOrUpdate(ctx context.Context, id AuthConfigId, input AuthConfig) (result CreateOrUpdateOperationResponse, 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 AuthConfig + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_delete.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_delete.go new file mode 100644 index 00000000000..de31f707aba --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_delete.go @@ -0,0 +1,47 @@ +package containerappsauthconfigs + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ContainerAppsAuthConfigsClient) Delete(ctx context.Context, id AuthConfigId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_get.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_get.go new file mode 100644 index 00000000000..3fd93ca8c3a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_get.go @@ -0,0 +1,53 @@ +package containerappsauthconfigs + +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 *AuthConfig +} + +// Get ... +func (c ContainerAppsAuthConfigsClient) Get(ctx context.Context, id AuthConfigId) (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 AuthConfig + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_listbycontainerapp.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_listbycontainerapp.go new file mode 100644 index 00000000000..c096c07c5d5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/method_listbycontainerapp.go @@ -0,0 +1,105 @@ +package containerappsauthconfigs + +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 ListByContainerAppOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AuthConfig +} + +type ListByContainerAppCompleteResult struct { + LatestHttpResponse *http.Response + Items []AuthConfig +} + +type ListByContainerAppCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByContainerAppCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByContainerApp ... +func (c ContainerAppsAuthConfigsClient) ListByContainerApp(ctx context.Context, id ContainerAppId) (result ListByContainerAppOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByContainerAppCustomPager{}, + Path: fmt.Sprintf("%s/authConfigs", 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 *[]AuthConfig `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByContainerAppComplete retrieves all the results into a single object +func (c ContainerAppsAuthConfigsClient) ListByContainerAppComplete(ctx context.Context, id ContainerAppId) (ListByContainerAppCompleteResult, error) { + return c.ListByContainerAppCompleteMatchingPredicate(ctx, id, AuthConfigOperationPredicate{}) +} + +// ListByContainerAppCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsAuthConfigsClient) ListByContainerAppCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, predicate AuthConfigOperationPredicate) (result ListByContainerAppCompleteResult, err error) { + items := make([]AuthConfig, 0) + + resp, err := c.ListByContainerApp(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByContainerAppCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedaudiencesvalidation.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedaudiencesvalidation.go new file mode 100644 index 00000000000..594711ca638 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedaudiencesvalidation.go @@ -0,0 +1,8 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllowedAudiencesValidation struct { + AllowedAudiences *[]string `json:"allowedAudiences,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedprincipals.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedprincipals.go new file mode 100644 index 00000000000..f688f3136ef --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_allowedprincipals.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllowedPrincipals struct { + Groups *[]string `json:"groups,omitempty"` + Identities *[]string `json:"identities,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_apple.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_apple.go new file mode 100644 index 00000000000..342215d6cc3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_apple.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Apple struct { + Enabled *bool `json:"enabled,omitempty"` + Login *LoginScopes `json:"login,omitempty"` + Registration *AppleRegistration `json:"registration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appleregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appleregistration.go new file mode 100644 index 00000000000..f4313788047 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appleregistration.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AppleRegistration struct { + ClientId *string `json:"clientId,omitempty"` + ClientSecretSettingName *string `json:"clientSecretSettingName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appregistration.go new file mode 100644 index 00000000000..6709a45a29c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_appregistration.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AppRegistration struct { + AppId *string `json:"appId,omitempty"` + AppSecretSettingName *string `json:"appSecretSettingName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfig.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfig.go new file mode 100644 index 00000000000..de04bb26a5a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfig.go @@ -0,0 +1,16 @@ +package containerappsauthconfigs + +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 AuthConfig struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AuthConfigProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfigproperties.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfigproperties.go new file mode 100644 index 00000000000..bf35c45b412 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authconfigproperties.go @@ -0,0 +1,13 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthConfigProperties struct { + EncryptionSettings *EncryptionSettings `json:"encryptionSettings,omitempty"` + GlobalValidation *GlobalValidation `json:"globalValidation,omitempty"` + HTTPSettings *HTTPSettings `json:"httpSettings,omitempty"` + IdentityProviders *IdentityProviders `json:"identityProviders,omitempty"` + Login *Login `json:"login,omitempty"` + Platform *AuthPlatform `json:"platform,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authplatform.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authplatform.go new file mode 100644 index 00000000000..78d033cd9f3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_authplatform.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthPlatform struct { + Enabled *bool `json:"enabled,omitempty"` + RuntimeVersion *string `json:"runtimeVersion,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectory.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectory.go new file mode 100644 index 00000000000..8a14182dc4a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectory.go @@ -0,0 +1,12 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureActiveDirectory struct { + Enabled *bool `json:"enabled,omitempty"` + IsAutoProvisioned *bool `json:"isAutoProvisioned,omitempty"` + Login *AzureActiveDirectoryLogin `json:"login,omitempty"` + Registration *AzureActiveDirectoryRegistration `json:"registration,omitempty"` + Validation *AzureActiveDirectoryValidation `json:"validation,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectorylogin.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectorylogin.go new file mode 100644 index 00000000000..569680f2c2b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectorylogin.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureActiveDirectoryLogin struct { + DisableWWWAuthenticate *bool `json:"disableWWWAuthenticate,omitempty"` + LoginParameters *[]string `json:"loginParameters,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryregistration.go new file mode 100644 index 00000000000..8e7c8c65bad --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryregistration.go @@ -0,0 +1,13 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureActiveDirectoryRegistration struct { + ClientId *string `json:"clientId,omitempty"` + ClientSecretCertificateIssuer *string `json:"clientSecretCertificateIssuer,omitempty"` + ClientSecretCertificateSubjectAlternativeName *string `json:"clientSecretCertificateSubjectAlternativeName,omitempty"` + ClientSecretCertificateThumbprint *string `json:"clientSecretCertificateThumbprint,omitempty"` + ClientSecretSettingName *string `json:"clientSecretSettingName,omitempty"` + OpenIdIssuer *string `json:"openIdIssuer,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryvalidation.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryvalidation.go new file mode 100644 index 00000000000..432f84b385a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azureactivedirectoryvalidation.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureActiveDirectoryValidation struct { + AllowedAudiences *[]string `json:"allowedAudiences,omitempty"` + DefaultAuthorizationPolicy *DefaultAuthorizationPolicy `json:"defaultAuthorizationPolicy,omitempty"` + JwtClaimChecks *JwtClaimChecks `json:"jwtClaimChecks,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebapps.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebapps.go new file mode 100644 index 00000000000..c59e25c28b7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebapps.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStaticWebApps struct { + Enabled *bool `json:"enabled,omitempty"` + Registration *AzureStaticWebAppsRegistration `json:"registration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebappsregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebappsregistration.go new file mode 100644 index 00000000000..a0b15a30098 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_azurestaticwebappsregistration.go @@ -0,0 +1,8 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureStaticWebAppsRegistration struct { + ClientId *string `json:"clientId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_blobstoragetokenstore.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_blobstoragetokenstore.go new file mode 100644 index 00000000000..4f3644b64d9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_blobstoragetokenstore.go @@ -0,0 +1,8 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BlobStorageTokenStore struct { + SasURLSettingName string `json:"sasUrlSettingName"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_clientregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_clientregistration.go new file mode 100644 index 00000000000..cf09dea7cde --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_clientregistration.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientRegistration struct { + ClientId *string `json:"clientId,omitempty"` + ClientSecretSettingName *string `json:"clientSecretSettingName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_cookieexpiration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_cookieexpiration.go new file mode 100644 index 00000000000..7121c522a07 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_cookieexpiration.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CookieExpiration struct { + Convention *CookieExpirationConvention `json:"convention,omitempty"` + TimeToExpiration *string `json:"timeToExpiration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_customopenidconnectprovider.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_customopenidconnectprovider.go new file mode 100644 index 00000000000..f8afc83eba5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_customopenidconnectprovider.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomOpenIdConnectProvider struct { + Enabled *bool `json:"enabled,omitempty"` + Login *OpenIdConnectLogin `json:"login,omitempty"` + Registration *OpenIdConnectRegistration `json:"registration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_defaultauthorizationpolicy.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_defaultauthorizationpolicy.go new file mode 100644 index 00000000000..0364e6bba4d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_defaultauthorizationpolicy.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DefaultAuthorizationPolicy struct { + AllowedApplications *[]string `json:"allowedApplications,omitempty"` + AllowedPrincipals *AllowedPrincipals `json:"allowedPrincipals,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_encryptionsettings.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_encryptionsettings.go new file mode 100644 index 00000000000..775aa1b9fca --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_encryptionsettings.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionSettings struct { + ContainerAppAuthEncryptionSecretName *string `json:"containerAppAuthEncryptionSecretName,omitempty"` + ContainerAppAuthSigningSecretName *string `json:"containerAppAuthSigningSecretName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_facebook.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_facebook.go new file mode 100644 index 00000000000..d354c73120e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_facebook.go @@ -0,0 +1,11 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Facebook struct { + Enabled *bool `json:"enabled,omitempty"` + GraphApiVersion *string `json:"graphApiVersion,omitempty"` + Login *LoginScopes `json:"login,omitempty"` + Registration *AppRegistration `json:"registration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_forwardproxy.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_forwardproxy.go new file mode 100644 index 00000000000..15f8944d7d0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_forwardproxy.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForwardProxy struct { + Convention *ForwardProxyConvention `json:"convention,omitempty"` + CustomHostHeaderName *string `json:"customHostHeaderName,omitempty"` + CustomProtoHeaderName *string `json:"customProtoHeaderName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_github.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_github.go new file mode 100644 index 00000000000..d63088b7c68 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_github.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHub struct { + Enabled *bool `json:"enabled,omitempty"` + Login *LoginScopes `json:"login,omitempty"` + Registration *ClientRegistration `json:"registration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_globalvalidation.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_globalvalidation.go new file mode 100644 index 00000000000..f2b4e6a7bbf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_globalvalidation.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GlobalValidation struct { + ExcludedPaths *[]string `json:"excludedPaths,omitempty"` + RedirectToProvider *string `json:"redirectToProvider,omitempty"` + UnauthenticatedClientAction *UnauthenticatedClientActionV2 `json:"unauthenticatedClientAction,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_google.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_google.go new file mode 100644 index 00000000000..6df90407ba4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_google.go @@ -0,0 +1,11 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Google struct { + Enabled *bool `json:"enabled,omitempty"` + Login *LoginScopes `json:"login,omitempty"` + Registration *ClientRegistration `json:"registration,omitempty"` + Validation *AllowedAudiencesValidation `json:"validation,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettings.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettings.go new file mode 100644 index 00000000000..b12578d6a4f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettings.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPSettings struct { + ForwardProxy *ForwardProxy `json:"forwardProxy,omitempty"` + RequireHTTPS *bool `json:"requireHttps,omitempty"` + Routes *HTTPSettingsRoutes `json:"routes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettingsroutes.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettingsroutes.go new file mode 100644 index 00000000000..77768a0aaa3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_httpsettingsroutes.go @@ -0,0 +1,8 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPSettingsRoutes struct { + ApiPrefix *string `json:"apiPrefix,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_identityproviders.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_identityproviders.go new file mode 100644 index 00000000000..3ea9ba760f8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_identityproviders.go @@ -0,0 +1,15 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProviders struct { + Apple *Apple `json:"apple,omitempty"` + AzureActiveDirectory *AzureActiveDirectory `json:"azureActiveDirectory,omitempty"` + AzureStaticWebApps *AzureStaticWebApps `json:"azureStaticWebApps,omitempty"` + CustomOpenIdConnectProviders *map[string]CustomOpenIdConnectProvider `json:"customOpenIdConnectProviders,omitempty"` + Facebook *Facebook `json:"facebook,omitempty"` + GitHub *GitHub `json:"gitHub,omitempty"` + Google *Google `json:"google,omitempty"` + Twitter *Twitter `json:"twitter,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_jwtclaimchecks.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_jwtclaimchecks.go new file mode 100644 index 00000000000..dc79e4613dd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_jwtclaimchecks.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JwtClaimChecks struct { + AllowedClientApplications *[]string `json:"allowedClientApplications,omitempty"` + AllowedGroups *[]string `json:"allowedGroups,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_login.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_login.go new file mode 100644 index 00000000000..c2abbcaeb5b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_login.go @@ -0,0 +1,13 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Login struct { + AllowedExternalRedirectURLs *[]string `json:"allowedExternalRedirectUrls,omitempty"` + CookieExpiration *CookieExpiration `json:"cookieExpiration,omitempty"` + Nonce *Nonce `json:"nonce,omitempty"` + PreserveURLFragmentsForLogins *bool `json:"preserveUrlFragmentsForLogins,omitempty"` + Routes *LoginRoutes `json:"routes,omitempty"` + TokenStore *TokenStore `json:"tokenStore,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginroutes.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginroutes.go new file mode 100644 index 00000000000..3bc35729049 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginroutes.go @@ -0,0 +1,8 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoginRoutes struct { + LogoutEndpoint *string `json:"logoutEndpoint,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginscopes.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginscopes.go new file mode 100644 index 00000000000..12f3aa5d541 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_loginscopes.go @@ -0,0 +1,8 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoginScopes struct { + Scopes *[]string `json:"scopes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_nonce.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_nonce.go new file mode 100644 index 00000000000..ea13ee897e5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_nonce.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Nonce struct { + NonceExpirationInterval *string `json:"nonceExpirationInterval,omitempty"` + ValidateNonce *bool `json:"validateNonce,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectclientcredential.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectclientcredential.go new file mode 100644 index 00000000000..07860f39082 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectclientcredential.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdConnectClientCredential struct { + ClientSecretSettingName *string `json:"clientSecretSettingName,omitempty"` + Method *ClientCredentialMethod `json:"method,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectconfig.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectconfig.go new file mode 100644 index 00000000000..d99c17ee8cf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectconfig.go @@ -0,0 +1,12 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdConnectConfig struct { + AuthorizationEndpoint *string `json:"authorizationEndpoint,omitempty"` + CertificationUri *string `json:"certificationUri,omitempty"` + Issuer *string `json:"issuer,omitempty"` + TokenEndpoint *string `json:"tokenEndpoint,omitempty"` + WellKnownOpenIdConfiguration *string `json:"wellKnownOpenIdConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectlogin.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectlogin.go new file mode 100644 index 00000000000..d5a6d880ae4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectlogin.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdConnectLogin struct { + NameClaimType *string `json:"nameClaimType,omitempty"` + Scopes *[]string `json:"scopes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectregistration.go new file mode 100644 index 00000000000..178e8a393bc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_openidconnectregistration.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OpenIdConnectRegistration struct { + ClientCredential *OpenIdConnectClientCredential `json:"clientCredential,omitempty"` + ClientId *string `json:"clientId,omitempty"` + OpenIdConnectConfiguration *OpenIdConnectConfig `json:"openIdConnectConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_tokenstore.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_tokenstore.go new file mode 100644 index 00000000000..61bb96269fe --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_tokenstore.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenStore struct { + AzureBlobStorage *BlobStorageTokenStore `json:"azureBlobStorage,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + TokenRefreshExtensionHours *float64 `json:"tokenRefreshExtensionHours,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitter.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitter.go new file mode 100644 index 00000000000..86411693f47 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitter.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Twitter struct { + Enabled *bool `json:"enabled,omitempty"` + Registration *TwitterRegistration `json:"registration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitterregistration.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitterregistration.go new file mode 100644 index 00000000000..9363c659750 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/model_twitterregistration.go @@ -0,0 +1,9 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TwitterRegistration struct { + ConsumerKey *string `json:"consumerKey,omitempty"` + ConsumerSecretSettingName *string `json:"consumerSecretSettingName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/predicates.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/predicates.go new file mode 100644 index 00000000000..588139a3fbb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/predicates.go @@ -0,0 +1,27 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthConfigOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AuthConfigOperationPredicate) Matches(input AuthConfig) 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/containerapps/2025-01-01/containerappsauthconfigs/version.go b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/version.go new file mode 100644 index 00000000000..be3e895ba8f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsauthconfigs/version.go @@ -0,0 +1,10 @@ +package containerappsauthconfigs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/containerappsauthconfigs/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/README.md b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/README.md new file mode 100644 index 00000000000..7b276848124 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas` Documentation + +The `containerappsrevisionreplicas` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas" +``` + + +### Client Initialization + +```go +client := containerappsrevisionreplicas.NewContainerAppsRevisionReplicasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContainerAppsRevisionReplicasClient.GetReplica` + +```go +ctx := context.TODO() +id := containerappsrevisionreplicas.NewReplicaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName", "replicaName") + +read, err := client.GetReplica(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsRevisionReplicasClient.ListReplicas` + +```go +ctx := context.TODO() +id := containerappsrevisionreplicas.NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.ListReplicas(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/client.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/client.go new file mode 100644 index 00000000000..6948105cc45 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/client.go @@ -0,0 +1,26 @@ +package containerappsrevisionreplicas + +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 ContainerAppsRevisionReplicasClient struct { + Client *resourcemanager.Client +} + +func NewContainerAppsRevisionReplicasClientWithBaseURI(sdkApi sdkEnv.Api) (*ContainerAppsRevisionReplicasClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "containerappsrevisionreplicas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContainerAppsRevisionReplicasClient: %+v", err) + } + + return &ContainerAppsRevisionReplicasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/constants.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/constants.go new file mode 100644 index 00000000000..8c0c5556098 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/constants.go @@ -0,0 +1,98 @@ +package containerappsrevisionreplicas + +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 ContainerAppContainerRunningState string + +const ( + ContainerAppContainerRunningStateRunning ContainerAppContainerRunningState = "Running" + ContainerAppContainerRunningStateTerminated ContainerAppContainerRunningState = "Terminated" + ContainerAppContainerRunningStateWaiting ContainerAppContainerRunningState = "Waiting" +) + +func PossibleValuesForContainerAppContainerRunningState() []string { + return []string{ + string(ContainerAppContainerRunningStateRunning), + string(ContainerAppContainerRunningStateTerminated), + string(ContainerAppContainerRunningStateWaiting), + } +} + +func (s *ContainerAppContainerRunningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerAppContainerRunningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerAppContainerRunningState(input string) (*ContainerAppContainerRunningState, error) { + vals := map[string]ContainerAppContainerRunningState{ + "running": ContainerAppContainerRunningStateRunning, + "terminated": ContainerAppContainerRunningStateTerminated, + "waiting": ContainerAppContainerRunningStateWaiting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerAppContainerRunningState(input) + return &out, nil +} + +type ContainerAppReplicaRunningState string + +const ( + ContainerAppReplicaRunningStateNotRunning ContainerAppReplicaRunningState = "NotRunning" + ContainerAppReplicaRunningStateRunning ContainerAppReplicaRunningState = "Running" + ContainerAppReplicaRunningStateUnknown ContainerAppReplicaRunningState = "Unknown" +) + +func PossibleValuesForContainerAppReplicaRunningState() []string { + return []string{ + string(ContainerAppReplicaRunningStateNotRunning), + string(ContainerAppReplicaRunningStateRunning), + string(ContainerAppReplicaRunningStateUnknown), + } +} + +func (s *ContainerAppReplicaRunningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerAppReplicaRunningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerAppReplicaRunningState(input string) (*ContainerAppReplicaRunningState, error) { + vals := map[string]ContainerAppReplicaRunningState{ + "notrunning": ContainerAppReplicaRunningStateNotRunning, + "running": ContainerAppReplicaRunningStateRunning, + "unknown": ContainerAppReplicaRunningStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerAppReplicaRunningState(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica.go new file mode 100644 index 00000000000..975837cad12 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica.go @@ -0,0 +1,148 @@ +package containerappsrevisionreplicas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ReplicaId{}) +} + +var _ resourceids.ResourceId = &ReplicaId{} + +// ReplicaId is a struct representing the Resource ID for a Replica +type ReplicaId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + RevisionName string + ReplicaName string +} + +// NewReplicaID returns a new ReplicaId struct +func NewReplicaID(subscriptionId string, resourceGroupName string, containerAppName string, revisionName string, replicaName string) ReplicaId { + return ReplicaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + RevisionName: revisionName, + ReplicaName: replicaName, + } +} + +// ParseReplicaID parses 'input' into a ReplicaId +func ParseReplicaID(input string) (*ReplicaId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReplicaIDInsensitively parses 'input' case-insensitively into a ReplicaId +// note: this method should only be used for API response data and not user input +func ParseReplicaIDInsensitively(input string) (*ReplicaId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReplicaId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.RevisionName, ok = input.Parsed["revisionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "revisionName", input) + } + + if id.ReplicaName, ok = input.Parsed["replicaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "replicaName", input) + } + + return nil +} + +// ValidateReplicaID checks that 'input' can be parsed as a Replica ID +func ValidateReplicaID(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 := ParseReplicaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replica ID +func (id ReplicaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/revisions/%s/replicas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.RevisionName, id.ReplicaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replica ID +func (id ReplicaId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticRevisions", "revisions", "revisions"), + resourceids.UserSpecifiedSegment("revisionName", "revisionName"), + resourceids.StaticSegment("staticReplicas", "replicas", "replicas"), + resourceids.UserSpecifiedSegment("replicaName", "replicaName"), + } +} + +// String returns a human-readable description of this Replica ID +func (id ReplicaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Revision Name: %q", id.RevisionName), + fmt.Sprintf("Replica Name: %q", id.ReplicaName), + } + return fmt.Sprintf("Replica (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica_test.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica_test.go new file mode 100644 index 00000000000..d27ad64d60a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_replica_test.go @@ -0,0 +1,372 @@ +package containerappsrevisionreplicas + +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 = &ReplicaId{} + +func TestNewReplicaID(t *testing.T) { + id := NewReplicaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName", "replicaName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.RevisionName != "revisionName" { + t.Fatalf("Expected %q but got %q for Segment 'RevisionName'", id.RevisionName, "revisionName") + } + + if id.ReplicaName != "replicaName" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicaName'", id.ReplicaName, "replicaName") + } +} + +func TestFormatReplicaID(t *testing.T) { + actual := NewReplicaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName", "replicaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas/replicaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicaId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas/replicaName", + Expected: &ReplicaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + ReplicaName: "replicaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas/replicaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicaID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + if actual.ReplicaName != v.Expected.ReplicaName { + t.Fatalf("Expected %q but got %q for ReplicaName", v.Expected.ReplicaName, actual.ReplicaName) + } + + } +} + +func TestParseReplicaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicaId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE/rEpLiCaS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas/replicaName", + Expected: &ReplicaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + ReplicaName: "replicaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/replicas/replicaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE/rEpLiCaS/rEpLiCaNaMe", + Expected: &ReplicaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + RevisionName: "rEvIsIoNnAmE", + ReplicaName: "rEpLiCaNaMe", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE/rEpLiCaS/rEpLiCaNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicaIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + if actual.ReplicaName != v.Expected.ReplicaName { + t.Fatalf("Expected %q but got %q for ReplicaName", v.Expected.ReplicaName, actual.ReplicaName) + } + + } +} + +func TestSegmentsForReplicaId(t *testing.T) { + segments := ReplicaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicaId 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/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision.go new file mode 100644 index 00000000000..456072b418e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision.go @@ -0,0 +1,139 @@ +package containerappsrevisionreplicas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RevisionId{}) +} + +var _ resourceids.ResourceId = &RevisionId{} + +// RevisionId is a struct representing the Resource ID for a Revision +type RevisionId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + RevisionName string +} + +// NewRevisionID returns a new RevisionId struct +func NewRevisionID(subscriptionId string, resourceGroupName string, containerAppName string, revisionName string) RevisionId { + return RevisionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + RevisionName: revisionName, + } +} + +// ParseRevisionID parses 'input' into a RevisionId +func ParseRevisionID(input string) (*RevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRevisionIDInsensitively parses 'input' case-insensitively into a RevisionId +// note: this method should only be used for API response data and not user input +func ParseRevisionIDInsensitively(input string) (*RevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RevisionId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.RevisionName, ok = input.Parsed["revisionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "revisionName", input) + } + + return nil +} + +// ValidateRevisionID checks that 'input' can be parsed as a Revision ID +func ValidateRevisionID(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 := ParseRevisionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Revision ID +func (id RevisionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/revisions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.RevisionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Revision ID +func (id RevisionId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticRevisions", "revisions", "revisions"), + resourceids.UserSpecifiedSegment("revisionName", "revisionName"), + } +} + +// String returns a human-readable description of this Revision ID +func (id RevisionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Revision Name: %q", id.RevisionName), + } + return fmt.Sprintf("Revision (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision_test.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision_test.go new file mode 100644 index 00000000000..af1f6ca7d3d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/id_revision_test.go @@ -0,0 +1,327 @@ +package containerappsrevisionreplicas + +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 = &RevisionId{} + +func TestNewRevisionID(t *testing.T) { + id := NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.RevisionName != "revisionName" { + t.Fatalf("Expected %q but got %q for Segment 'RevisionName'", id.RevisionName, "revisionName") + } +} + +func TestFormatRevisionID(t *testing.T) { + actual := NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRevisionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName", + Expected: &RevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestParseRevisionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName", + Expected: &RevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE", + Expected: &RevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + RevisionName: "rEvIsIoNnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestSegmentsForRevisionId(t *testing.T) { + segments := RevisionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RevisionId 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/containerapps/2025-01-01/containerappsrevisionreplicas/method_getreplica.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_getreplica.go new file mode 100644 index 00000000000..9e4b91ade70 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_getreplica.go @@ -0,0 +1,53 @@ +package containerappsrevisionreplicas + +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 GetReplicaOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Replica +} + +// GetReplica ... +func (c ContainerAppsRevisionReplicasClient) GetReplica(ctx context.Context, id ReplicaId) (result GetReplicaOperationResponse, 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 Replica + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_listreplicas.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_listreplicas.go new file mode 100644 index 00000000000..2e6ffdcf031 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/method_listreplicas.go @@ -0,0 +1,54 @@ +package containerappsrevisionreplicas + +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 ListReplicasOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ReplicaCollection +} + +// ListReplicas ... +func (c ContainerAppsRevisionReplicasClient) ListReplicas(ctx context.Context, id RevisionId) (result ListReplicasOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/replicas", 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 ReplicaCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replica.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replica.go new file mode 100644 index 00000000000..9c16392147d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replica.go @@ -0,0 +1,16 @@ +package containerappsrevisionreplicas + +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 Replica struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicaProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacollection.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacollection.go new file mode 100644 index 00000000000..89102c20ef8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacollection.go @@ -0,0 +1,8 @@ +package containerappsrevisionreplicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicaCollection struct { + Value []Replica `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacontainer.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacontainer.go new file mode 100644 index 00000000000..65f98712252 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicacontainer.go @@ -0,0 +1,16 @@ +package containerappsrevisionreplicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicaContainer struct { + ContainerId *string `json:"containerId,omitempty"` + ExecEndpoint *string `json:"execEndpoint,omitempty"` + LogStreamEndpoint *string `json:"logStreamEndpoint,omitempty"` + Name *string `json:"name,omitempty"` + Ready *bool `json:"ready,omitempty"` + RestartCount *int64 `json:"restartCount,omitempty"` + RunningState *ContainerAppContainerRunningState `json:"runningState,omitempty"` + RunningStateDetails *string `json:"runningStateDetails,omitempty"` + Started *bool `json:"started,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicaproperties.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicaproperties.go new file mode 100644 index 00000000000..46fd7615b76 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/model_replicaproperties.go @@ -0,0 +1,30 @@ +package containerappsrevisionreplicas + +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 ReplicaProperties struct { + Containers *[]ReplicaContainer `json:"containers,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + InitContainers *[]ReplicaContainer `json:"initContainers,omitempty"` + RunningState *ContainerAppReplicaRunningState `json:"runningState,omitempty"` + RunningStateDetails *string `json:"runningStateDetails,omitempty"` +} + +func (o *ReplicaProperties) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicaProperties) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/version.go b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/version.go new file mode 100644 index 00000000000..fb1042cbddf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisionreplicas/version.go @@ -0,0 +1,10 @@ +package containerappsrevisionreplicas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/containerappsrevisionreplicas/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/README.md b/resource-manager/containerapps/2025-01-01/containerappsrevisions/README.md new file mode 100644 index 00000000000..204bdba4233 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/README.md @@ -0,0 +1,101 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsrevisions` Documentation + +The `containerappsrevisions` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappsrevisions" +``` + + +### Client Initialization + +```go +client := containerappsrevisions.NewContainerAppsRevisionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContainerAppsRevisionsClient.ActivateRevision` + +```go +ctx := context.TODO() +id := containerappsrevisions.NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.ActivateRevision(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsRevisionsClient.DeactivateRevision` + +```go +ctx := context.TODO() +id := containerappsrevisions.NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.DeactivateRevision(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsRevisionsClient.GetRevision` + +```go +ctx := context.TODO() +id := containerappsrevisions.NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.GetRevision(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContainerAppsRevisionsClient.ListRevisions` + +```go +ctx := context.TODO() +id := containerappsrevisions.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.ListRevisions(ctx, id, containerappsrevisions.DefaultListRevisionsOperationOptions())` can be used to do batched pagination +items, err := client.ListRevisionsComplete(ctx, id, containerappsrevisions.DefaultListRevisionsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ContainerAppsRevisionsClient.RestartRevision` + +```go +ctx := context.TODO() +id := containerappsrevisions.NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.RestartRevision(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/client.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/client.go new file mode 100644 index 00000000000..16764223cb1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/client.go @@ -0,0 +1,26 @@ +package containerappsrevisions + +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 ContainerAppsRevisionsClient struct { + Client *resourcemanager.Client +} + +func NewContainerAppsRevisionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ContainerAppsRevisionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "containerappsrevisions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContainerAppsRevisionsClient: %+v", err) + } + + return &ContainerAppsRevisionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/constants.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/constants.go new file mode 100644 index 00000000000..2e7267249bd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/constants.go @@ -0,0 +1,289 @@ +package containerappsrevisions + +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 RevisionHealthState string + +const ( + RevisionHealthStateHealthy RevisionHealthState = "Healthy" + RevisionHealthStateNone RevisionHealthState = "None" + RevisionHealthStateUnhealthy RevisionHealthState = "Unhealthy" +) + +func PossibleValuesForRevisionHealthState() []string { + return []string{ + string(RevisionHealthStateHealthy), + string(RevisionHealthStateNone), + string(RevisionHealthStateUnhealthy), + } +} + +func (s *RevisionHealthState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionHealthState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionHealthState(input string) (*RevisionHealthState, error) { + vals := map[string]RevisionHealthState{ + "healthy": RevisionHealthStateHealthy, + "none": RevisionHealthStateNone, + "unhealthy": RevisionHealthStateUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionHealthState(input) + return &out, nil +} + +type RevisionProvisioningState string + +const ( + RevisionProvisioningStateDeprovisioned RevisionProvisioningState = "Deprovisioned" + RevisionProvisioningStateDeprovisioning RevisionProvisioningState = "Deprovisioning" + RevisionProvisioningStateFailed RevisionProvisioningState = "Failed" + RevisionProvisioningStateProvisioned RevisionProvisioningState = "Provisioned" + RevisionProvisioningStateProvisioning RevisionProvisioningState = "Provisioning" +) + +func PossibleValuesForRevisionProvisioningState() []string { + return []string{ + string(RevisionProvisioningStateDeprovisioned), + string(RevisionProvisioningStateDeprovisioning), + string(RevisionProvisioningStateFailed), + string(RevisionProvisioningStateProvisioned), + string(RevisionProvisioningStateProvisioning), + } +} + +func (s *RevisionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionProvisioningState(input string) (*RevisionProvisioningState, error) { + vals := map[string]RevisionProvisioningState{ + "deprovisioned": RevisionProvisioningStateDeprovisioned, + "deprovisioning": RevisionProvisioningStateDeprovisioning, + "failed": RevisionProvisioningStateFailed, + "provisioned": RevisionProvisioningStateProvisioned, + "provisioning": RevisionProvisioningStateProvisioning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionProvisioningState(input) + return &out, nil +} + +type RevisionRunningState string + +const ( + RevisionRunningStateDegraded RevisionRunningState = "Degraded" + RevisionRunningStateFailed RevisionRunningState = "Failed" + RevisionRunningStateProcessing RevisionRunningState = "Processing" + RevisionRunningStateRunning RevisionRunningState = "Running" + RevisionRunningStateStopped RevisionRunningState = "Stopped" + RevisionRunningStateUnknown RevisionRunningState = "Unknown" +) + +func PossibleValuesForRevisionRunningState() []string { + return []string{ + string(RevisionRunningStateDegraded), + string(RevisionRunningStateFailed), + string(RevisionRunningStateProcessing), + string(RevisionRunningStateRunning), + string(RevisionRunningStateStopped), + string(RevisionRunningStateUnknown), + } +} + +func (s *RevisionRunningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionRunningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionRunningState(input string) (*RevisionRunningState, error) { + vals := map[string]RevisionRunningState{ + "degraded": RevisionRunningStateDegraded, + "failed": RevisionRunningStateFailed, + "processing": RevisionRunningStateProcessing, + "running": RevisionRunningStateRunning, + "stopped": RevisionRunningStateStopped, + "unknown": RevisionRunningStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionRunningState(input) + return &out, nil +} + +type Scheme string + +const ( + SchemeHTTP Scheme = "HTTP" + SchemeHTTPS Scheme = "HTTPS" +) + +func PossibleValuesForScheme() []string { + return []string{ + string(SchemeHTTP), + string(SchemeHTTPS), + } +} + +func (s *Scheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheme(input string) (*Scheme, error) { + vals := map[string]Scheme{ + "http": SchemeHTTP, + "https": SchemeHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Scheme(input) + return &out, nil +} + +type StorageType string + +const ( + StorageTypeAzureFile StorageType = "AzureFile" + StorageTypeEmptyDir StorageType = "EmptyDir" + StorageTypeNfsAzureFile StorageType = "NfsAzureFile" + StorageTypeSecret StorageType = "Secret" +) + +func PossibleValuesForStorageType() []string { + return []string{ + string(StorageTypeAzureFile), + string(StorageTypeEmptyDir), + string(StorageTypeNfsAzureFile), + string(StorageTypeSecret), + } +} + +func (s *StorageType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageType(input string) (*StorageType, error) { + vals := map[string]StorageType{ + "azurefile": StorageTypeAzureFile, + "emptydir": StorageTypeEmptyDir, + "nfsazurefile": StorageTypeNfsAzureFile, + "secret": StorageTypeSecret, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageType(input) + return &out, nil +} + +type Type string + +const ( + TypeLiveness Type = "Liveness" + TypeReadiness Type = "Readiness" + TypeStartup Type = "Startup" +) + +func PossibleValuesForType() []string { + return []string{ + string(TypeLiveness), + string(TypeReadiness), + string(TypeStartup), + } +} + +func (s *Type) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseType(input string) (*Type, error) { + vals := map[string]Type{ + "liveness": TypeLiveness, + "readiness": TypeReadiness, + "startup": TypeStartup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Type(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp.go new file mode 100644 index 00000000000..02b8ca33474 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp.go @@ -0,0 +1,130 @@ +package containerappsrevisions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppId{}) +} + +var _ resourceids.ResourceId = &ContainerAppId{} + +// ContainerAppId is a struct representing the Resource ID for a Container App +type ContainerAppId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string +} + +// NewContainerAppID returns a new ContainerAppId struct +func NewContainerAppID(subscriptionId string, resourceGroupName string, containerAppName string) ContainerAppId { + return ContainerAppId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + } +} + +// ParseContainerAppID parses 'input' into a ContainerAppId +func ParseContainerAppID(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppIDInsensitively parses 'input' case-insensitively into a ContainerAppId +// note: this method should only be used for API response data and not user input +func ParseContainerAppIDInsensitively(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + return nil +} + +// ValidateContainerAppID checks that 'input' can be parsed as a Container App ID +func ValidateContainerAppID(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 := ParseContainerAppID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App ID +func (id ContainerAppId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App ID +func (id ContainerAppId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + } +} + +// String returns a human-readable description of this Container App ID +func (id ContainerAppId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + } + return fmt.Sprintf("Container App (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp_test.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp_test.go new file mode 100644 index 00000000000..0654df56a64 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_containerapp_test.go @@ -0,0 +1,282 @@ +package containerappsrevisions + +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 = &ContainerAppId{} + +func TestNewContainerAppID(t *testing.T) { + id := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } +} + +func TestFormatContainerAppID(t *testing.T) { + actual := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestParseContainerAppIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestSegmentsForContainerAppId(t *testing.T) { + segments := ContainerAppId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppId 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/containerapps/2025-01-01/containerappsrevisions/id_revision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision.go new file mode 100644 index 00000000000..f11f18aac0f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision.go @@ -0,0 +1,139 @@ +package containerappsrevisions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RevisionId{}) +} + +var _ resourceids.ResourceId = &RevisionId{} + +// RevisionId is a struct representing the Resource ID for a Revision +type RevisionId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + RevisionName string +} + +// NewRevisionID returns a new RevisionId struct +func NewRevisionID(subscriptionId string, resourceGroupName string, containerAppName string, revisionName string) RevisionId { + return RevisionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + RevisionName: revisionName, + } +} + +// ParseRevisionID parses 'input' into a RevisionId +func ParseRevisionID(input string) (*RevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRevisionIDInsensitively parses 'input' case-insensitively into a RevisionId +// note: this method should only be used for API response data and not user input +func ParseRevisionIDInsensitively(input string) (*RevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RevisionId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.RevisionName, ok = input.Parsed["revisionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "revisionName", input) + } + + return nil +} + +// ValidateRevisionID checks that 'input' can be parsed as a Revision ID +func ValidateRevisionID(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 := ParseRevisionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Revision ID +func (id RevisionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/revisions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.RevisionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Revision ID +func (id RevisionId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticRevisions", "revisions", "revisions"), + resourceids.UserSpecifiedSegment("revisionName", "revisionName"), + } +} + +// String returns a human-readable description of this Revision ID +func (id RevisionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Revision Name: %q", id.RevisionName), + } + return fmt.Sprintf("Revision (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision_test.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision_test.go new file mode 100644 index 00000000000..a95bda46481 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/id_revision_test.go @@ -0,0 +1,327 @@ +package containerappsrevisions + +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 = &RevisionId{} + +func TestNewRevisionID(t *testing.T) { + id := NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.RevisionName != "revisionName" { + t.Fatalf("Expected %q but got %q for Segment 'RevisionName'", id.RevisionName, "revisionName") + } +} + +func TestFormatRevisionID(t *testing.T) { + actual := NewRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRevisionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName", + Expected: &RevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestParseRevisionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName", + Expected: &RevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/revisions/revisionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE", + Expected: &RevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + RevisionName: "rEvIsIoNnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/rEvIsIoNs/rEvIsIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestSegmentsForRevisionId(t *testing.T) { + segments := RevisionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RevisionId 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/containerapps/2025-01-01/containerappsrevisions/method_activaterevision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_activaterevision.go new file mode 100644 index 00000000000..1745777ac96 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_activaterevision.go @@ -0,0 +1,47 @@ +package containerappsrevisions + +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 ActivateRevisionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ActivateRevision ... +func (c ContainerAppsRevisionsClient) ActivateRevision(ctx context.Context, id RevisionId) (result ActivateRevisionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/activate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_deactivaterevision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_deactivaterevision.go new file mode 100644 index 00000000000..46be1cffefd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_deactivaterevision.go @@ -0,0 +1,47 @@ +package containerappsrevisions + +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 DeactivateRevisionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DeactivateRevision ... +func (c ContainerAppsRevisionsClient) DeactivateRevision(ctx context.Context, id RevisionId) (result DeactivateRevisionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/deactivate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_getrevision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_getrevision.go new file mode 100644 index 00000000000..5f54d0c3df2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_getrevision.go @@ -0,0 +1,53 @@ +package containerappsrevisions + +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 GetRevisionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Revision +} + +// GetRevision ... +func (c ContainerAppsRevisionsClient) GetRevision(ctx context.Context, id RevisionId) (result GetRevisionOperationResponse, 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 Revision + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_listrevisions.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_listrevisions.go new file mode 100644 index 00000000000..b25d4c9fd53 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_listrevisions.go @@ -0,0 +1,134 @@ +package containerappsrevisions + +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 ListRevisionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Revision +} + +type ListRevisionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Revision +} + +type ListRevisionsOperationOptions struct { + Filter *string +} + +func DefaultListRevisionsOperationOptions() ListRevisionsOperationOptions { + return ListRevisionsOperationOptions{} +} + +func (o ListRevisionsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRevisionsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListRevisionsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListRevisionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListRevisionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListRevisions ... +func (c ContainerAppsRevisionsClient) ListRevisions(ctx context.Context, id ContainerAppId, options ListRevisionsOperationOptions) (result ListRevisionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListRevisionsCustomPager{}, + Path: fmt.Sprintf("%s/revisions", 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 *[]Revision `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRevisionsComplete retrieves all the results into a single object +func (c ContainerAppsRevisionsClient) ListRevisionsComplete(ctx context.Context, id ContainerAppId, options ListRevisionsOperationOptions) (ListRevisionsCompleteResult, error) { + return c.ListRevisionsCompleteMatchingPredicate(ctx, id, options, RevisionOperationPredicate{}) +} + +// ListRevisionsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsRevisionsClient) ListRevisionsCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, options ListRevisionsOperationOptions, predicate RevisionOperationPredicate) (result ListRevisionsCompleteResult, err error) { + items := make([]Revision, 0) + + resp, err := c.ListRevisions(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRevisionsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_restartrevision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_restartrevision.go new file mode 100644 index 00000000000..e228b363490 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/method_restartrevision.go @@ -0,0 +1,47 @@ +package containerappsrevisions + +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 RestartRevisionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RestartRevision ... +func (c ContainerAppsRevisionsClient) RestartRevision(ctx context.Context, id RevisionId) (result RestartRevisionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/restart", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_basecontainer.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_basecontainer.go new file mode 100644 index 00000000000..1826920dd68 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_basecontainer.go @@ -0,0 +1,14 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseContainer struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_container.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_container.go new file mode 100644 index 00000000000..7f1c19ea4b7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_container.go @@ -0,0 +1,15 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Container struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Probes *[]ContainerAppProbe `json:"probes,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobe.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobe.go new file mode 100644 index 00000000000..4ce8a07dffb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobe.go @@ -0,0 +1,16 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbe struct { + FailureThreshold *int64 `json:"failureThreshold,omitempty"` + HTTPGet *ContainerAppProbeHTTPGet `json:"httpGet,omitempty"` + InitialDelaySeconds *int64 `json:"initialDelaySeconds,omitempty"` + PeriodSeconds *int64 `json:"periodSeconds,omitempty"` + SuccessThreshold *int64 `json:"successThreshold,omitempty"` + TcpSocket *ContainerAppProbeTcpSocket `json:"tcpSocket,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"` + Type *Type `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpget.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpget.go new file mode 100644 index 00000000000..d52a1cf5da3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpget.go @@ -0,0 +1,12 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGet struct { + HTTPHeaders *[]ContainerAppProbeHTTPGetHTTPHeadersInlined `json:"httpHeaders,omitempty"` + Host *string `json:"host,omitempty"` + Path *string `json:"path,omitempty"` + Port int64 `json:"port"` + Scheme *Scheme `json:"scheme,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpgethttpheadersinlined.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpgethttpheadersinlined.go new file mode 100644 index 00000000000..d1917e04cf0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobehttpgethttpheadersinlined.go @@ -0,0 +1,9 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGetHTTPHeadersInlined struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobetcpsocket.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobetcpsocket.go new file mode 100644 index 00000000000..c751a9f613a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerappprobetcpsocket.go @@ -0,0 +1,9 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeTcpSocket struct { + Host *string `json:"host,omitempty"` + Port int64 `json:"port"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerresources.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerresources.go new file mode 100644 index 00000000000..3e3de8997a9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_containerresources.go @@ -0,0 +1,10 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerResources struct { + Cpu *float64 `json:"cpu,omitempty"` + EphemeralStorage *string `json:"ephemeralStorage,omitempty"` + Memory *string `json:"memory,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_customscalerule.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_customscalerule.go new file mode 100644 index 00000000000..ad4c5124b9b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_customscalerule.go @@ -0,0 +1,11 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_environmentvar.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_environmentvar.go new file mode 100644 index 00000000000..1b4d78fc7ed --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_environmentvar.go @@ -0,0 +1,10 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentVar struct { + Name *string `json:"name,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_httpscalerule.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_httpscalerule.go new file mode 100644 index 00000000000..b147258bd4e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_httpscalerule.go @@ -0,0 +1,10 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_queuescalerule.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_queuescalerule.go new file mode 100644 index 00000000000..0a2b53148f3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_queuescalerule.go @@ -0,0 +1,12 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueueScaleRule struct { + AccountName *string `json:"accountName,omitempty"` + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + QueueLength *int64 `json:"queueLength,omitempty"` + QueueName *string `json:"queueName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revision.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revision.go new file mode 100644 index 00000000000..3b31b4ca691 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revision.go @@ -0,0 +1,16 @@ +package containerappsrevisions + +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 Revision struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RevisionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revisionproperties.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revisionproperties.go new file mode 100644 index 00000000000..9c61e1f4b45 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_revisionproperties.go @@ -0,0 +1,48 @@ +package containerappsrevisions + +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 RevisionProperties struct { + Active *bool `json:"active,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + HealthState *RevisionHealthState `json:"healthState,omitempty"` + LastActiveTime *string `json:"lastActiveTime,omitempty"` + ProvisioningError *string `json:"provisioningError,omitempty"` + ProvisioningState *RevisionProvisioningState `json:"provisioningState,omitempty"` + Replicas *int64 `json:"replicas,omitempty"` + RunningState *RevisionRunningState `json:"runningState,omitempty"` + Template *Template `json:"template,omitempty"` + TrafficWeight *int64 `json:"trafficWeight,omitempty"` +} + +func (o *RevisionProperties) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RevisionProperties) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} + +func (o *RevisionProperties) GetLastActiveTimeAsTime() (*time.Time, error) { + if o.LastActiveTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastActiveTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RevisionProperties) SetLastActiveTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastActiveTime = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scale.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scale.go new file mode 100644 index 00000000000..ac8e1b940f0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scale.go @@ -0,0 +1,12 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Scale struct { + CooldownPeriod *int64 `json:"cooldownPeriod,omitempty"` + MaxReplicas *int64 `json:"maxReplicas,omitempty"` + MinReplicas *int64 `json:"minReplicas,omitempty"` + PollingInterval *int64 `json:"pollingInterval,omitempty"` + Rules *[]ScaleRule `json:"rules,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scalerule.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scalerule.go new file mode 100644 index 00000000000..c456a55fad2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scalerule.go @@ -0,0 +1,12 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRule struct { + AzureQueue *QueueScaleRule `json:"azureQueue,omitempty"` + Custom *CustomScaleRule `json:"custom,omitempty"` + HTTP *HTTPScaleRule `json:"http,omitempty"` + Name *string `json:"name,omitempty"` + Tcp *TcpScaleRule `json:"tcp,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scaleruleauth.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scaleruleauth.go new file mode 100644 index 00000000000..2135985725a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_scaleruleauth.go @@ -0,0 +1,9 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRuleAuth struct { + SecretRef *string `json:"secretRef,omitempty"` + TriggerParameter *string `json:"triggerParameter,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_secretvolumeitem.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_secretvolumeitem.go new file mode 100644 index 00000000000..507833690ca --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_secretvolumeitem.go @@ -0,0 +1,9 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretVolumeItem struct { + Path *string `json:"path,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_servicebind.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_servicebind.go new file mode 100644 index 00000000000..91f1da05ffd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_servicebind.go @@ -0,0 +1,9 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceBind struct { + Name *string `json:"name,omitempty"` + ServiceId *string `json:"serviceId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_tcpscalerule.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_tcpscalerule.go new file mode 100644 index 00000000000..7c0540ee9c6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_tcpscalerule.go @@ -0,0 +1,10 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TcpScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_template.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_template.go new file mode 100644 index 00000000000..8de2ea6c5bb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_template.go @@ -0,0 +1,14 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Template struct { + Containers *[]Container `json:"containers,omitempty"` + InitContainers *[]BaseContainer `json:"initContainers,omitempty"` + RevisionSuffix *string `json:"revisionSuffix,omitempty"` + Scale *Scale `json:"scale,omitempty"` + ServiceBinds *[]ServiceBind `json:"serviceBinds,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + Volumes *[]Volume `json:"volumes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volume.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volume.go new file mode 100644 index 00000000000..8088c22d516 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volume.go @@ -0,0 +1,12 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Volume struct { + MountOptions *string `json:"mountOptions,omitempty"` + Name *string `json:"name,omitempty"` + Secrets *[]SecretVolumeItem `json:"secrets,omitempty"` + StorageName *string `json:"storageName,omitempty"` + StorageType *StorageType `json:"storageType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volumemount.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volumemount.go new file mode 100644 index 00000000000..2c57b8dd4c1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/model_volumemount.go @@ -0,0 +1,10 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VolumeMount struct { + MountPath *string `json:"mountPath,omitempty"` + SubPath *string `json:"subPath,omitempty"` + VolumeName *string `json:"volumeName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappsrevisions/predicates.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/predicates.go new file mode 100644 index 00000000000..264c9985b0d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/predicates.go @@ -0,0 +1,27 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RevisionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RevisionOperationPredicate) Matches(input Revision) 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/containerapps/2025-01-01/containerappsrevisions/version.go b/resource-manager/containerapps/2025-01-01/containerappsrevisions/version.go new file mode 100644 index 00000000000..7fbc6da6f93 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappsrevisions/version.go @@ -0,0 +1,10 @@ +package containerappsrevisions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/containerappsrevisions/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/README.md b/resource-manager/containerapps/2025-01-01/containerappssessionpools/README.md new file mode 100644 index 00000000000..3d0956653b7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappssessionpools` Documentation + +The `containerappssessionpools` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappssessionpools" +``` + + +### Client Initialization + +```go +client := containerappssessionpools.NewContainerAppsSessionPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContainerAppsSessionPoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := containerappssessionpools.NewSessionPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "sessionPoolName") + +payload := containerappssessionpools.SessionPool{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsSessionPoolsClient.Delete` + +```go +ctx := context.TODO() +id := containerappssessionpools.NewSessionPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "sessionPoolName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsSessionPoolsClient.Get` + +```go +ctx := context.TODO() +id := containerappssessionpools.NewSessionPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "sessionPoolName") + +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: `ContainerAppsSessionPoolsClient.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: `ContainerAppsSessionPoolsClient.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: `ContainerAppsSessionPoolsClient.Update` + +```go +ctx := context.TODO() +id := containerappssessionpools.NewSessionPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "sessionPoolName") + +payload := containerappssessionpools.SessionPoolUpdatableProperties{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/client.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/client.go new file mode 100644 index 00000000000..e5fa83624fd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/client.go @@ -0,0 +1,26 @@ +package containerappssessionpools + +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 ContainerAppsSessionPoolsClient struct { + Client *resourcemanager.Client +} + +func NewContainerAppsSessionPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*ContainerAppsSessionPoolsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "containerappssessionpools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContainerAppsSessionPoolsClient: %+v", err) + } + + return &ContainerAppsSessionPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/constants.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/constants.go new file mode 100644 index 00000000000..6847612be5e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/constants.go @@ -0,0 +1,265 @@ +package containerappssessionpools + +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 ContainerType string + +const ( + ContainerTypeCustomContainer ContainerType = "CustomContainer" + ContainerTypePythonLTS ContainerType = "PythonLTS" +) + +func PossibleValuesForContainerType() []string { + return []string{ + string(ContainerTypeCustomContainer), + string(ContainerTypePythonLTS), + } +} + +func (s *ContainerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerType(input string) (*ContainerType, error) { + vals := map[string]ContainerType{ + "customcontainer": ContainerTypeCustomContainer, + "pythonlts": ContainerTypePythonLTS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerType(input) + return &out, nil +} + +type IdentitySettingsLifeCycle string + +const ( + IdentitySettingsLifeCycleMain IdentitySettingsLifeCycle = "Main" + IdentitySettingsLifeCycleNone IdentitySettingsLifeCycle = "None" +) + +func PossibleValuesForIdentitySettingsLifeCycle() []string { + return []string{ + string(IdentitySettingsLifeCycleMain), + string(IdentitySettingsLifeCycleNone), + } +} + +func (s *IdentitySettingsLifeCycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentitySettingsLifeCycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentitySettingsLifeCycle(input string) (*IdentitySettingsLifeCycle, error) { + vals := map[string]IdentitySettingsLifeCycle{ + "main": IdentitySettingsLifeCycleMain, + "none": IdentitySettingsLifeCycleNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentitySettingsLifeCycle(input) + return &out, nil +} + +type LifecycleType string + +const ( + LifecycleTypeOnContainerExit LifecycleType = "OnContainerExit" + LifecycleTypeTimed LifecycleType = "Timed" +) + +func PossibleValuesForLifecycleType() []string { + return []string{ + string(LifecycleTypeOnContainerExit), + string(LifecycleTypeTimed), + } +} + +func (s *LifecycleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLifecycleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLifecycleType(input string) (*LifecycleType, error) { + vals := map[string]LifecycleType{ + "oncontainerexit": LifecycleTypeOnContainerExit, + "timed": LifecycleTypeTimed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LifecycleType(input) + return &out, nil +} + +type PoolManagementType string + +const ( + PoolManagementTypeDynamic PoolManagementType = "Dynamic" + PoolManagementTypeManual PoolManagementType = "Manual" +) + +func PossibleValuesForPoolManagementType() []string { + return []string{ + string(PoolManagementTypeDynamic), + string(PoolManagementTypeManual), + } +} + +func (s *PoolManagementType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePoolManagementType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePoolManagementType(input string) (*PoolManagementType, error) { + vals := map[string]PoolManagementType{ + "dynamic": PoolManagementTypeDynamic, + "manual": PoolManagementTypeManual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PoolManagementType(input) + return &out, nil +} + +type SessionNetworkStatus string + +const ( + SessionNetworkStatusEgressDisabled SessionNetworkStatus = "EgressDisabled" + SessionNetworkStatusEgressEnabled SessionNetworkStatus = "EgressEnabled" +) + +func PossibleValuesForSessionNetworkStatus() []string { + return []string{ + string(SessionNetworkStatusEgressDisabled), + string(SessionNetworkStatusEgressEnabled), + } +} + +func (s *SessionNetworkStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSessionNetworkStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSessionNetworkStatus(input string) (*SessionNetworkStatus, error) { + vals := map[string]SessionNetworkStatus{ + "egressdisabled": SessionNetworkStatusEgressDisabled, + "egressenabled": SessionNetworkStatusEgressEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionNetworkStatus(input) + return &out, nil +} + +type SessionPoolProvisioningState string + +const ( + SessionPoolProvisioningStateCanceled SessionPoolProvisioningState = "Canceled" + SessionPoolProvisioningStateDeleting SessionPoolProvisioningState = "Deleting" + SessionPoolProvisioningStateFailed SessionPoolProvisioningState = "Failed" + SessionPoolProvisioningStateInProgress SessionPoolProvisioningState = "InProgress" + SessionPoolProvisioningStateSucceeded SessionPoolProvisioningState = "Succeeded" +) + +func PossibleValuesForSessionPoolProvisioningState() []string { + return []string{ + string(SessionPoolProvisioningStateCanceled), + string(SessionPoolProvisioningStateDeleting), + string(SessionPoolProvisioningStateFailed), + string(SessionPoolProvisioningStateInProgress), + string(SessionPoolProvisioningStateSucceeded), + } +} + +func (s *SessionPoolProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSessionPoolProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSessionPoolProvisioningState(input string) (*SessionPoolProvisioningState, error) { + vals := map[string]SessionPoolProvisioningState{ + "canceled": SessionPoolProvisioningStateCanceled, + "deleting": SessionPoolProvisioningStateDeleting, + "failed": SessionPoolProvisioningStateFailed, + "inprogress": SessionPoolProvisioningStateInProgress, + "succeeded": SessionPoolProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SessionPoolProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool.go new file mode 100644 index 00000000000..1a01cf96d3a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool.go @@ -0,0 +1,130 @@ +package containerappssessionpools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SessionPoolId{}) +} + +var _ resourceids.ResourceId = &SessionPoolId{} + +// SessionPoolId is a struct representing the Resource ID for a Session Pool +type SessionPoolId struct { + SubscriptionId string + ResourceGroupName string + SessionPoolName string +} + +// NewSessionPoolID returns a new SessionPoolId struct +func NewSessionPoolID(subscriptionId string, resourceGroupName string, sessionPoolName string) SessionPoolId { + return SessionPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SessionPoolName: sessionPoolName, + } +} + +// ParseSessionPoolID parses 'input' into a SessionPoolId +func ParseSessionPoolID(input string) (*SessionPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SessionPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SessionPoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSessionPoolIDInsensitively parses 'input' case-insensitively into a SessionPoolId +// note: this method should only be used for API response data and not user input +func ParseSessionPoolIDInsensitively(input string) (*SessionPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SessionPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SessionPoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SessionPoolId) 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.SessionPoolName, ok = input.Parsed["sessionPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sessionPoolName", input) + } + + return nil +} + +// ValidateSessionPoolID checks that 'input' can be parsed as a Session Pool ID +func ValidateSessionPoolID(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 := ParseSessionPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Session Pool ID +func (id SessionPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/sessionPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SessionPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Session Pool ID +func (id SessionPoolId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticSessionPools", "sessionPools", "sessionPools"), + resourceids.UserSpecifiedSegment("sessionPoolName", "sessionPoolName"), + } +} + +// String returns a human-readable description of this Session Pool ID +func (id SessionPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Session Pool Name: %q", id.SessionPoolName), + } + return fmt.Sprintf("Session Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool_test.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool_test.go new file mode 100644 index 00000000000..5de9f7ba930 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/id_sessionpool_test.go @@ -0,0 +1,282 @@ +package containerappssessionpools + +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 = &SessionPoolId{} + +func TestNewSessionPoolID(t *testing.T) { + id := NewSessionPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "sessionPoolName") + + 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.SessionPoolName != "sessionPoolName" { + t.Fatalf("Expected %q but got %q for Segment 'SessionPoolName'", id.SessionPoolName, "sessionPoolName") + } +} + +func TestFormatSessionPoolID(t *testing.T) { + actual := NewSessionPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "sessionPoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools/sessionPoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSessionPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionPoolId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools/sessionPoolName", + Expected: &SessionPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SessionPoolName: "sessionPoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools/sessionPoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionPoolID(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.SessionPoolName != v.Expected.SessionPoolName { + t.Fatalf("Expected %q but got %q for SessionPoolName", v.Expected.SessionPoolName, actual.SessionPoolName) + } + + } +} + +func TestParseSessionPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SessionPoolId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/sEsSiOnPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools/sessionPoolName", + Expected: &SessionPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SessionPoolName: "sessionPoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/sessionPools/sessionPoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/sEsSiOnPoOlS/sEsSiOnPoOlNaMe", + Expected: &SessionPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SessionPoolName: "sEsSiOnPoOlNaMe", + }, + }, + { + // 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.aPp/sEsSiOnPoOlS/sEsSiOnPoOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSessionPoolIDInsensitively(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.SessionPoolName != v.Expected.SessionPoolName { + t.Fatalf("Expected %q but got %q for SessionPoolName", v.Expected.SessionPoolName, actual.SessionPoolName) + } + + } +} + +func TestSegmentsForSessionPoolId(t *testing.T) { + segments := SessionPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SessionPoolId 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/containerapps/2025-01-01/containerappssessionpools/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_createorupdate.go new file mode 100644 index 00000000000..26a600fc03e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_createorupdate.go @@ -0,0 +1,75 @@ +package containerappssessionpools + +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 *SessionPool +} + +// CreateOrUpdate ... +func (c ContainerAppsSessionPoolsClient) CreateOrUpdate(ctx context.Context, id SessionPoolId, input SessionPool) (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 ContainerAppsSessionPoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id SessionPoolId, input SessionPool) 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/containerapps/2025-01-01/containerappssessionpools/method_delete.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_delete.go new file mode 100644 index 00000000000..093ce3c4cc7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_delete.go @@ -0,0 +1,70 @@ +package containerappssessionpools + +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 ContainerAppsSessionPoolsClient) Delete(ctx context.Context, id SessionPoolId) (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 ContainerAppsSessionPoolsClient) DeleteThenPoll(ctx context.Context, id SessionPoolId) 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/containerapps/2025-01-01/containerappssessionpools/method_get.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_get.go new file mode 100644 index 00000000000..a07d09c6519 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_get.go @@ -0,0 +1,53 @@ +package containerappssessionpools + +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 *SessionPool +} + +// Get ... +func (c ContainerAppsSessionPoolsClient) Get(ctx context.Context, id SessionPoolId) (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 SessionPool + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbyresourcegroup.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbyresourcegroup.go new file mode 100644 index 00000000000..4eacee66ef9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package containerappssessionpools + +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 *[]SessionPool +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []SessionPool +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ContainerAppsSessionPoolsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/sessionPools", 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 *[]SessionPool `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 ContainerAppsSessionPoolsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SessionPoolOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsSessionPoolsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SessionPoolOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]SessionPool, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbysubscription.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbysubscription.go new file mode 100644 index 00000000000..ff448670e89 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_listbysubscription.go @@ -0,0 +1,106 @@ +package containerappssessionpools + +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 *[]SessionPool +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []SessionPool +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ContainerAppsSessionPoolsClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/sessionPools", 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 *[]SessionPool `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 ContainerAppsSessionPoolsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, SessionPoolOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsSessionPoolsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SessionPoolOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]SessionPool, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_update.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_update.go new file mode 100644 index 00000000000..5ee5e9420a6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/method_update.go @@ -0,0 +1,75 @@ +package containerappssessionpools + +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 *SessionPool +} + +// Update ... +func (c ContainerAppsSessionPoolsClient) Update(ctx context.Context, id SessionPoolId, input SessionPoolUpdatableProperties) (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 ContainerAppsSessionPoolsClient) UpdateThenPoll(ctx context.Context, id SessionPoolId, input SessionPoolUpdatableProperties) 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/containerapps/2025-01-01/containerappssessionpools/model_customcontainertemplate.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_customcontainertemplate.go new file mode 100644 index 00000000000..9371e74cc23 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_customcontainertemplate.go @@ -0,0 +1,10 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomContainerTemplate struct { + Containers *[]SessionContainer `json:"containers,omitempty"` + Ingress *SessionIngress `json:"ingress,omitempty"` + RegistryCredentials *SessionRegistryCredentials `json:"registryCredentials,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_dynamicpoolconfiguration.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_dynamicpoolconfiguration.go new file mode 100644 index 00000000000..0eaf4c921d9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_dynamicpoolconfiguration.go @@ -0,0 +1,8 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DynamicPoolConfiguration struct { + LifecycleConfiguration *LifecycleConfiguration `json:"lifecycleConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_environmentvar.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_environmentvar.go new file mode 100644 index 00000000000..add2280824b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_environmentvar.go @@ -0,0 +1,10 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentVar struct { + Name *string `json:"name,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_lifecycleconfiguration.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_lifecycleconfiguration.go new file mode 100644 index 00000000000..a27f42bc6a8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_lifecycleconfiguration.go @@ -0,0 +1,10 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LifecycleConfiguration struct { + CooldownPeriodInSeconds *int64 `json:"cooldownPeriodInSeconds,omitempty"` + LifecycleType *LifecycleType `json:"lifecycleType,omitempty"` + MaxAlivePeriodInSeconds *int64 `json:"maxAlivePeriodInSeconds,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_managedidentitysetting.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_managedidentitysetting.go new file mode 100644 index 00000000000..90d023ab236 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_managedidentitysetting.go @@ -0,0 +1,9 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitySetting struct { + Identity string `json:"identity"` + Lifecycle *IdentitySettingsLifeCycle `json:"lifecycle,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_scaleconfiguration.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_scaleconfiguration.go new file mode 100644 index 00000000000..5f7191cdcc0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_scaleconfiguration.go @@ -0,0 +1,9 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleConfiguration struct { + MaxConcurrentSessions *int64 `json:"maxConcurrentSessions,omitempty"` + ReadySessionInstances *int64 `json:"readySessionInstances,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainer.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainer.go new file mode 100644 index 00000000000..f0a0cfda9a6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainer.go @@ -0,0 +1,13 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionContainer struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Resources *SessionContainerResources `json:"resources,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainerresources.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainerresources.go new file mode 100644 index 00000000000..66fcda45521 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioncontainerresources.go @@ -0,0 +1,9 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionContainerResources struct { + Cpu *float64 `json:"cpu,omitempty"` + Memory *string `json:"memory,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioningress.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioningress.go new file mode 100644 index 00000000000..dd531fd9c19 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessioningress.go @@ -0,0 +1,8 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionIngress struct { + TargetPort *int64 `json:"targetPort,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionnetworkconfiguration.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionnetworkconfiguration.go new file mode 100644 index 00000000000..c977a45acb8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionnetworkconfiguration.go @@ -0,0 +1,8 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionNetworkConfiguration struct { + Status *SessionNetworkStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpool.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpool.go new file mode 100644 index 00000000000..518c1c34ec4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpool.go @@ -0,0 +1,20 @@ +package containerappssessionpools + +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 SessionPool struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *SessionPoolProperties `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/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolproperties.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolproperties.go new file mode 100644 index 00000000000..719a7d07246 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolproperties.go @@ -0,0 +1,19 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionPoolProperties struct { + ContainerType *ContainerType `json:"containerType,omitempty"` + CustomContainerTemplate *CustomContainerTemplate `json:"customContainerTemplate,omitempty"` + DynamicPoolConfiguration *DynamicPoolConfiguration `json:"dynamicPoolConfiguration,omitempty"` + EnvironmentId *string `json:"environmentId,omitempty"` + ManagedIdentitySettings *[]ManagedIdentitySetting `json:"managedIdentitySettings,omitempty"` + NodeCount *int64 `json:"nodeCount,omitempty"` + PoolManagementEndpoint *string `json:"poolManagementEndpoint,omitempty"` + PoolManagementType *PoolManagementType `json:"poolManagementType,omitempty"` + ProvisioningState *SessionPoolProvisioningState `json:"provisioningState,omitempty"` + ScaleConfiguration *ScaleConfiguration `json:"scaleConfiguration,omitempty"` + Secrets *[]SessionPoolSecret `json:"secrets,omitempty"` + SessionNetworkConfiguration *SessionNetworkConfiguration `json:"sessionNetworkConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolsecret.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolsecret.go new file mode 100644 index 00000000000..e1eb197f24e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolsecret.go @@ -0,0 +1,9 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionPoolSecret struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatableproperties.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatableproperties.go new file mode 100644 index 00000000000..77a5e1845df --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatableproperties.go @@ -0,0 +1,14 @@ +package containerappssessionpools + +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 SessionPoolUpdatableProperties struct { + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *SessionPoolUpdatablePropertiesProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatablepropertiesproperties.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatablepropertiesproperties.go new file mode 100644 index 00000000000..324b49866eb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionpoolupdatablepropertiesproperties.go @@ -0,0 +1,12 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionPoolUpdatablePropertiesProperties struct { + CustomContainerTemplate *CustomContainerTemplate `json:"customContainerTemplate,omitempty"` + DynamicPoolConfiguration *DynamicPoolConfiguration `json:"dynamicPoolConfiguration,omitempty"` + ScaleConfiguration *ScaleConfiguration `json:"scaleConfiguration,omitempty"` + Secrets *[]SessionPoolSecret `json:"secrets,omitempty"` + SessionNetworkConfiguration *SessionNetworkConfiguration `json:"sessionNetworkConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionregistrycredentials.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionregistrycredentials.go new file mode 100644 index 00000000000..0f87b9152a2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/model_sessionregistrycredentials.go @@ -0,0 +1,11 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionRegistryCredentials struct { + Identity *string `json:"identity,omitempty"` + PasswordSecretRef *string `json:"passwordSecretRef,omitempty"` + Server *string `json:"server,omitempty"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssessionpools/predicates.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/predicates.go new file mode 100644 index 00000000000..b5e04477700 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/predicates.go @@ -0,0 +1,32 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SessionPoolOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SessionPoolOperationPredicate) Matches(input SessionPool) 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/containerapps/2025-01-01/containerappssessionpools/version.go b/resource-manager/containerapps/2025-01-01/containerappssessionpools/version.go new file mode 100644 index 00000000000..0b318121af2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssessionpools/version.go @@ -0,0 +1,10 @@ +package containerappssessionpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/containerappssessionpools/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/README.md b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/README.md new file mode 100644 index 00000000000..8a7a59a7ba3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappssourcecontrols` Documentation + +The `containerappssourcecontrols` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/containerappssourcecontrols" +``` + + +### Client Initialization + +```go +client := containerappssourcecontrols.NewContainerAppsSourceControlsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContainerAppsSourceControlsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := containerappssourcecontrols.NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "sourceControlName") + +payload := containerappssourcecontrols.SourceControl{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsSourceControlsClient.Delete` + +```go +ctx := context.TODO() +id := containerappssourcecontrols.NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "sourceControlName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ContainerAppsSourceControlsClient.Get` + +```go +ctx := context.TODO() +id := containerappssourcecontrols.NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "sourceControlName") + +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: `ContainerAppsSourceControlsClient.ListByContainerApp` + +```go +ctx := context.TODO() +id := containerappssourcecontrols.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.ListByContainerApp(ctx, id)` can be used to do batched pagination +items, err := client.ListByContainerAppComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/client.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/client.go new file mode 100644 index 00000000000..5946a41621a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/client.go @@ -0,0 +1,26 @@ +package containerappssourcecontrols + +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 ContainerAppsSourceControlsClient struct { + Client *resourcemanager.Client +} + +func NewContainerAppsSourceControlsClientWithBaseURI(sdkApi sdkEnv.Api) (*ContainerAppsSourceControlsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "containerappssourcecontrols", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContainerAppsSourceControlsClient: %+v", err) + } + + return &ContainerAppsSourceControlsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/constants.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/constants.go new file mode 100644 index 00000000000..efb9bb4bbc4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/constants.go @@ -0,0 +1,57 @@ +package containerappssourcecontrols + +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 SourceControlOperationState string + +const ( + SourceControlOperationStateCanceled SourceControlOperationState = "Canceled" + SourceControlOperationStateFailed SourceControlOperationState = "Failed" + SourceControlOperationStateInProgress SourceControlOperationState = "InProgress" + SourceControlOperationStateSucceeded SourceControlOperationState = "Succeeded" +) + +func PossibleValuesForSourceControlOperationState() []string { + return []string{ + string(SourceControlOperationStateCanceled), + string(SourceControlOperationStateFailed), + string(SourceControlOperationStateInProgress), + string(SourceControlOperationStateSucceeded), + } +} + +func (s *SourceControlOperationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceControlOperationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceControlOperationState(input string) (*SourceControlOperationState, error) { + vals := map[string]SourceControlOperationState{ + "canceled": SourceControlOperationStateCanceled, + "failed": SourceControlOperationStateFailed, + "inprogress": SourceControlOperationStateInProgress, + "succeeded": SourceControlOperationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceControlOperationState(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp.go new file mode 100644 index 00000000000..9adb2f4ec75 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp.go @@ -0,0 +1,130 @@ +package containerappssourcecontrols + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppId{}) +} + +var _ resourceids.ResourceId = &ContainerAppId{} + +// ContainerAppId is a struct representing the Resource ID for a Container App +type ContainerAppId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string +} + +// NewContainerAppID returns a new ContainerAppId struct +func NewContainerAppID(subscriptionId string, resourceGroupName string, containerAppName string) ContainerAppId { + return ContainerAppId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + } +} + +// ParseContainerAppID parses 'input' into a ContainerAppId +func ParseContainerAppID(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppIDInsensitively parses 'input' case-insensitively into a ContainerAppId +// note: this method should only be used for API response data and not user input +func ParseContainerAppIDInsensitively(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + return nil +} + +// ValidateContainerAppID checks that 'input' can be parsed as a Container App ID +func ValidateContainerAppID(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 := ParseContainerAppID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App ID +func (id ContainerAppId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App ID +func (id ContainerAppId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + } +} + +// String returns a human-readable description of this Container App ID +func (id ContainerAppId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + } + return fmt.Sprintf("Container App (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp_test.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp_test.go new file mode 100644 index 00000000000..83b55f61a57 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_containerapp_test.go @@ -0,0 +1,282 @@ +package containerappssourcecontrols + +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 = &ContainerAppId{} + +func TestNewContainerAppID(t *testing.T) { + id := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } +} + +func TestFormatContainerAppID(t *testing.T) { + actual := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestParseContainerAppIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestSegmentsForContainerAppId(t *testing.T) { + segments := ContainerAppId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppId 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/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol.go new file mode 100644 index 00000000000..1cf8704ee10 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol.go @@ -0,0 +1,139 @@ +package containerappssourcecontrols + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SourceControlId{}) +} + +var _ resourceids.ResourceId = &SourceControlId{} + +// SourceControlId is a struct representing the Resource ID for a Source Control +type SourceControlId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + SourceControlName string +} + +// NewSourceControlID returns a new SourceControlId struct +func NewSourceControlID(subscriptionId string, resourceGroupName string, containerAppName string, sourceControlName string) SourceControlId { + return SourceControlId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + SourceControlName: sourceControlName, + } +} + +// ParseSourceControlID parses 'input' into a SourceControlId +func ParseSourceControlID(input string) (*SourceControlId, error) { + parser := resourceids.NewParserFromResourceIdType(&SourceControlId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SourceControlId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSourceControlIDInsensitively parses 'input' case-insensitively into a SourceControlId +// note: this method should only be used for API response data and not user input +func ParseSourceControlIDInsensitively(input string) (*SourceControlId, error) { + parser := resourceids.NewParserFromResourceIdType(&SourceControlId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SourceControlId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SourceControlId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.SourceControlName, ok = input.Parsed["sourceControlName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sourceControlName", input) + } + + return nil +} + +// ValidateSourceControlID checks that 'input' can be parsed as a Source Control ID +func ValidateSourceControlID(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 := ParseSourceControlID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Source Control ID +func (id SourceControlId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/sourceControls/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.SourceControlName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Source Control ID +func (id SourceControlId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticSourceControls", "sourceControls", "sourceControls"), + resourceids.UserSpecifiedSegment("sourceControlName", "sourceControlName"), + } +} + +// String returns a human-readable description of this Source Control ID +func (id SourceControlId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Source Control Name: %q", id.SourceControlName), + } + return fmt.Sprintf("Source Control (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol_test.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol_test.go new file mode 100644 index 00000000000..21faa26ecca --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/id_sourcecontrol_test.go @@ -0,0 +1,327 @@ +package containerappssourcecontrols + +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 = &SourceControlId{} + +func TestNewSourceControlID(t *testing.T) { + id := NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "sourceControlName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.SourceControlName != "sourceControlName" { + t.Fatalf("Expected %q but got %q for Segment 'SourceControlName'", id.SourceControlName, "sourceControlName") + } +} + +func TestFormatSourceControlID(t *testing.T) { + actual := NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "sourceControlName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls/sourceControlName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSourceControlID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SourceControlId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls/sourceControlName", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + SourceControlName: "sourceControlName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls/sourceControlName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSourceControlID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.SourceControlName != v.Expected.SourceControlName { + t.Fatalf("Expected %q but got %q for SourceControlName", v.Expected.SourceControlName, actual.SourceControlName) + } + + } +} + +func TestParseSourceControlIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SourceControlId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/sOuRcEcOnTrOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls/sourceControlName", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + SourceControlName: "sourceControlName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/sourceControls/sourceControlName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/sOuRcEcOnTrOlS/sOuRcEcOnTrOlNaMe", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + SourceControlName: "sOuRcEcOnTrOlNaMe", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/sOuRcEcOnTrOlS/sOuRcEcOnTrOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSourceControlIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.SourceControlName != v.Expected.SourceControlName { + t.Fatalf("Expected %q but got %q for SourceControlName", v.Expected.SourceControlName, actual.SourceControlName) + } + + } +} + +func TestSegmentsForSourceControlId(t *testing.T) { + segments := SourceControlId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SourceControlId 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/containerapps/2025-01-01/containerappssourcecontrols/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_createorupdate.go new file mode 100644 index 00000000000..2c94c7b08fc --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_createorupdate.go @@ -0,0 +1,75 @@ +package containerappssourcecontrols + +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 *SourceControl +} + +// CreateOrUpdate ... +func (c ContainerAppsSourceControlsClient) CreateOrUpdate(ctx context.Context, id SourceControlId, input SourceControl) (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 ContainerAppsSourceControlsClient) CreateOrUpdateThenPoll(ctx context.Context, id SourceControlId, input SourceControl) 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/containerapps/2025-01-01/containerappssourcecontrols/method_delete.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_delete.go new file mode 100644 index 00000000000..45da30be268 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_delete.go @@ -0,0 +1,71 @@ +package containerappssourcecontrols + +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 ContainerAppsSourceControlsClient) Delete(ctx context.Context, id SourceControlId) (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 ContainerAppsSourceControlsClient) DeleteThenPoll(ctx context.Context, id SourceControlId) 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/containerapps/2025-01-01/containerappssourcecontrols/method_get.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_get.go new file mode 100644 index 00000000000..fab8194e2ab --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_get.go @@ -0,0 +1,53 @@ +package containerappssourcecontrols + +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 *SourceControl +} + +// Get ... +func (c ContainerAppsSourceControlsClient) Get(ctx context.Context, id SourceControlId) (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 SourceControl + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_listbycontainerapp.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_listbycontainerapp.go new file mode 100644 index 00000000000..ad3d60ca029 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/method_listbycontainerapp.go @@ -0,0 +1,105 @@ +package containerappssourcecontrols + +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 ListByContainerAppOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SourceControl +} + +type ListByContainerAppCompleteResult struct { + LatestHttpResponse *http.Response + Items []SourceControl +} + +type ListByContainerAppCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByContainerAppCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByContainerApp ... +func (c ContainerAppsSourceControlsClient) ListByContainerApp(ctx context.Context, id ContainerAppId) (result ListByContainerAppOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByContainerAppCustomPager{}, + Path: fmt.Sprintf("%s/sourceControls", 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 *[]SourceControl `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByContainerAppComplete retrieves all the results into a single object +func (c ContainerAppsSourceControlsClient) ListByContainerAppComplete(ctx context.Context, id ContainerAppId) (ListByContainerAppCompleteResult, error) { + return c.ListByContainerAppCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) +} + +// ListByContainerAppCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContainerAppsSourceControlsClient) ListByContainerAppCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, predicate SourceControlOperationPredicate) (result ListByContainerAppCompleteResult, err error) { + items := make([]SourceControl, 0) + + resp, err := c.ListByContainerApp(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByContainerAppCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_azurecredentials.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_azurecredentials.go new file mode 100644 index 00000000000..ccb7c6817cb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_azurecredentials.go @@ -0,0 +1,12 @@ +package containerappssourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureCredentials struct { + ClientId *string `json:"clientId,omitempty"` + ClientSecret *string `json:"clientSecret,omitempty"` + Kind *string `json:"kind,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_githubactionconfiguration.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_githubactionconfiguration.go new file mode 100644 index 00000000000..ae0f9a31808 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_githubactionconfiguration.go @@ -0,0 +1,16 @@ +package containerappssourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GithubActionConfiguration struct { + AzureCredentials *AzureCredentials `json:"azureCredentials,omitempty"` + ContextPath *string `json:"contextPath,omitempty"` + GitHubPersonalAccessToken *string `json:"githubPersonalAccessToken,omitempty"` + Image *string `json:"image,omitempty"` + Os *string `json:"os,omitempty"` + PublishType *string `json:"publishType,omitempty"` + RegistryInfo *RegistryInfo `json:"registryInfo,omitempty"` + RuntimeStack *string `json:"runtimeStack,omitempty"` + RuntimeVersion *string `json:"runtimeVersion,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_registryinfo.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_registryinfo.go new file mode 100644 index 00000000000..4b1fd214594 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_registryinfo.go @@ -0,0 +1,10 @@ +package containerappssourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryInfo struct { + RegistryPassword *string `json:"registryPassword,omitempty"` + RegistryURL *string `json:"registryUrl,omitempty"` + RegistryUserName *string `json:"registryUserName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrol.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrol.go new file mode 100644 index 00000000000..c04cf1897be --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrol.go @@ -0,0 +1,16 @@ +package containerappssourcecontrols + +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 SourceControl struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SourceControlProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrolproperties.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrolproperties.go new file mode 100644 index 00000000000..581a51ce039 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/model_sourcecontrolproperties.go @@ -0,0 +1,11 @@ +package containerappssourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControlProperties struct { + Branch *string `json:"branch,omitempty"` + GitHubActionConfiguration *GithubActionConfiguration `json:"githubActionConfiguration,omitempty"` + OperationState *SourceControlOperationState `json:"operationState,omitempty"` + RepoURL *string `json:"repoUrl,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/predicates.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/predicates.go new file mode 100644 index 00000000000..38f640c20f4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/predicates.go @@ -0,0 +1,27 @@ +package containerappssourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControlOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SourceControlOperationPredicate) Matches(input SourceControl) 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/containerapps/2025-01-01/containerappssourcecontrols/version.go b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/version.go new file mode 100644 index 00000000000..6bd8885cec5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/containerappssourcecontrols/version.go @@ -0,0 +1,10 @@ +package containerappssourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/containerappssourcecontrols/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/README.md b/resource-manager/containerapps/2025-01-01/daprcomponents/README.md new file mode 100644 index 00000000000..415852c0267 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/README.md @@ -0,0 +1,192 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/daprcomponents` Documentation + +The `daprcomponents` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/daprcomponents" +``` + + +### Client Initialization + +```go +client := daprcomponents.NewDaprComponentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DaprComponentsClient.ConnectedEnvironmentsDaprComponentsCreateOrUpdate` + +```go +ctx := context.TODO() +id := daprcomponents.NewConnectedEnvironmentDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "daprComponentName") + +payload := daprcomponents.DaprComponent{ + // ... +} + + +read, err := client.ConnectedEnvironmentsDaprComponentsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DaprComponentsClient.ConnectedEnvironmentsDaprComponentsDelete` + +```go +ctx := context.TODO() +id := daprcomponents.NewConnectedEnvironmentDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "daprComponentName") + +read, err := client.ConnectedEnvironmentsDaprComponentsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DaprComponentsClient.ConnectedEnvironmentsDaprComponentsGet` + +```go +ctx := context.TODO() +id := daprcomponents.NewConnectedEnvironmentDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "daprComponentName") + +read, err := client.ConnectedEnvironmentsDaprComponentsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DaprComponentsClient.ConnectedEnvironmentsDaprComponentsList` + +```go +ctx := context.TODO() +id := daprcomponents.NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + +// alternatively `client.ConnectedEnvironmentsDaprComponentsList(ctx, id)` can be used to do batched pagination +items, err := client.ConnectedEnvironmentsDaprComponentsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DaprComponentsClient.ConnectedEnvironmentsDaprComponentsListSecrets` + +```go +ctx := context.TODO() +id := daprcomponents.NewConnectedEnvironmentDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "daprComponentName") + +read, err := client.ConnectedEnvironmentsDaprComponentsListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DaprComponentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := daprcomponents.NewDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "daprComponentName") + +payload := daprcomponents.DaprComponent{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DaprComponentsClient.Delete` + +```go +ctx := context.TODO() +id := daprcomponents.NewDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "daprComponentName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DaprComponentsClient.Get` + +```go +ctx := context.TODO() +id := daprcomponents.NewDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "daprComponentName") + +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: `DaprComponentsClient.List` + +```go +ctx := context.TODO() +id := daprcomponents.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// 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: `DaprComponentsClient.ListSecrets` + +```go +ctx := context.TODO() +id := daprcomponents.NewDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "daprComponentName") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/client.go b/resource-manager/containerapps/2025-01-01/daprcomponents/client.go new file mode 100644 index 00000000000..7fb966bb0e5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/client.go @@ -0,0 +1,26 @@ +package daprcomponents + +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 DaprComponentsClient struct { + Client *resourcemanager.Client +} + +func NewDaprComponentsClientWithBaseURI(sdkApi sdkEnv.Api) (*DaprComponentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "daprcomponents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DaprComponentsClient: %+v", err) + } + + return &DaprComponentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment.go new file mode 100644 index 00000000000..22645392402 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment.go @@ -0,0 +1,130 @@ +package daprcomponents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentId{} + +// ConnectedEnvironmentId is a struct representing the Resource ID for a Connected Environment +type ConnectedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string +} + +// NewConnectedEnvironmentID returns a new ConnectedEnvironmentId struct +func NewConnectedEnvironmentID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string) ConnectedEnvironmentId { + return ConnectedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + } +} + +// ParseConnectedEnvironmentID parses 'input' into a ConnectedEnvironmentId +func ParseConnectedEnvironmentID(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentIDInsensitively(input string) (*ConnectedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentID checks that 'input' can be parsed as a Connected Environment ID +func ValidateConnectedEnvironmentID(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 := ParseConnectedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment ID +func (id ConnectedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment ID +func (id ConnectedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + } +} + +// String returns a human-readable description of this Connected Environment ID +func (id ConnectedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + } + return fmt.Sprintf("Connected Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment_test.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment_test.go new file mode 100644 index 00000000000..136f6cad8e3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironment_test.go @@ -0,0 +1,282 @@ +package daprcomponents + +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 = &ConnectedEnvironmentId{} + +func TestNewConnectedEnvironmentID(t *testing.T) { + id := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } +} + +func TestFormatConnectedEnvironmentID(t *testing.T) { + actual := NewConnectedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestParseConnectedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Expected: &ConnectedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentId(t *testing.T) { + segments := ConnectedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentId 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/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent.go new file mode 100644 index 00000000000..6fd9fb8aaa2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent.go @@ -0,0 +1,139 @@ +package daprcomponents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedEnvironmentDaprComponentId{}) +} + +var _ resourceids.ResourceId = &ConnectedEnvironmentDaprComponentId{} + +// ConnectedEnvironmentDaprComponentId is a struct representing the Resource ID for a Connected Environment Dapr Component +type ConnectedEnvironmentDaprComponentId struct { + SubscriptionId string + ResourceGroupName string + ConnectedEnvironmentName string + DaprComponentName string +} + +// NewConnectedEnvironmentDaprComponentID returns a new ConnectedEnvironmentDaprComponentId struct +func NewConnectedEnvironmentDaprComponentID(subscriptionId string, resourceGroupName string, connectedEnvironmentName string, daprComponentName string) ConnectedEnvironmentDaprComponentId { + return ConnectedEnvironmentDaprComponentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedEnvironmentName: connectedEnvironmentName, + DaprComponentName: daprComponentName, + } +} + +// ParseConnectedEnvironmentDaprComponentID parses 'input' into a ConnectedEnvironmentDaprComponentId +func ParseConnectedEnvironmentDaprComponentID(input string) (*ConnectedEnvironmentDaprComponentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentDaprComponentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentDaprComponentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedEnvironmentDaprComponentIDInsensitively parses 'input' case-insensitively into a ConnectedEnvironmentDaprComponentId +// note: this method should only be used for API response data and not user input +func ParseConnectedEnvironmentDaprComponentIDInsensitively(input string) (*ConnectedEnvironmentDaprComponentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedEnvironmentDaprComponentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedEnvironmentDaprComponentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedEnvironmentDaprComponentId) 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.ConnectedEnvironmentName, ok = input.Parsed["connectedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedEnvironmentName", input) + } + + if id.DaprComponentName, ok = input.Parsed["daprComponentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "daprComponentName", input) + } + + return nil +} + +// ValidateConnectedEnvironmentDaprComponentID checks that 'input' can be parsed as a Connected Environment Dapr Component ID +func ValidateConnectedEnvironmentDaprComponentID(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 := ParseConnectedEnvironmentDaprComponentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Environment Dapr Component ID +func (id ConnectedEnvironmentDaprComponentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/connectedEnvironments/%s/daprComponents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedEnvironmentName, id.DaprComponentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Environment Dapr Component ID +func (id ConnectedEnvironmentDaprComponentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticConnectedEnvironments", "connectedEnvironments", "connectedEnvironments"), + resourceids.UserSpecifiedSegment("connectedEnvironmentName", "connectedEnvironmentName"), + resourceids.StaticSegment("staticDaprComponents", "daprComponents", "daprComponents"), + resourceids.UserSpecifiedSegment("daprComponentName", "daprComponentName"), + } +} + +// String returns a human-readable description of this Connected Environment Dapr Component ID +func (id ConnectedEnvironmentDaprComponentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Environment Name: %q", id.ConnectedEnvironmentName), + fmt.Sprintf("Dapr Component Name: %q", id.DaprComponentName), + } + return fmt.Sprintf("Connected Environment Dapr Component (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent_test.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent_test.go new file mode 100644 index 00000000000..3f0c9163f05 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_connectedenvironmentdaprcomponent_test.go @@ -0,0 +1,327 @@ +package daprcomponents + +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 = &ConnectedEnvironmentDaprComponentId{} + +func TestNewConnectedEnvironmentDaprComponentID(t *testing.T) { + id := NewConnectedEnvironmentDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "daprComponentName") + + 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.ConnectedEnvironmentName != "connectedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedEnvironmentName'", id.ConnectedEnvironmentName, "connectedEnvironmentName") + } + + if id.DaprComponentName != "daprComponentName" { + t.Fatalf("Expected %q but got %q for Segment 'DaprComponentName'", id.DaprComponentName, "daprComponentName") + } +} + +func TestFormatConnectedEnvironmentDaprComponentID(t *testing.T) { + actual := NewConnectedEnvironmentDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedEnvironmentName", "daprComponentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents/daprComponentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedEnvironmentDaprComponentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentDaprComponentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents/daprComponentName", + Expected: &ConnectedEnvironmentDaprComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + DaprComponentName: "daprComponentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents/daprComponentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentDaprComponentID(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.DaprComponentName != v.Expected.DaprComponentName { + t.Fatalf("Expected %q but got %q for DaprComponentName", v.Expected.DaprComponentName, actual.DaprComponentName) + } + + } +} + +func TestParseConnectedEnvironmentDaprComponentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedEnvironmentDaprComponentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/dApRcOmPoNeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents/daprComponentName", + Expected: &ConnectedEnvironmentDaprComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ConnectedEnvironmentName: "connectedEnvironmentName", + DaprComponentName: "daprComponentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/connectedEnvironments/connectedEnvironmentName/daprComponents/daprComponentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/dApRcOmPoNeNtS/dApRcOmPoNeNtNaMe", + Expected: &ConnectedEnvironmentDaprComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ConnectedEnvironmentName: "cOnNeCtEdEnViRoNmEnTnAmE", + DaprComponentName: "dApRcOmPoNeNtNaMe", + }, + }, + { + // 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.aPp/cOnNeCtEdEnViRoNmEnTs/cOnNeCtEdEnViRoNmEnTnAmE/dApRcOmPoNeNtS/dApRcOmPoNeNtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedEnvironmentDaprComponentIDInsensitively(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.ConnectedEnvironmentName != v.Expected.ConnectedEnvironmentName { + t.Fatalf("Expected %q but got %q for ConnectedEnvironmentName", v.Expected.ConnectedEnvironmentName, actual.ConnectedEnvironmentName) + } + + if actual.DaprComponentName != v.Expected.DaprComponentName { + t.Fatalf("Expected %q but got %q for DaprComponentName", v.Expected.DaprComponentName, actual.DaprComponentName) + } + + } +} + +func TestSegmentsForConnectedEnvironmentDaprComponentId(t *testing.T) { + segments := ConnectedEnvironmentDaprComponentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedEnvironmentDaprComponentId 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/containerapps/2025-01-01/daprcomponents/id_daprcomponent.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent.go new file mode 100644 index 00000000000..79e702bc196 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent.go @@ -0,0 +1,139 @@ +package daprcomponents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DaprComponentId{}) +} + +var _ resourceids.ResourceId = &DaprComponentId{} + +// DaprComponentId is a struct representing the Resource ID for a Dapr Component +type DaprComponentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + DaprComponentName string +} + +// NewDaprComponentID returns a new DaprComponentId struct +func NewDaprComponentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, daprComponentName string) DaprComponentId { + return DaprComponentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + DaprComponentName: daprComponentName, + } +} + +// ParseDaprComponentID parses 'input' into a DaprComponentId +func ParseDaprComponentID(input string) (*DaprComponentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DaprComponentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DaprComponentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDaprComponentIDInsensitively parses 'input' case-insensitively into a DaprComponentId +// note: this method should only be used for API response data and not user input +func ParseDaprComponentIDInsensitively(input string) (*DaprComponentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DaprComponentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DaprComponentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DaprComponentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.DaprComponentName, ok = input.Parsed["daprComponentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "daprComponentName", input) + } + + return nil +} + +// ValidateDaprComponentID checks that 'input' can be parsed as a Dapr Component ID +func ValidateDaprComponentID(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 := ParseDaprComponentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dapr Component ID +func (id DaprComponentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/daprComponents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.DaprComponentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dapr Component ID +func (id DaprComponentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticDaprComponents", "daprComponents", "daprComponents"), + resourceids.UserSpecifiedSegment("daprComponentName", "daprComponentName"), + } +} + +// String returns a human-readable description of this Dapr Component ID +func (id DaprComponentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Dapr Component Name: %q", id.DaprComponentName), + } + return fmt.Sprintf("Dapr Component (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent_test.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent_test.go new file mode 100644 index 00000000000..6710fa76d6a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_daprcomponent_test.go @@ -0,0 +1,327 @@ +package daprcomponents + +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 = &DaprComponentId{} + +func TestNewDaprComponentID(t *testing.T) { + id := NewDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "daprComponentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.DaprComponentName != "daprComponentName" { + t.Fatalf("Expected %q but got %q for Segment 'DaprComponentName'", id.DaprComponentName, "daprComponentName") + } +} + +func TestFormatDaprComponentID(t *testing.T) { + actual := NewDaprComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "daprComponentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents/daprComponentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDaprComponentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DaprComponentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents/daprComponentName", + Expected: &DaprComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + DaprComponentName: "daprComponentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents/daprComponentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDaprComponentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.DaprComponentName != v.Expected.DaprComponentName { + t.Fatalf("Expected %q but got %q for DaprComponentName", v.Expected.DaprComponentName, actual.DaprComponentName) + } + + } +} + +func TestParseDaprComponentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DaprComponentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dApRcOmPoNeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents/daprComponentName", + Expected: &DaprComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + DaprComponentName: "daprComponentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/daprComponents/daprComponentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dApRcOmPoNeNtS/dApRcOmPoNeNtNaMe", + Expected: &DaprComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + DaprComponentName: "dApRcOmPoNeNtNaMe", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dApRcOmPoNeNtS/dApRcOmPoNeNtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDaprComponentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.DaprComponentName != v.Expected.DaprComponentName { + t.Fatalf("Expected %q but got %q for DaprComponentName", v.Expected.DaprComponentName, actual.DaprComponentName) + } + + } +} + +func TestSegmentsForDaprComponentId(t *testing.T) { + segments := DaprComponentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DaprComponentId 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/containerapps/2025-01-01/daprcomponents/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment.go new file mode 100644 index 00000000000..0b98a11a2b4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment.go @@ -0,0 +1,130 @@ +package daprcomponents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment_test.go new file mode 100644 index 00000000000..3d16f91a9c4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package daprcomponents + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentscreateorupdate.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentscreateorupdate.go new file mode 100644 index 00000000000..3b339e8d2a8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentscreateorupdate.go @@ -0,0 +1,57 @@ +package daprcomponents + +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 ConnectedEnvironmentsDaprComponentsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DaprComponent +} + +// ConnectedEnvironmentsDaprComponentsCreateOrUpdate ... +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsCreateOrUpdate(ctx context.Context, id ConnectedEnvironmentDaprComponentId, input DaprComponent) (result ConnectedEnvironmentsDaprComponentsCreateOrUpdateOperationResponse, 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 DaprComponent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsdelete.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsdelete.go new file mode 100644 index 00000000000..2b8c43d7177 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsdelete.go @@ -0,0 +1,47 @@ +package daprcomponents + +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 ConnectedEnvironmentsDaprComponentsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ConnectedEnvironmentsDaprComponentsDelete ... +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsDelete(ctx context.Context, id ConnectedEnvironmentDaprComponentId) (result ConnectedEnvironmentsDaprComponentsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsget.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsget.go new file mode 100644 index 00000000000..fa7c1d61804 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentsget.go @@ -0,0 +1,53 @@ +package daprcomponents + +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 ConnectedEnvironmentsDaprComponentsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DaprComponent +} + +// ConnectedEnvironmentsDaprComponentsGet ... +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsGet(ctx context.Context, id ConnectedEnvironmentDaprComponentId) (result ConnectedEnvironmentsDaprComponentsGetOperationResponse, 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 DaprComponent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslist.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslist.go new file mode 100644 index 00000000000..b0bd3cbd16b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslist.go @@ -0,0 +1,105 @@ +package daprcomponents + +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 ConnectedEnvironmentsDaprComponentsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DaprComponent +} + +type ConnectedEnvironmentsDaprComponentsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DaprComponent +} + +type ConnectedEnvironmentsDaprComponentsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ConnectedEnvironmentsDaprComponentsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ConnectedEnvironmentsDaprComponentsList ... +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsList(ctx context.Context, id ConnectedEnvironmentId) (result ConnectedEnvironmentsDaprComponentsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ConnectedEnvironmentsDaprComponentsListCustomPager{}, + Path: fmt.Sprintf("%s/daprComponents", 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 *[]DaprComponent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ConnectedEnvironmentsDaprComponentsListComplete retrieves all the results into a single object +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsListComplete(ctx context.Context, id ConnectedEnvironmentId) (ConnectedEnvironmentsDaprComponentsListCompleteResult, error) { + return c.ConnectedEnvironmentsDaprComponentsListCompleteMatchingPredicate(ctx, id, DaprComponentOperationPredicate{}) +} + +// ConnectedEnvironmentsDaprComponentsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsListCompleteMatchingPredicate(ctx context.Context, id ConnectedEnvironmentId, predicate DaprComponentOperationPredicate) (result ConnectedEnvironmentsDaprComponentsListCompleteResult, err error) { + items := make([]DaprComponent, 0) + + resp, err := c.ConnectedEnvironmentsDaprComponentsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ConnectedEnvironmentsDaprComponentsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslistsecrets.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslistsecrets.go new file mode 100644 index 00000000000..6474a29e1d8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_connectedenvironmentsdaprcomponentslistsecrets.go @@ -0,0 +1,54 @@ +package daprcomponents + +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 ConnectedEnvironmentsDaprComponentsListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DaprSecretsCollection +} + +// ConnectedEnvironmentsDaprComponentsListSecrets ... +func (c DaprComponentsClient) ConnectedEnvironmentsDaprComponentsListSecrets(ctx context.Context, id ConnectedEnvironmentDaprComponentId) (result ConnectedEnvironmentsDaprComponentsListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 DaprSecretsCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_createorupdate.go new file mode 100644 index 00000000000..b9ca657b15d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_createorupdate.go @@ -0,0 +1,57 @@ +package daprcomponents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DaprComponent +} + +// CreateOrUpdate ... +func (c DaprComponentsClient) CreateOrUpdate(ctx context.Context, id DaprComponentId, input DaprComponent) (result CreateOrUpdateOperationResponse, 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 DaprComponent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_delete.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_delete.go new file mode 100644 index 00000000000..211efc17f75 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_delete.go @@ -0,0 +1,47 @@ +package daprcomponents + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DaprComponentsClient) Delete(ctx context.Context, id DaprComponentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_get.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_get.go new file mode 100644 index 00000000000..b60e81d0ae5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_get.go @@ -0,0 +1,53 @@ +package daprcomponents + +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 *DaprComponent +} + +// Get ... +func (c DaprComponentsClient) Get(ctx context.Context, id DaprComponentId) (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 DaprComponent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_list.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_list.go new file mode 100644 index 00000000000..69e55736217 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_list.go @@ -0,0 +1,105 @@ +package daprcomponents + +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 *[]DaprComponent +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DaprComponent +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c DaprComponentsClient) List(ctx context.Context, id ManagedEnvironmentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/daprComponents", 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 *[]DaprComponent `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 DaprComponentsClient) ListComplete(ctx context.Context, id ManagedEnvironmentId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DaprComponentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DaprComponentsClient) ListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate DaprComponentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DaprComponent, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/method_listsecrets.go b/resource-manager/containerapps/2025-01-01/daprcomponents/method_listsecrets.go new file mode 100644 index 00000000000..03d6c3ccdcb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/method_listsecrets.go @@ -0,0 +1,54 @@ +package daprcomponents + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DaprSecretsCollection +} + +// ListSecrets ... +func (c DaprComponentsClient) ListSecrets(ctx context.Context, id DaprComponentId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 DaprSecretsCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponent.go b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponent.go new file mode 100644 index 00000000000..bb4b6f41c32 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponent.go @@ -0,0 +1,16 @@ +package daprcomponents + +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 DaprComponent struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DaprComponentProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponentproperties.go b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponentproperties.go new file mode 100644 index 00000000000..5dba15d7cdd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprcomponentproperties.go @@ -0,0 +1,15 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprComponentProperties struct { + ComponentType *string `json:"componentType,omitempty"` + IgnoreErrors *bool `json:"ignoreErrors,omitempty"` + InitTimeout *string `json:"initTimeout,omitempty"` + Metadata *[]DaprMetadata `json:"metadata,omitempty"` + Scopes *[]string `json:"scopes,omitempty"` + SecretStoreComponent *string `json:"secretStoreComponent,omitempty"` + Secrets *[]Secret `json:"secrets,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprmetadata.go b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprmetadata.go new file mode 100644 index 00000000000..8b82e1749b4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprmetadata.go @@ -0,0 +1,10 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprMetadata struct { + Name *string `json:"name,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecret.go b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecret.go new file mode 100644 index 00000000000..82ce596575c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecret.go @@ -0,0 +1,9 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprSecret struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecretscollection.go b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecretscollection.go new file mode 100644 index 00000000000..0f52a6c5f30 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/model_daprsecretscollection.go @@ -0,0 +1,8 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprSecretsCollection struct { + Value []DaprSecret `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/model_secret.go b/resource-manager/containerapps/2025-01-01/daprcomponents/model_secret.go new file mode 100644 index 00000000000..324d56bf7cf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/model_secret.go @@ -0,0 +1,11 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Secret struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/daprcomponents/predicates.go b/resource-manager/containerapps/2025-01-01/daprcomponents/predicates.go new file mode 100644 index 00000000000..c623d167466 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/predicates.go @@ -0,0 +1,27 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprComponentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DaprComponentOperationPredicate) Matches(input DaprComponent) 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/containerapps/2025-01-01/daprcomponents/version.go b/resource-manager/containerapps/2025-01-01/daprcomponents/version.go new file mode 100644 index 00000000000..ba8ac46cc06 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/daprcomponents/version.go @@ -0,0 +1,10 @@ +package daprcomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/daprcomponents/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/README.md b/resource-manager/containerapps/2025-01-01/diagnostics/README.md new file mode 100644 index 00000000000..758709dc512 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/README.md @@ -0,0 +1,200 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/diagnostics` Documentation + +The `diagnostics` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/diagnostics" +``` + + +### Client Initialization + +```go +client := diagnostics.NewDiagnosticsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DiagnosticsClient.ContainerAppsDiagnosticsGetDetector` + +```go +ctx := context.TODO() +id := diagnostics.NewContainerAppDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "detectorName") + +read, err := client.ContainerAppsDiagnosticsGetDetector(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticsClient.ContainerAppsDiagnosticsGetRevision` + +```go +ctx := context.TODO() +id := diagnostics.NewRevisionsApiRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + +read, err := client.ContainerAppsDiagnosticsGetRevision(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticsClient.ContainerAppsDiagnosticsGetRoot` + +```go +ctx := context.TODO() +id := diagnostics.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +read, err := client.ContainerAppsDiagnosticsGetRoot(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticsClient.ContainerAppsDiagnosticsListDetectors` + +```go +ctx := context.TODO() +id := diagnostics.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.ContainerAppsDiagnosticsListDetectors(ctx, id)` can be used to do batched pagination +items, err := client.ContainerAppsDiagnosticsListDetectorsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiagnosticsClient.ContainerAppsDiagnosticsListRevisions` + +```go +ctx := context.TODO() +id := diagnostics.NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + +// alternatively `client.ContainerAppsDiagnosticsListRevisions(ctx, id, diagnostics.DefaultContainerAppsDiagnosticsListRevisionsOperationOptions())` can be used to do batched pagination +items, err := client.ContainerAppsDiagnosticsListRevisionsComplete(ctx, id, diagnostics.DefaultContainerAppsDiagnosticsListRevisionsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiagnosticsClient.JobsGetDetector` + +```go +ctx := context.TODO() +id := diagnostics.NewDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorName") + +read, err := client.JobsGetDetector(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticsClient.JobsListDetectors` + +```go +ctx := context.TODO() +id := diagnostics.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +// alternatively `client.JobsListDetectors(ctx, id)` can be used to do batched pagination +items, err := client.JobsListDetectorsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiagnosticsClient.JobsProxyGet` + +```go +ctx := context.TODO() +id := diagnostics.NewDetectorPropertyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorPropertyName") + +read, err := client.JobsProxyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticsClient.ManagedEnvironmentDiagnosticsGetDetector` + +```go +ctx := context.TODO() +id := diagnostics.NewManagedEnvironmentDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "detectorName") + +read, err := client.ManagedEnvironmentDiagnosticsGetDetector(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiagnosticsClient.ManagedEnvironmentDiagnosticsListDetectors` + +```go +ctx := context.TODO() +id := diagnostics.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// alternatively `client.ManagedEnvironmentDiagnosticsListDetectors(ctx, id)` can be used to do batched pagination +items, err := client.ManagedEnvironmentDiagnosticsListDetectorsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiagnosticsClient.ManagedEnvironmentsDiagnosticsGetRoot` + +```go +ctx := context.TODO() +id := diagnostics.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +read, err := client.ManagedEnvironmentsDiagnosticsGetRoot(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/client.go b/resource-manager/containerapps/2025-01-01/diagnostics/client.go new file mode 100644 index 00000000000..4b218f34ee2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/client.go @@ -0,0 +1,26 @@ +package diagnostics + +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 DiagnosticsClient struct { + Client *resourcemanager.Client +} + +func NewDiagnosticsClientWithBaseURI(sdkApi sdkEnv.Api) (*DiagnosticsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "diagnostics", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DiagnosticsClient: %+v", err) + } + + return &DiagnosticsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/constants.go b/resource-manager/containerapps/2025-01-01/diagnostics/constants.go new file mode 100644 index 00000000000..81635223305 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/constants.go @@ -0,0 +1,976 @@ +package diagnostics + +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 Action string + +const ( + ActionAllow Action = "Allow" + ActionDeny Action = "Deny" +) + +func PossibleValuesForAction() []string { + return []string{ + string(ActionAllow), + string(ActionDeny), + } +} + +func (s *Action) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAction(input string) (*Action, error) { + vals := map[string]Action{ + "allow": ActionAllow, + "deny": ActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Action(input) + return &out, nil +} + +type ActiveRevisionsMode string + +const ( + ActiveRevisionsModeMultiple ActiveRevisionsMode = "Multiple" + ActiveRevisionsModeSingle ActiveRevisionsMode = "Single" +) + +func PossibleValuesForActiveRevisionsMode() []string { + return []string{ + string(ActiveRevisionsModeMultiple), + string(ActiveRevisionsModeSingle), + } +} + +func (s *ActiveRevisionsMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActiveRevisionsMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActiveRevisionsMode(input string) (*ActiveRevisionsMode, error) { + vals := map[string]ActiveRevisionsMode{ + "multiple": ActiveRevisionsModeMultiple, + "single": ActiveRevisionsModeSingle, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActiveRevisionsMode(input) + return &out, nil +} + +type Affinity string + +const ( + AffinityNone Affinity = "none" + AffinitySticky Affinity = "sticky" +) + +func PossibleValuesForAffinity() []string { + return []string{ + string(AffinityNone), + string(AffinitySticky), + } +} + +func (s *Affinity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAffinity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAffinity(input string) (*Affinity, error) { + vals := map[string]Affinity{ + "none": AffinityNone, + "sticky": AffinitySticky, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Affinity(input) + return &out, nil +} + +type AppProtocol string + +const ( + AppProtocolGrpc AppProtocol = "grpc" + AppProtocolHTTP AppProtocol = "http" +) + +func PossibleValuesForAppProtocol() []string { + return []string{ + string(AppProtocolGrpc), + string(AppProtocolHTTP), + } +} + +func (s *AppProtocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAppProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAppProtocol(input string) (*AppProtocol, error) { + vals := map[string]AppProtocol{ + "grpc": AppProtocolGrpc, + "http": AppProtocolHTTP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AppProtocol(input) + return &out, nil +} + +type BindingType string + +const ( + BindingTypeDisabled BindingType = "Disabled" + BindingTypeSniEnabled BindingType = "SniEnabled" +) + +func PossibleValuesForBindingType() []string { + return []string{ + string(BindingTypeDisabled), + string(BindingTypeSniEnabled), + } +} + +func (s *BindingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBindingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBindingType(input string) (*BindingType, error) { + vals := map[string]BindingType{ + "disabled": BindingTypeDisabled, + "snienabled": BindingTypeSniEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BindingType(input) + return &out, nil +} + +type ContainerAppProvisioningState string + +const ( + ContainerAppProvisioningStateCanceled ContainerAppProvisioningState = "Canceled" + ContainerAppProvisioningStateDeleting ContainerAppProvisioningState = "Deleting" + ContainerAppProvisioningStateFailed ContainerAppProvisioningState = "Failed" + ContainerAppProvisioningStateInProgress ContainerAppProvisioningState = "InProgress" + ContainerAppProvisioningStateSucceeded ContainerAppProvisioningState = "Succeeded" +) + +func PossibleValuesForContainerAppProvisioningState() []string { + return []string{ + string(ContainerAppProvisioningStateCanceled), + string(ContainerAppProvisioningStateDeleting), + string(ContainerAppProvisioningStateFailed), + string(ContainerAppProvisioningStateInProgress), + string(ContainerAppProvisioningStateSucceeded), + } +} + +func (s *ContainerAppProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerAppProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerAppProvisioningState(input string) (*ContainerAppProvisioningState, error) { + vals := map[string]ContainerAppProvisioningState{ + "canceled": ContainerAppProvisioningStateCanceled, + "deleting": ContainerAppProvisioningStateDeleting, + "failed": ContainerAppProvisioningStateFailed, + "inprogress": ContainerAppProvisioningStateInProgress, + "succeeded": ContainerAppProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerAppProvisioningState(input) + return &out, nil +} + +type ContainerAppRunningStatus string + +const ( + ContainerAppRunningStatusProgressing ContainerAppRunningStatus = "Progressing" + ContainerAppRunningStatusReady ContainerAppRunningStatus = "Ready" + ContainerAppRunningStatusRunning ContainerAppRunningStatus = "Running" + ContainerAppRunningStatusStopped ContainerAppRunningStatus = "Stopped" + ContainerAppRunningStatusSuspended ContainerAppRunningStatus = "Suspended" +) + +func PossibleValuesForContainerAppRunningStatus() []string { + return []string{ + string(ContainerAppRunningStatusProgressing), + string(ContainerAppRunningStatusReady), + string(ContainerAppRunningStatusRunning), + string(ContainerAppRunningStatusStopped), + string(ContainerAppRunningStatusSuspended), + } +} + +func (s *ContainerAppRunningStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerAppRunningStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerAppRunningStatus(input string) (*ContainerAppRunningStatus, error) { + vals := map[string]ContainerAppRunningStatus{ + "progressing": ContainerAppRunningStatusProgressing, + "ready": ContainerAppRunningStatusReady, + "running": ContainerAppRunningStatusRunning, + "stopped": ContainerAppRunningStatusStopped, + "suspended": ContainerAppRunningStatusSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerAppRunningStatus(input) + return &out, nil +} + +type EnvironmentProvisioningState string + +const ( + EnvironmentProvisioningStateCanceled EnvironmentProvisioningState = "Canceled" + EnvironmentProvisioningStateFailed EnvironmentProvisioningState = "Failed" + EnvironmentProvisioningStateInfrastructureSetupComplete EnvironmentProvisioningState = "InfrastructureSetupComplete" + EnvironmentProvisioningStateInfrastructureSetupInProgress EnvironmentProvisioningState = "InfrastructureSetupInProgress" + EnvironmentProvisioningStateInitializationInProgress EnvironmentProvisioningState = "InitializationInProgress" + EnvironmentProvisioningStateScheduledForDelete EnvironmentProvisioningState = "ScheduledForDelete" + EnvironmentProvisioningStateSucceeded EnvironmentProvisioningState = "Succeeded" + EnvironmentProvisioningStateUpgradeFailed EnvironmentProvisioningState = "UpgradeFailed" + EnvironmentProvisioningStateUpgradeRequested EnvironmentProvisioningState = "UpgradeRequested" + EnvironmentProvisioningStateWaiting EnvironmentProvisioningState = "Waiting" +) + +func PossibleValuesForEnvironmentProvisioningState() []string { + return []string{ + string(EnvironmentProvisioningStateCanceled), + string(EnvironmentProvisioningStateFailed), + string(EnvironmentProvisioningStateInfrastructureSetupComplete), + string(EnvironmentProvisioningStateInfrastructureSetupInProgress), + string(EnvironmentProvisioningStateInitializationInProgress), + string(EnvironmentProvisioningStateScheduledForDelete), + string(EnvironmentProvisioningStateSucceeded), + string(EnvironmentProvisioningStateUpgradeFailed), + string(EnvironmentProvisioningStateUpgradeRequested), + string(EnvironmentProvisioningStateWaiting), + } +} + +func (s *EnvironmentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnvironmentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnvironmentProvisioningState(input string) (*EnvironmentProvisioningState, error) { + vals := map[string]EnvironmentProvisioningState{ + "canceled": EnvironmentProvisioningStateCanceled, + "failed": EnvironmentProvisioningStateFailed, + "infrastructuresetupcomplete": EnvironmentProvisioningStateInfrastructureSetupComplete, + "infrastructuresetupinprogress": EnvironmentProvisioningStateInfrastructureSetupInProgress, + "initializationinprogress": EnvironmentProvisioningStateInitializationInProgress, + "scheduledfordelete": EnvironmentProvisioningStateScheduledForDelete, + "succeeded": EnvironmentProvisioningStateSucceeded, + "upgradefailed": EnvironmentProvisioningStateUpgradeFailed, + "upgraderequested": EnvironmentProvisioningStateUpgradeRequested, + "waiting": EnvironmentProvisioningStateWaiting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnvironmentProvisioningState(input) + return &out, nil +} + +type ExtendedLocationTypes string + +const ( + ExtendedLocationTypesCustomLocation ExtendedLocationTypes = "CustomLocation" +) + +func PossibleValuesForExtendedLocationTypes() []string { + return []string{ + string(ExtendedLocationTypesCustomLocation), + } +} + +func (s *ExtendedLocationTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtendedLocationTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtendedLocationTypes(input string) (*ExtendedLocationTypes, error) { + vals := map[string]ExtendedLocationTypes{ + "customlocation": ExtendedLocationTypesCustomLocation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtendedLocationTypes(input) + return &out, nil +} + +type IdentitySettingsLifeCycle string + +const ( + IdentitySettingsLifeCycleAll IdentitySettingsLifeCycle = "All" + IdentitySettingsLifeCycleInit IdentitySettingsLifeCycle = "Init" + IdentitySettingsLifeCycleMain IdentitySettingsLifeCycle = "Main" + IdentitySettingsLifeCycleNone IdentitySettingsLifeCycle = "None" +) + +func PossibleValuesForIdentitySettingsLifeCycle() []string { + return []string{ + string(IdentitySettingsLifeCycleAll), + string(IdentitySettingsLifeCycleInit), + string(IdentitySettingsLifeCycleMain), + string(IdentitySettingsLifeCycleNone), + } +} + +func (s *IdentitySettingsLifeCycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentitySettingsLifeCycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentitySettingsLifeCycle(input string) (*IdentitySettingsLifeCycle, error) { + vals := map[string]IdentitySettingsLifeCycle{ + "all": IdentitySettingsLifeCycleAll, + "init": IdentitySettingsLifeCycleInit, + "main": IdentitySettingsLifeCycleMain, + "none": IdentitySettingsLifeCycleNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentitySettingsLifeCycle(input) + return &out, nil +} + +type IngressClientCertificateMode string + +const ( + IngressClientCertificateModeAccept IngressClientCertificateMode = "accept" + IngressClientCertificateModeIgnore IngressClientCertificateMode = "ignore" + IngressClientCertificateModeRequire IngressClientCertificateMode = "require" +) + +func PossibleValuesForIngressClientCertificateMode() []string { + return []string{ + string(IngressClientCertificateModeAccept), + string(IngressClientCertificateModeIgnore), + string(IngressClientCertificateModeRequire), + } +} + +func (s *IngressClientCertificateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIngressClientCertificateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIngressClientCertificateMode(input string) (*IngressClientCertificateMode, error) { + vals := map[string]IngressClientCertificateMode{ + "accept": IngressClientCertificateModeAccept, + "ignore": IngressClientCertificateModeIgnore, + "require": IngressClientCertificateModeRequire, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IngressClientCertificateMode(input) + return &out, nil +} + +type IngressTransportMethod string + +const ( + IngressTransportMethodAuto IngressTransportMethod = "auto" + IngressTransportMethodHTTP IngressTransportMethod = "http" + IngressTransportMethodHTTPTwo IngressTransportMethod = "http2" + IngressTransportMethodTcp IngressTransportMethod = "tcp" +) + +func PossibleValuesForIngressTransportMethod() []string { + return []string{ + string(IngressTransportMethodAuto), + string(IngressTransportMethodHTTP), + string(IngressTransportMethodHTTPTwo), + string(IngressTransportMethodTcp), + } +} + +func (s *IngressTransportMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIngressTransportMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIngressTransportMethod(input string) (*IngressTransportMethod, error) { + vals := map[string]IngressTransportMethod{ + "auto": IngressTransportMethodAuto, + "http": IngressTransportMethodHTTP, + "http2": IngressTransportMethodHTTPTwo, + "tcp": IngressTransportMethodTcp, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IngressTransportMethod(input) + return &out, nil +} + +type JobProvisioningState string + +const ( + JobProvisioningStateCanceled JobProvisioningState = "Canceled" + JobProvisioningStateDeleting JobProvisioningState = "Deleting" + JobProvisioningStateFailed JobProvisioningState = "Failed" + JobProvisioningStateInProgress JobProvisioningState = "InProgress" + JobProvisioningStateSucceeded JobProvisioningState = "Succeeded" +) + +func PossibleValuesForJobProvisioningState() []string { + return []string{ + string(JobProvisioningStateCanceled), + string(JobProvisioningStateDeleting), + string(JobProvisioningStateFailed), + string(JobProvisioningStateInProgress), + string(JobProvisioningStateSucceeded), + } +} + +func (s *JobProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobProvisioningState(input string) (*JobProvisioningState, error) { + vals := map[string]JobProvisioningState{ + "canceled": JobProvisioningStateCanceled, + "deleting": JobProvisioningStateDeleting, + "failed": JobProvisioningStateFailed, + "inprogress": JobProvisioningStateInProgress, + "succeeded": JobProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobProvisioningState(input) + return &out, nil +} + +type LogLevel string + +const ( + LogLevelDebug LogLevel = "debug" + LogLevelError LogLevel = "error" + LogLevelInfo LogLevel = "info" + LogLevelWarn LogLevel = "warn" +) + +func PossibleValuesForLogLevel() []string { + return []string{ + string(LogLevelDebug), + string(LogLevelError), + string(LogLevelInfo), + string(LogLevelWarn), + } +} + +func (s *LogLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLogLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLogLevel(input string) (*LogLevel, error) { + vals := map[string]LogLevel{ + "debug": LogLevelDebug, + "error": LogLevelError, + "info": LogLevelInfo, + "warn": LogLevelWarn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LogLevel(input) + return &out, nil +} + +type RevisionHealthState string + +const ( + RevisionHealthStateHealthy RevisionHealthState = "Healthy" + RevisionHealthStateNone RevisionHealthState = "None" + RevisionHealthStateUnhealthy RevisionHealthState = "Unhealthy" +) + +func PossibleValuesForRevisionHealthState() []string { + return []string{ + string(RevisionHealthStateHealthy), + string(RevisionHealthStateNone), + string(RevisionHealthStateUnhealthy), + } +} + +func (s *RevisionHealthState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionHealthState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionHealthState(input string) (*RevisionHealthState, error) { + vals := map[string]RevisionHealthState{ + "healthy": RevisionHealthStateHealthy, + "none": RevisionHealthStateNone, + "unhealthy": RevisionHealthStateUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionHealthState(input) + return &out, nil +} + +type RevisionProvisioningState string + +const ( + RevisionProvisioningStateDeprovisioned RevisionProvisioningState = "Deprovisioned" + RevisionProvisioningStateDeprovisioning RevisionProvisioningState = "Deprovisioning" + RevisionProvisioningStateFailed RevisionProvisioningState = "Failed" + RevisionProvisioningStateProvisioned RevisionProvisioningState = "Provisioned" + RevisionProvisioningStateProvisioning RevisionProvisioningState = "Provisioning" +) + +func PossibleValuesForRevisionProvisioningState() []string { + return []string{ + string(RevisionProvisioningStateDeprovisioned), + string(RevisionProvisioningStateDeprovisioning), + string(RevisionProvisioningStateFailed), + string(RevisionProvisioningStateProvisioned), + string(RevisionProvisioningStateProvisioning), + } +} + +func (s *RevisionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionProvisioningState(input string) (*RevisionProvisioningState, error) { + vals := map[string]RevisionProvisioningState{ + "deprovisioned": RevisionProvisioningStateDeprovisioned, + "deprovisioning": RevisionProvisioningStateDeprovisioning, + "failed": RevisionProvisioningStateFailed, + "provisioned": RevisionProvisioningStateProvisioned, + "provisioning": RevisionProvisioningStateProvisioning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionProvisioningState(input) + return &out, nil +} + +type RevisionRunningState string + +const ( + RevisionRunningStateDegraded RevisionRunningState = "Degraded" + RevisionRunningStateFailed RevisionRunningState = "Failed" + RevisionRunningStateProcessing RevisionRunningState = "Processing" + RevisionRunningStateRunning RevisionRunningState = "Running" + RevisionRunningStateStopped RevisionRunningState = "Stopped" + RevisionRunningStateUnknown RevisionRunningState = "Unknown" +) + +func PossibleValuesForRevisionRunningState() []string { + return []string{ + string(RevisionRunningStateDegraded), + string(RevisionRunningStateFailed), + string(RevisionRunningStateProcessing), + string(RevisionRunningStateRunning), + string(RevisionRunningStateStopped), + string(RevisionRunningStateUnknown), + } +} + +func (s *RevisionRunningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRevisionRunningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRevisionRunningState(input string) (*RevisionRunningState, error) { + vals := map[string]RevisionRunningState{ + "degraded": RevisionRunningStateDegraded, + "failed": RevisionRunningStateFailed, + "processing": RevisionRunningStateProcessing, + "running": RevisionRunningStateRunning, + "stopped": RevisionRunningStateStopped, + "unknown": RevisionRunningStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RevisionRunningState(input) + return &out, nil +} + +type Scheme string + +const ( + SchemeHTTP Scheme = "HTTP" + SchemeHTTPS Scheme = "HTTPS" +) + +func PossibleValuesForScheme() []string { + return []string{ + string(SchemeHTTP), + string(SchemeHTTPS), + } +} + +func (s *Scheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheme(input string) (*Scheme, error) { + vals := map[string]Scheme{ + "http": SchemeHTTP, + "https": SchemeHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Scheme(input) + return &out, nil +} + +type StorageType string + +const ( + StorageTypeAzureFile StorageType = "AzureFile" + StorageTypeEmptyDir StorageType = "EmptyDir" + StorageTypeNfsAzureFile StorageType = "NfsAzureFile" + StorageTypeSecret StorageType = "Secret" +) + +func PossibleValuesForStorageType() []string { + return []string{ + string(StorageTypeAzureFile), + string(StorageTypeEmptyDir), + string(StorageTypeNfsAzureFile), + string(StorageTypeSecret), + } +} + +func (s *StorageType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageType(input string) (*StorageType, error) { + vals := map[string]StorageType{ + "azurefile": StorageTypeAzureFile, + "emptydir": StorageTypeEmptyDir, + "nfsazurefile": StorageTypeNfsAzureFile, + "secret": StorageTypeSecret, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageType(input) + return &out, nil +} + +type TriggerType string + +const ( + TriggerTypeEvent TriggerType = "Event" + TriggerTypeManual TriggerType = "Manual" + TriggerTypeSchedule TriggerType = "Schedule" +) + +func PossibleValuesForTriggerType() []string { + return []string{ + string(TriggerTypeEvent), + string(TriggerTypeManual), + string(TriggerTypeSchedule), + } +} + +func (s *TriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggerType(input string) (*TriggerType, error) { + vals := map[string]TriggerType{ + "event": TriggerTypeEvent, + "manual": TriggerTypeManual, + "schedule": TriggerTypeSchedule, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggerType(input) + return &out, nil +} + +type Type string + +const ( + TypeLiveness Type = "Liveness" + TypeReadiness Type = "Readiness" + TypeStartup Type = "Startup" +) + +func PossibleValuesForType() []string { + return []string{ + string(TypeLiveness), + string(TypeReadiness), + string(TypeStartup), + } +} + +func (s *Type) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseType(input string) (*Type, error) { + vals := map[string]Type{ + "liveness": TypeLiveness, + "readiness": TypeReadiness, + "startup": TypeStartup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Type(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp.go new file mode 100644 index 00000000000..ac0b2cd3c60 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp.go @@ -0,0 +1,130 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppId{}) +} + +var _ resourceids.ResourceId = &ContainerAppId{} + +// ContainerAppId is a struct representing the Resource ID for a Container App +type ContainerAppId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string +} + +// NewContainerAppID returns a new ContainerAppId struct +func NewContainerAppID(subscriptionId string, resourceGroupName string, containerAppName string) ContainerAppId { + return ContainerAppId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + } +} + +// ParseContainerAppID parses 'input' into a ContainerAppId +func ParseContainerAppID(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppIDInsensitively parses 'input' case-insensitively into a ContainerAppId +// note: this method should only be used for API response data and not user input +func ParseContainerAppIDInsensitively(input string) (*ContainerAppId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + return nil +} + +// ValidateContainerAppID checks that 'input' can be parsed as a Container App ID +func ValidateContainerAppID(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 := ParseContainerAppID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App ID +func (id ContainerAppId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App ID +func (id ContainerAppId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + } +} + +// String returns a human-readable description of this Container App ID +func (id ContainerAppId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + } + return fmt.Sprintf("Container App (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp_test.go new file mode 100644 index 00000000000..7030ac8b313 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerapp_test.go @@ -0,0 +1,282 @@ +package diagnostics + +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 = &ContainerAppId{} + +func TestNewContainerAppID(t *testing.T) { + id := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } +} + +func TestFormatContainerAppID(t *testing.T) { + actual := NewContainerAppID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestParseContainerAppIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Expected: &ContainerAppId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + } +} + +func TestSegmentsForContainerAppId(t *testing.T) { + segments := ContainerAppId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppId 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/containerapps/2025-01-01/diagnostics/id_containerappdetector.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector.go new file mode 100644 index 00000000000..d666801e302 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector.go @@ -0,0 +1,139 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ContainerAppDetectorId{}) +} + +var _ resourceids.ResourceId = &ContainerAppDetectorId{} + +// ContainerAppDetectorId is a struct representing the Resource ID for a Container App Detector +type ContainerAppDetectorId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + DetectorName string +} + +// NewContainerAppDetectorID returns a new ContainerAppDetectorId struct +func NewContainerAppDetectorID(subscriptionId string, resourceGroupName string, containerAppName string, detectorName string) ContainerAppDetectorId { + return ContainerAppDetectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + DetectorName: detectorName, + } +} + +// ParseContainerAppDetectorID parses 'input' into a ContainerAppDetectorId +func ParseContainerAppDetectorID(input string) (*ContainerAppDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppDetectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContainerAppDetectorIDInsensitively parses 'input' case-insensitively into a ContainerAppDetectorId +// note: this method should only be used for API response data and not user input +func ParseContainerAppDetectorIDInsensitively(input string) (*ContainerAppDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContainerAppDetectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContainerAppDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContainerAppDetectorId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.DetectorName, ok = input.Parsed["detectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorName", input) + } + + return nil +} + +// ValidateContainerAppDetectorID checks that 'input' can be parsed as a Container App Detector ID +func ValidateContainerAppDetectorID(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 := ParseContainerAppDetectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Container App Detector ID +func (id ContainerAppDetectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/detectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.DetectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Container App Detector ID +func (id ContainerAppDetectorId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticDetectors", "detectors", "detectors"), + resourceids.UserSpecifiedSegment("detectorName", "detectorName"), + } +} + +// String returns a human-readable description of this Container App Detector ID +func (id ContainerAppDetectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Detector Name: %q", id.DetectorName), + } + return fmt.Sprintf("Container App Detector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector_test.go new file mode 100644 index 00000000000..7035f244fc4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_containerappdetector_test.go @@ -0,0 +1,327 @@ +package diagnostics + +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 = &ContainerAppDetectorId{} + +func TestNewContainerAppDetectorID(t *testing.T) { + id := NewContainerAppDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "detectorName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.DetectorName != "detectorName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorName'", id.DetectorName, "detectorName") + } +} + +func TestFormatContainerAppDetectorID(t *testing.T) { + actual := NewContainerAppDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "detectorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContainerAppDetectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName", + Expected: &ContainerAppDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppDetectorID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestParseContainerAppDetectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContainerAppDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName", + Expected: &ContainerAppDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectors/detectorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRs/dEtEcToRnAmE", + Expected: &ContainerAppDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + DetectorName: "dEtEcToRnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRs/dEtEcToRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContainerAppDetectorIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestSegmentsForContainerAppDetectorId(t *testing.T) { + segments := ContainerAppDetectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContainerAppDetectorId 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/containerapps/2025-01-01/diagnostics/id_detector.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_detector.go new file mode 100644 index 00000000000..c569bdd3bdb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_detector.go @@ -0,0 +1,139 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DetectorId{}) +} + +var _ resourceids.ResourceId = &DetectorId{} + +// DetectorId is a struct representing the Resource ID for a Detector +type DetectorId struct { + SubscriptionId string + ResourceGroupName string + JobName string + DetectorName string +} + +// NewDetectorID returns a new DetectorId struct +func NewDetectorID(subscriptionId string, resourceGroupName string, jobName string, detectorName string) DetectorId { + return DetectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + DetectorName: detectorName, + } +} + +// ParseDetectorID parses 'input' into a DetectorId +func ParseDetectorID(input string) (*DetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDetectorIDInsensitively parses 'input' case-insensitively into a DetectorId +// note: this method should only be used for API response data and not user input +func ParseDetectorIDInsensitively(input string) (*DetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DetectorId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.DetectorName, ok = input.Parsed["detectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorName", input) + } + + return nil +} + +// ValidateDetectorID checks that 'input' can be parsed as a Detector ID +func ValidateDetectorID(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 := ParseDetectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Detector ID +func (id DetectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s/detectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName, id.DetectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Detector ID +func (id DetectorId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticDetectors", "detectors", "detectors"), + resourceids.UserSpecifiedSegment("detectorName", "detectorName"), + } +} + +// String returns a human-readable description of this Detector ID +func (id DetectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Detector Name: %q", id.DetectorName), + } + return fmt.Sprintf("Detector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_detector_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_detector_test.go new file mode 100644 index 00000000000..436d965bfe2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_detector_test.go @@ -0,0 +1,327 @@ +package diagnostics + +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 = &DetectorId{} + +func TestNewDetectorID(t *testing.T) { + id := NewDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.DetectorName != "detectorName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorName'", id.DetectorName, "detectorName") + } +} + +func TestFormatDetectorID(t *testing.T) { + actual := NewDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDetectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName", + Expected: &DetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestParseDetectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName", + Expected: &DetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRs/dEtEcToRnAmE", + Expected: &DetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + DetectorName: "dEtEcToRnAmE", + }, + }, + { + // 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.aPp/jObS/jObNaMe/dEtEcToRs/dEtEcToRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestSegmentsForDetectorId(t *testing.T) { + segments := DetectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DetectorId 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/containerapps/2025-01-01/diagnostics/id_detectorproperty.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty.go new file mode 100644 index 00000000000..c04bd05517d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty.go @@ -0,0 +1,139 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DetectorPropertyId{}) +} + +var _ resourceids.ResourceId = &DetectorPropertyId{} + +// DetectorPropertyId is a struct representing the Resource ID for a Detector Property +type DetectorPropertyId struct { + SubscriptionId string + ResourceGroupName string + JobName string + DetectorPropertyName string +} + +// NewDetectorPropertyID returns a new DetectorPropertyId struct +func NewDetectorPropertyID(subscriptionId string, resourceGroupName string, jobName string, detectorPropertyName string) DetectorPropertyId { + return DetectorPropertyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + DetectorPropertyName: detectorPropertyName, + } +} + +// ParseDetectorPropertyID parses 'input' into a DetectorPropertyId +func ParseDetectorPropertyID(input string) (*DetectorPropertyId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorPropertyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorPropertyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDetectorPropertyIDInsensitively parses 'input' case-insensitively into a DetectorPropertyId +// note: this method should only be used for API response data and not user input +func ParseDetectorPropertyIDInsensitively(input string) (*DetectorPropertyId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorPropertyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorPropertyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DetectorPropertyId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.DetectorPropertyName, ok = input.Parsed["detectorPropertyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorPropertyName", input) + } + + return nil +} + +// ValidateDetectorPropertyID checks that 'input' can be parsed as a Detector Property ID +func ValidateDetectorPropertyID(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 := ParseDetectorPropertyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Detector Property ID +func (id DetectorPropertyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s/detectorProperties/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName, id.DetectorPropertyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Detector Property ID +func (id DetectorPropertyId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticDetectorProperties", "detectorProperties", "detectorProperties"), + resourceids.UserSpecifiedSegment("detectorPropertyName", "detectorPropertyName"), + } +} + +// String returns a human-readable description of this Detector Property ID +func (id DetectorPropertyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Detector Property Name: %q", id.DetectorPropertyName), + } + return fmt.Sprintf("Detector Property (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty_test.go new file mode 100644 index 00000000000..4910029dab6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_detectorproperty_test.go @@ -0,0 +1,327 @@ +package diagnostics + +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 = &DetectorPropertyId{} + +func TestNewDetectorPropertyID(t *testing.T) { + id := NewDetectorPropertyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorPropertyName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.DetectorPropertyName != "detectorPropertyName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorPropertyName'", id.DetectorPropertyName, "detectorPropertyName") + } +} + +func TestFormatDetectorPropertyID(t *testing.T) { + actual := NewDetectorPropertyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorPropertyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDetectorPropertyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorPropertyId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName", + Expected: &DetectorPropertyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorPropertyName: "detectorPropertyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorPropertyID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorPropertyName != v.Expected.DetectorPropertyName { + t.Fatalf("Expected %q but got %q for DetectorPropertyName", v.Expected.DetectorPropertyName, actual.DetectorPropertyName) + } + + } +} + +func TestParseDetectorPropertyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorPropertyId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRpRoPeRtIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName", + Expected: &DetectorPropertyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorPropertyName: "detectorPropertyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRpRoPeRtIeS/dEtEcToRpRoPeRtYnAmE", + Expected: &DetectorPropertyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + DetectorPropertyName: "dEtEcToRpRoPeRtYnAmE", + }, + }, + { + // 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.aPp/jObS/jObNaMe/dEtEcToRpRoPeRtIeS/dEtEcToRpRoPeRtYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorPropertyIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorPropertyName != v.Expected.DetectorPropertyName { + t.Fatalf("Expected %q but got %q for DetectorPropertyName", v.Expected.DetectorPropertyName, actual.DetectorPropertyName) + } + + } +} + +func TestSegmentsForDetectorPropertyId(t *testing.T) { + segments := DetectorPropertyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DetectorPropertyId 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/containerapps/2025-01-01/diagnostics/id_job.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_job.go new file mode 100644 index 00000000000..e6acffeb951 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_job.go @@ -0,0 +1,130 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobId{}) +} + +var _ resourceids.ResourceId = &JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + return nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_job_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_job_test.go new file mode 100644 index 00000000000..401dc9344b3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_job_test.go @@ -0,0 +1,282 @@ +package diagnostics + +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 = &JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + }, + }, + { + // 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.aPp/jObS/jObNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/containerapps/2025-01-01/diagnostics/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment.go new file mode 100644 index 00000000000..9462d806945 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment.go @@ -0,0 +1,130 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment_test.go new file mode 100644 index 00000000000..755e224d05d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package diagnostics + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector.go new file mode 100644 index 00000000000..d6d5c7c0e39 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector.go @@ -0,0 +1,139 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentDetectorId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentDetectorId{} + +// ManagedEnvironmentDetectorId is a struct representing the Resource ID for a Managed Environment Detector +type ManagedEnvironmentDetectorId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + DetectorName string +} + +// NewManagedEnvironmentDetectorID returns a new ManagedEnvironmentDetectorId struct +func NewManagedEnvironmentDetectorID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, detectorName string) ManagedEnvironmentDetectorId { + return ManagedEnvironmentDetectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + DetectorName: detectorName, + } +} + +// ParseManagedEnvironmentDetectorID parses 'input' into a ManagedEnvironmentDetectorId +func ParseManagedEnvironmentDetectorID(input string) (*ManagedEnvironmentDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentDetectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentDetectorIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentDetectorId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentDetectorIDInsensitively(input string) (*ManagedEnvironmentDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentDetectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentDetectorId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.DetectorName, ok = input.Parsed["detectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorName", input) + } + + return nil +} + +// ValidateManagedEnvironmentDetectorID checks that 'input' can be parsed as a Managed Environment Detector ID +func ValidateManagedEnvironmentDetectorID(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 := ParseManagedEnvironmentDetectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment Detector ID +func (id ManagedEnvironmentDetectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/detectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.DetectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment Detector ID +func (id ManagedEnvironmentDetectorId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticDetectors", "detectors", "detectors"), + resourceids.UserSpecifiedSegment("detectorName", "detectorName"), + } +} + +// String returns a human-readable description of this Managed Environment Detector ID +func (id ManagedEnvironmentDetectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Detector Name: %q", id.DetectorName), + } + return fmt.Sprintf("Managed Environment Detector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector_test.go new file mode 100644 index 00000000000..f42632fecd1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_managedenvironmentdetector_test.go @@ -0,0 +1,327 @@ +package diagnostics + +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 = &ManagedEnvironmentDetectorId{} + +func TestNewManagedEnvironmentDetectorID(t *testing.T) { + id := NewManagedEnvironmentDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "detectorName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.DetectorName != "detectorName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorName'", id.DetectorName, "detectorName") + } +} + +func TestFormatManagedEnvironmentDetectorID(t *testing.T) { + actual := NewManagedEnvironmentDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "detectorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentDetectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName", + Expected: &ManagedEnvironmentDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentDetectorID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestParseManagedEnvironmentDetectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dEtEcToRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName", + Expected: &ManagedEnvironmentDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dEtEcToRs/dEtEcToRnAmE", + Expected: &ManagedEnvironmentDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + DetectorName: "dEtEcToRnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dEtEcToRs/dEtEcToRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentDetectorIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestSegmentsForManagedEnvironmentDetectorId(t *testing.T) { + segments := ManagedEnvironmentDetectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentDetectorId 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/containerapps/2025-01-01/diagnostics/id_revisionsapirevision.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision.go new file mode 100644 index 00000000000..50e75e3e19d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision.go @@ -0,0 +1,141 @@ +package diagnostics + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RevisionsApiRevisionId{}) +} + +var _ resourceids.ResourceId = &RevisionsApiRevisionId{} + +// RevisionsApiRevisionId is a struct representing the Resource ID for a Revisions Api Revision +type RevisionsApiRevisionId struct { + SubscriptionId string + ResourceGroupName string + ContainerAppName string + RevisionName string +} + +// NewRevisionsApiRevisionID returns a new RevisionsApiRevisionId struct +func NewRevisionsApiRevisionID(subscriptionId string, resourceGroupName string, containerAppName string, revisionName string) RevisionsApiRevisionId { + return RevisionsApiRevisionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ContainerAppName: containerAppName, + RevisionName: revisionName, + } +} + +// ParseRevisionsApiRevisionID parses 'input' into a RevisionsApiRevisionId +func ParseRevisionsApiRevisionID(input string) (*RevisionsApiRevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionsApiRevisionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionsApiRevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRevisionsApiRevisionIDInsensitively parses 'input' case-insensitively into a RevisionsApiRevisionId +// note: this method should only be used for API response data and not user input +func ParseRevisionsApiRevisionIDInsensitively(input string) (*RevisionsApiRevisionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RevisionsApiRevisionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RevisionsApiRevisionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RevisionsApiRevisionId) 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.ContainerAppName, ok = input.Parsed["containerAppName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "containerAppName", input) + } + + if id.RevisionName, ok = input.Parsed["revisionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "revisionName", input) + } + + return nil +} + +// ValidateRevisionsApiRevisionID checks that 'input' can be parsed as a Revisions Api Revision ID +func ValidateRevisionsApiRevisionID(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 := ParseRevisionsApiRevisionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Revisions Api Revision ID +func (id RevisionsApiRevisionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/containerApps/%s/detectorProperties/revisionsApi/revisions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ContainerAppName, id.RevisionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Revisions Api Revision ID +func (id RevisionsApiRevisionId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticContainerApps", "containerApps", "containerApps"), + resourceids.UserSpecifiedSegment("containerAppName", "containerAppName"), + resourceids.StaticSegment("staticDetectorProperties", "detectorProperties", "detectorProperties"), + resourceids.StaticSegment("staticRevisionsApi", "revisionsApi", "revisionsApi"), + resourceids.StaticSegment("staticRevisions", "revisions", "revisions"), + resourceids.UserSpecifiedSegment("revisionName", "revisionName"), + } +} + +// String returns a human-readable description of this Revisions Api Revision ID +func (id RevisionsApiRevisionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Container App Name: %q", id.ContainerAppName), + fmt.Sprintf("Revision Name: %q", id.RevisionName), + } + return fmt.Sprintf("Revisions Api Revision (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision_test.go b/resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision_test.go new file mode 100644 index 00000000000..1956715d4c9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/id_revisionsapirevision_test.go @@ -0,0 +1,357 @@ +package diagnostics + +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 = &RevisionsApiRevisionId{} + +func TestNewRevisionsApiRevisionID(t *testing.T) { + id := NewRevisionsApiRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName") + + 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.ContainerAppName != "containerAppName" { + t.Fatalf("Expected %q but got %q for Segment 'ContainerAppName'", id.ContainerAppName, "containerAppName") + } + + if id.RevisionName != "revisionName" { + t.Fatalf("Expected %q but got %q for Segment 'RevisionName'", id.RevisionName, "revisionName") + } +} + +func TestFormatRevisionsApiRevisionID(t *testing.T) { + actual := NewRevisionsApiRevisionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "containerAppName", "revisionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRevisionsApiRevisionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionsApiRevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName", + Expected: &RevisionsApiRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionsApiRevisionID(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestParseRevisionsApiRevisionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RevisionsApiRevisionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI/rEvIsIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName", + Expected: &RevisionsApiRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ContainerAppName: "containerAppName", + RevisionName: "revisionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/containerApps/containerAppName/detectorProperties/revisionsApi/revisions/revisionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI/rEvIsIoNs/rEvIsIoNnAmE", + Expected: &RevisionsApiRevisionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ContainerAppName: "cOnTaInErApPnAmE", + RevisionName: "rEvIsIoNnAmE", + }, + }, + { + // 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.aPp/cOnTaInErApPs/cOnTaInErApPnAmE/dEtEcToRpRoPeRtIeS/rEvIsIoNsApI/rEvIsIoNs/rEvIsIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRevisionsApiRevisionIDInsensitively(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.ContainerAppName != v.Expected.ContainerAppName { + t.Fatalf("Expected %q but got %q for ContainerAppName", v.Expected.ContainerAppName, actual.ContainerAppName) + } + + if actual.RevisionName != v.Expected.RevisionName { + t.Fatalf("Expected %q but got %q for RevisionName", v.Expected.RevisionName, actual.RevisionName) + } + + } +} + +func TestSegmentsForRevisionsApiRevisionId(t *testing.T) { + segments := RevisionsApiRevisionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RevisionsApiRevisionId 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/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetdetector.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetdetector.go new file mode 100644 index 00000000000..9a2a1c43e1f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetdetector.go @@ -0,0 +1,53 @@ +package diagnostics + +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 ContainerAppsDiagnosticsGetDetectorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Diagnostics +} + +// ContainerAppsDiagnosticsGetDetector ... +func (c DiagnosticsClient) ContainerAppsDiagnosticsGetDetector(ctx context.Context, id ContainerAppDetectorId) (result ContainerAppsDiagnosticsGetDetectorOperationResponse, 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 Diagnostics + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetrevision.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetrevision.go new file mode 100644 index 00000000000..af6794d14ab --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetrevision.go @@ -0,0 +1,53 @@ +package diagnostics + +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 ContainerAppsDiagnosticsGetRevisionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Revision +} + +// ContainerAppsDiagnosticsGetRevision ... +func (c DiagnosticsClient) ContainerAppsDiagnosticsGetRevision(ctx context.Context, id RevisionsApiRevisionId) (result ContainerAppsDiagnosticsGetRevisionOperationResponse, 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 Revision + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetroot.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetroot.go new file mode 100644 index 00000000000..ec30717f8d0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticsgetroot.go @@ -0,0 +1,54 @@ +package diagnostics + +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 ContainerAppsDiagnosticsGetRootOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ContainerApp +} + +// ContainerAppsDiagnosticsGetRoot ... +func (c DiagnosticsClient) ContainerAppsDiagnosticsGetRoot(ctx context.Context, id ContainerAppId) (result ContainerAppsDiagnosticsGetRootOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/detectorProperties/rootApi", 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 ContainerApp + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistdetectors.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistdetectors.go new file mode 100644 index 00000000000..9a66dd775d5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistdetectors.go @@ -0,0 +1,105 @@ +package diagnostics + +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 ContainerAppsDiagnosticsListDetectorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Diagnostics +} + +type ContainerAppsDiagnosticsListDetectorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Diagnostics +} + +type ContainerAppsDiagnosticsListDetectorsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ContainerAppsDiagnosticsListDetectorsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ContainerAppsDiagnosticsListDetectors ... +func (c DiagnosticsClient) ContainerAppsDiagnosticsListDetectors(ctx context.Context, id ContainerAppId) (result ContainerAppsDiagnosticsListDetectorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ContainerAppsDiagnosticsListDetectorsCustomPager{}, + Path: fmt.Sprintf("%s/detectors", 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 *[]Diagnostics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ContainerAppsDiagnosticsListDetectorsComplete retrieves all the results into a single object +func (c DiagnosticsClient) ContainerAppsDiagnosticsListDetectorsComplete(ctx context.Context, id ContainerAppId) (ContainerAppsDiagnosticsListDetectorsCompleteResult, error) { + return c.ContainerAppsDiagnosticsListDetectorsCompleteMatchingPredicate(ctx, id, DiagnosticsOperationPredicate{}) +} + +// ContainerAppsDiagnosticsListDetectorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DiagnosticsClient) ContainerAppsDiagnosticsListDetectorsCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, predicate DiagnosticsOperationPredicate) (result ContainerAppsDiagnosticsListDetectorsCompleteResult, err error) { + items := make([]Diagnostics, 0) + + resp, err := c.ContainerAppsDiagnosticsListDetectors(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ContainerAppsDiagnosticsListDetectorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistrevisions.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistrevisions.go new file mode 100644 index 00000000000..96e393b50eb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_containerappsdiagnosticslistrevisions.go @@ -0,0 +1,134 @@ +package diagnostics + +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 ContainerAppsDiagnosticsListRevisionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Revision +} + +type ContainerAppsDiagnosticsListRevisionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Revision +} + +type ContainerAppsDiagnosticsListRevisionsOperationOptions struct { + Filter *string +} + +func DefaultContainerAppsDiagnosticsListRevisionsOperationOptions() ContainerAppsDiagnosticsListRevisionsOperationOptions { + return ContainerAppsDiagnosticsListRevisionsOperationOptions{} +} + +func (o ContainerAppsDiagnosticsListRevisionsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ContainerAppsDiagnosticsListRevisionsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ContainerAppsDiagnosticsListRevisionsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ContainerAppsDiagnosticsListRevisionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ContainerAppsDiagnosticsListRevisionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ContainerAppsDiagnosticsListRevisions ... +func (c DiagnosticsClient) ContainerAppsDiagnosticsListRevisions(ctx context.Context, id ContainerAppId, options ContainerAppsDiagnosticsListRevisionsOperationOptions) (result ContainerAppsDiagnosticsListRevisionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ContainerAppsDiagnosticsListRevisionsCustomPager{}, + Path: fmt.Sprintf("%s/detectorProperties/revisionsApi/revisions", 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 *[]Revision `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ContainerAppsDiagnosticsListRevisionsComplete retrieves all the results into a single object +func (c DiagnosticsClient) ContainerAppsDiagnosticsListRevisionsComplete(ctx context.Context, id ContainerAppId, options ContainerAppsDiagnosticsListRevisionsOperationOptions) (ContainerAppsDiagnosticsListRevisionsCompleteResult, error) { + return c.ContainerAppsDiagnosticsListRevisionsCompleteMatchingPredicate(ctx, id, options, RevisionOperationPredicate{}) +} + +// ContainerAppsDiagnosticsListRevisionsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DiagnosticsClient) ContainerAppsDiagnosticsListRevisionsCompleteMatchingPredicate(ctx context.Context, id ContainerAppId, options ContainerAppsDiagnosticsListRevisionsOperationOptions, predicate RevisionOperationPredicate) (result ContainerAppsDiagnosticsListRevisionsCompleteResult, err error) { + items := make([]Revision, 0) + + resp, err := c.ContainerAppsDiagnosticsListRevisions(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ContainerAppsDiagnosticsListRevisionsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_jobsgetdetector.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_jobsgetdetector.go new file mode 100644 index 00000000000..e14b69e502e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_jobsgetdetector.go @@ -0,0 +1,53 @@ +package diagnostics + +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 JobsGetDetectorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Diagnostics +} + +// JobsGetDetector ... +func (c DiagnosticsClient) JobsGetDetector(ctx context.Context, id DetectorId) (result JobsGetDetectorOperationResponse, 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 Diagnostics + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_jobslistdetectors.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_jobslistdetectors.go new file mode 100644 index 00000000000..3e8e418b987 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_jobslistdetectors.go @@ -0,0 +1,105 @@ +package diagnostics + +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 JobsListDetectorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Diagnostics +} + +type JobsListDetectorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Diagnostics +} + +type JobsListDetectorsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *JobsListDetectorsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// JobsListDetectors ... +func (c DiagnosticsClient) JobsListDetectors(ctx context.Context, id JobId) (result JobsListDetectorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &JobsListDetectorsCustomPager{}, + Path: fmt.Sprintf("%s/detectors", 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 *[]Diagnostics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// JobsListDetectorsComplete retrieves all the results into a single object +func (c DiagnosticsClient) JobsListDetectorsComplete(ctx context.Context, id JobId) (JobsListDetectorsCompleteResult, error) { + return c.JobsListDetectorsCompleteMatchingPredicate(ctx, id, DiagnosticsOperationPredicate{}) +} + +// JobsListDetectorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DiagnosticsClient) JobsListDetectorsCompleteMatchingPredicate(ctx context.Context, id JobId, predicate DiagnosticsOperationPredicate) (result JobsListDetectorsCompleteResult, err error) { + items := make([]Diagnostics, 0) + + resp, err := c.JobsListDetectors(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = JobsListDetectorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_jobsproxyget.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_jobsproxyget.go new file mode 100644 index 00000000000..73b67337e25 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_jobsproxyget.go @@ -0,0 +1,53 @@ +package diagnostics + +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 JobsProxyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Job +} + +// JobsProxyGet ... +func (c DiagnosticsClient) JobsProxyGet(ctx context.Context, id DetectorPropertyId) (result JobsProxyGetOperationResponse, 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 Job + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticsgetdetector.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticsgetdetector.go new file mode 100644 index 00000000000..fe513db6b31 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticsgetdetector.go @@ -0,0 +1,53 @@ +package diagnostics + +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 ManagedEnvironmentDiagnosticsGetDetectorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Diagnostics +} + +// ManagedEnvironmentDiagnosticsGetDetector ... +func (c DiagnosticsClient) ManagedEnvironmentDiagnosticsGetDetector(ctx context.Context, id ManagedEnvironmentDetectorId) (result ManagedEnvironmentDiagnosticsGetDetectorOperationResponse, 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 Diagnostics + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticslistdetectors.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticslistdetectors.go new file mode 100644 index 00000000000..f172ca2d567 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentdiagnosticslistdetectors.go @@ -0,0 +1,105 @@ +package diagnostics + +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 ManagedEnvironmentDiagnosticsListDetectorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Diagnostics +} + +type ManagedEnvironmentDiagnosticsListDetectorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Diagnostics +} + +type ManagedEnvironmentDiagnosticsListDetectorsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ManagedEnvironmentDiagnosticsListDetectorsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ManagedEnvironmentDiagnosticsListDetectors ... +func (c DiagnosticsClient) ManagedEnvironmentDiagnosticsListDetectors(ctx context.Context, id ManagedEnvironmentId) (result ManagedEnvironmentDiagnosticsListDetectorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ManagedEnvironmentDiagnosticsListDetectorsCustomPager{}, + Path: fmt.Sprintf("%s/detectors", 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 *[]Diagnostics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ManagedEnvironmentDiagnosticsListDetectorsComplete retrieves all the results into a single object +func (c DiagnosticsClient) ManagedEnvironmentDiagnosticsListDetectorsComplete(ctx context.Context, id ManagedEnvironmentId) (ManagedEnvironmentDiagnosticsListDetectorsCompleteResult, error) { + return c.ManagedEnvironmentDiagnosticsListDetectorsCompleteMatchingPredicate(ctx, id, DiagnosticsOperationPredicate{}) +} + +// ManagedEnvironmentDiagnosticsListDetectorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DiagnosticsClient) ManagedEnvironmentDiagnosticsListDetectorsCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate DiagnosticsOperationPredicate) (result ManagedEnvironmentDiagnosticsListDetectorsCompleteResult, err error) { + items := make([]Diagnostics, 0) + + resp, err := c.ManagedEnvironmentDiagnosticsListDetectors(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ManagedEnvironmentDiagnosticsListDetectorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentsdiagnosticsgetroot.go b/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentsdiagnosticsgetroot.go new file mode 100644 index 00000000000..2c03f97f04c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/method_managedenvironmentsdiagnosticsgetroot.go @@ -0,0 +1,54 @@ +package diagnostics + +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 ManagedEnvironmentsDiagnosticsGetRootOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedEnvironment +} + +// ManagedEnvironmentsDiagnosticsGetRoot ... +func (c DiagnosticsClient) ManagedEnvironmentsDiagnosticsGetRoot(ctx context.Context, id ManagedEnvironmentId) (result ManagedEnvironmentsDiagnosticsGetRootOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/detectorProperties/rootApi", 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 ManagedEnvironment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_applogsconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_applogsconfiguration.go new file mode 100644 index 00000000000..90fe9ced93f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_applogsconfiguration.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AppLogsConfiguration struct { + Destination *string `json:"destination,omitempty"` + LogAnalyticsConfiguration *LogAnalyticsConfiguration `json:"logAnalyticsConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_basecontainer.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_basecontainer.go new file mode 100644 index 00000000000..bf26a0fd70f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_basecontainer.go @@ -0,0 +1,14 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseContainer struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_certificatekeyvaultproperties.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_certificatekeyvaultproperties.go new file mode 100644 index 00000000000..d481a5d6359 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_certificatekeyvaultproperties.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateKeyVaultProperties struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_configuration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_configuration.go new file mode 100644 index 00000000000..077843798ae --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_configuration.go @@ -0,0 +1,16 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Configuration struct { + ActiveRevisionsMode *ActiveRevisionsMode `json:"activeRevisionsMode,omitempty"` + Dapr *Dapr `json:"dapr,omitempty"` + IdentitySettings *[]IdentitySettings `json:"identitySettings,omitempty"` + Ingress *Ingress `json:"ingress,omitempty"` + MaxInactiveRevisions *int64 `json:"maxInactiveRevisions,omitempty"` + Registries *[]RegistryCredentials `json:"registries,omitempty"` + Runtime *Runtime `json:"runtime,omitempty"` + Secrets *[]Secret `json:"secrets,omitempty"` + Service *Service `json:"service,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_container.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_container.go new file mode 100644 index 00000000000..7f3e49527c3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_container.go @@ -0,0 +1,15 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Container struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Probes *[]ContainerAppProbe `json:"probes,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_containerapp.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerapp.go new file mode 100644 index 00000000000..85fafde1e7c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerapp.go @@ -0,0 +1,22 @@ +package diagnostics + +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 ContainerApp struct { + ExtendedLocation *ExtendedLocation `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ContainerAppProperties `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/containerapps/2025-01-01/diagnostics/model_containerappprobe.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobe.go new file mode 100644 index 00000000000..062f3583dc5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobe.go @@ -0,0 +1,16 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbe struct { + FailureThreshold *int64 `json:"failureThreshold,omitempty"` + HTTPGet *ContainerAppProbeHTTPGet `json:"httpGet,omitempty"` + InitialDelaySeconds *int64 `json:"initialDelaySeconds,omitempty"` + PeriodSeconds *int64 `json:"periodSeconds,omitempty"` + SuccessThreshold *int64 `json:"successThreshold,omitempty"` + TcpSocket *ContainerAppProbeTcpSocket `json:"tcpSocket,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"` + Type *Type `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpget.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpget.go new file mode 100644 index 00000000000..00fbe4d674c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpget.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGet struct { + HTTPHeaders *[]ContainerAppProbeHTTPGetHTTPHeadersInlined `json:"httpHeaders,omitempty"` + Host *string `json:"host,omitempty"` + Path *string `json:"path,omitempty"` + Port int64 `json:"port"` + Scheme *Scheme `json:"scheme,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpgethttpheadersinlined.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpgethttpheadersinlined.go new file mode 100644 index 00000000000..c2be2e96951 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobehttpgethttpheadersinlined.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGetHTTPHeadersInlined struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobetcpsocket.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobetcpsocket.go new file mode 100644 index 00000000000..0d96b8163d7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappprobetcpsocket.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeTcpSocket struct { + Host *string `json:"host,omitempty"` + Port int64 `json:"port"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappproperties.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappproperties.go new file mode 100644 index 00000000000..e86abcdc503 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerappproperties.go @@ -0,0 +1,20 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProperties struct { + Configuration *Configuration `json:"configuration,omitempty"` + CustomDomainVerificationId *string `json:"customDomainVerificationId,omitempty"` + EnvironmentId *string `json:"environmentId,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + LatestReadyRevisionName *string `json:"latestReadyRevisionName,omitempty"` + LatestRevisionFqdn *string `json:"latestRevisionFqdn,omitempty"` + LatestRevisionName *string `json:"latestRevisionName,omitempty"` + ManagedEnvironmentId *string `json:"managedEnvironmentId,omitempty"` + OutboundIPAddresses *[]string `json:"outboundIpAddresses,omitempty"` + ProvisioningState *ContainerAppProvisioningState `json:"provisioningState,omitempty"` + RunningStatus *ContainerAppRunningStatus `json:"runningStatus,omitempty"` + Template *Template `json:"template,omitempty"` + WorkloadProfileName *string `json:"workloadProfileName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_containerresources.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerresources.go new file mode 100644 index 00000000000..91f243cb51b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_containerresources.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerResources struct { + Cpu *float64 `json:"cpu,omitempty"` + EphemeralStorage *string `json:"ephemeralStorage,omitempty"` + Memory *string `json:"memory,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_corspolicy.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_corspolicy.go new file mode 100644 index 00000000000..6fe8eb6bfb6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_corspolicy.go @@ -0,0 +1,13 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CorsPolicy struct { + AllowCredentials *bool `json:"allowCredentials,omitempty"` + AllowedHeaders *[]string `json:"allowedHeaders,omitempty"` + AllowedMethods *[]string `json:"allowedMethods,omitempty"` + AllowedOrigins []string `json:"allowedOrigins"` + ExposeHeaders *[]string `json:"exposeHeaders,omitempty"` + MaxAge *int64 `json:"maxAge,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_customdomain.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_customdomain.go new file mode 100644 index 00000000000..060f10bbf3c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_customdomain.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomDomain struct { + BindingType *BindingType `json:"bindingType,omitempty"` + CertificateId *string `json:"certificateId,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_customdomainconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_customdomainconfiguration.go new file mode 100644 index 00000000000..6fe5efc1d5e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_customdomainconfiguration.go @@ -0,0 +1,33 @@ +package diagnostics + +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 CustomDomainConfiguration struct { + CertificateKeyVaultProperties *CertificateKeyVaultProperties `json:"certificateKeyVaultProperties,omitempty"` + CertificatePassword *string `json:"certificatePassword,omitempty"` + CertificateValue *string `json:"certificateValue,omitempty"` + CustomDomainVerificationId *string `json:"customDomainVerificationId,omitempty"` + DnsSuffix *string `json:"dnsSuffix,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` +} + +func (o *CustomDomainConfiguration) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CustomDomainConfiguration) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_customscalerule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_customscalerule.go new file mode 100644 index 00000000000..1e03883bb71 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_customscalerule.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_dapr.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_dapr.go new file mode 100644 index 00000000000..665efbc4e83 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_dapr.go @@ -0,0 +1,15 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Dapr struct { + AppId *string `json:"appId,omitempty"` + AppPort *int64 `json:"appPort,omitempty"` + AppProtocol *AppProtocol `json:"appProtocol,omitempty"` + EnableApiLogging *bool `json:"enableApiLogging,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + HTTPMaxRequestSize *int64 `json:"httpMaxRequestSize,omitempty"` + HTTPReadBufferSize *int64 `json:"httpReadBufferSize,omitempty"` + LogLevel *LogLevel `json:"logLevel,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_daprconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_daprconfiguration.go new file mode 100644 index 00000000000..512609602f3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_daprconfiguration.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprConfiguration struct { + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadata.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadata.go new file mode 100644 index 00000000000..d585c441cf3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadata.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadata struct { + PropertyBag *[]DiagnosticDataProviderMetadataPropertyBagInlined `json:"propertyBag,omitempty"` + ProviderName *string `json:"providerName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadatapropertybaginlined.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadatapropertybaginlined.go new file mode 100644 index 00000000000..ba23db4513b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdataprovidermetadatapropertybaginlined.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadataPropertyBagInlined struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponsecolumn.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponsecolumn.go new file mode 100644 index 00000000000..0b9744e7c04 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponsecolumn.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseColumn struct { + ColumnName *string `json:"columnName,omitempty"` + ColumnType *string `json:"columnType,omitempty"` + DataType *string `json:"dataType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponseobject.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponseobject.go new file mode 100644 index 00000000000..2da1abb2602 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticdatatableresponseobject.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseObject struct { + Columns *[]DiagnosticDataTableResponseColumn `json:"columns,omitempty"` + Rows *[]interface{} `json:"rows,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticrendering.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticrendering.go new file mode 100644 index 00000000000..16b1a2ff8c9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticrendering.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticRendering struct { + Description *string `json:"description,omitempty"` + IsVisible *bool `json:"isVisible,omitempty"` + Title *string `json:"title,omitempty"` + Type *int64 `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnostics.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnostics.go new file mode 100644 index 00000000000..ff162b54cf4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnostics.go @@ -0,0 +1,16 @@ +package diagnostics + +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 Diagnostics struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdataapiresponse.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdataapiresponse.go new file mode 100644 index 00000000000..affb30b265b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdataapiresponse.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDataApiResponse struct { + RenderingProperties *DiagnosticRendering `json:"renderingProperties,omitempty"` + Table *DiagnosticDataTableResponseObject `json:"table,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdefinition.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdefinition.go new file mode 100644 index 00000000000..aa89d010ac5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsdefinition.go @@ -0,0 +1,16 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDefinition struct { + AnalysisTypes *[]string `json:"analysisTypes,omitempty"` + Author *string `json:"author,omitempty"` + Category *string `json:"category,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Score *float64 `json:"score,omitempty"` + SupportTopicList *[]DiagnosticSupportTopic `json:"supportTopicList,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsproperties.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsproperties.go new file mode 100644 index 00000000000..c18b6dd9de3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsproperties.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsProperties struct { + DataProviderMetadata *DiagnosticDataProviderMetadata `json:"dataProviderMetadata,omitempty"` + Dataset *[]DiagnosticsDataApiResponse `json:"dataset,omitempty"` + Metadata *DiagnosticsDefinition `json:"metadata,omitempty"` + Status *DiagnosticsStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsstatus.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsstatus.go new file mode 100644 index 00000000000..4bfc6af51df --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsstatus.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsStatus struct { + Message *string `json:"message,omitempty"` + StatusId *int64 `json:"statusId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsupporttopic.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsupporttopic.go new file mode 100644 index 00000000000..111e1e400e6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_diagnosticsupporttopic.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSupportTopic struct { + Id *string `json:"id,omitempty"` + PesId *string `json:"pesId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_environmentvar.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_environmentvar.go new file mode 100644 index 00000000000..6c7d3dc6fb1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_environmentvar.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentVar struct { + Name *string `json:"name,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_extendedlocation.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_extendedlocation.go new file mode 100644 index 00000000000..bc440ede620 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_extendedlocation.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedLocation struct { + Name *string `json:"name,omitempty"` + Type *ExtendedLocationTypes `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_httpscalerule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_httpscalerule.go new file mode 100644 index 00000000000..d189127599a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_httpscalerule.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_identitysettings.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_identitysettings.go new file mode 100644 index 00000000000..e592c735395 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_identitysettings.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentitySettings struct { + Identity string `json:"identity"` + Lifecycle *IdentitySettingsLifeCycle `json:"lifecycle,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_ingress.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_ingress.go new file mode 100644 index 00000000000..2b4d8191903 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_ingress.go @@ -0,0 +1,20 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Ingress struct { + AdditionalPortMappings *[]IngressPortMapping `json:"additionalPortMappings,omitempty"` + AllowInsecure *bool `json:"allowInsecure,omitempty"` + ClientCertificateMode *IngressClientCertificateMode `json:"clientCertificateMode,omitempty"` + CorsPolicy *CorsPolicy `json:"corsPolicy,omitempty"` + CustomDomains *[]CustomDomain `json:"customDomains,omitempty"` + ExposedPort *int64 `json:"exposedPort,omitempty"` + External *bool `json:"external,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + IPSecurityRestrictions *[]IPSecurityRestrictionRule `json:"ipSecurityRestrictions,omitempty"` + StickySessions *IngressStickySessions `json:"stickySessions,omitempty"` + TargetPort *int64 `json:"targetPort,omitempty"` + Traffic *[]TrafficWeight `json:"traffic,omitempty"` + Transport *IngressTransportMethod `json:"transport,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_ingressportmapping.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_ingressportmapping.go new file mode 100644 index 00000000000..1c9776d6599 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_ingressportmapping.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IngressPortMapping struct { + ExposedPort *int64 `json:"exposedPort,omitempty"` + External bool `json:"external"` + TargetPort int64 `json:"targetPort"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_ingressstickysessions.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_ingressstickysessions.go new file mode 100644 index 00000000000..19d1b114937 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_ingressstickysessions.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IngressStickySessions struct { + Affinity *Affinity `json:"affinity,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_ipsecurityrestrictionrule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_ipsecurityrestrictionrule.go new file mode 100644 index 00000000000..5c8f316c3e8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_ipsecurityrestrictionrule.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPSecurityRestrictionRule struct { + Action Action `json:"action"` + Description *string `json:"description,omitempty"` + IPAddressRange string `json:"ipAddressRange"` + Name string `json:"name"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_job.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_job.go new file mode 100644 index 00000000000..74caa4c68a8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_job.go @@ -0,0 +1,20 @@ +package diagnostics + +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 Job struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *JobProperties `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/containerapps/2025-01-01/diagnostics/model_jobconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfiguration.go new file mode 100644 index 00000000000..673ef92fcd5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfiguration.go @@ -0,0 +1,16 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfiguration struct { + EventTriggerConfig *JobConfigurationEventTriggerConfig `json:"eventTriggerConfig,omitempty"` + IdentitySettings *[]IdentitySettings `json:"identitySettings,omitempty"` + ManualTriggerConfig *JobConfigurationManualTriggerConfig `json:"manualTriggerConfig,omitempty"` + Registries *[]RegistryCredentials `json:"registries,omitempty"` + ReplicaRetryLimit *int64 `json:"replicaRetryLimit,omitempty"` + ReplicaTimeout int64 `json:"replicaTimeout"` + ScheduleTriggerConfig *JobConfigurationScheduleTriggerConfig `json:"scheduleTriggerConfig,omitempty"` + Secrets *[]Secret `json:"secrets,omitempty"` + TriggerType TriggerType `json:"triggerType"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationeventtriggerconfig.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationeventtriggerconfig.go new file mode 100644 index 00000000000..d75b822a94a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationeventtriggerconfig.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfigurationEventTriggerConfig struct { + Parallelism *int64 `json:"parallelism,omitempty"` + ReplicaCompletionCount *int64 `json:"replicaCompletionCount,omitempty"` + Scale *JobScale `json:"scale,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationmanualtriggerconfig.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationmanualtriggerconfig.go new file mode 100644 index 00000000000..5e693724e3a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationmanualtriggerconfig.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfigurationManualTriggerConfig struct { + Parallelism *int64 `json:"parallelism,omitempty"` + ReplicaCompletionCount *int64 `json:"replicaCompletionCount,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationscheduletriggerconfig.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationscheduletriggerconfig.go new file mode 100644 index 00000000000..76a14e5c7e7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobconfigurationscheduletriggerconfig.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfigurationScheduleTriggerConfig struct { + CronExpression string `json:"cronExpression"` + Parallelism *int64 `json:"parallelism,omitempty"` + ReplicaCompletionCount *int64 `json:"replicaCompletionCount,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobproperties.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobproperties.go new file mode 100644 index 00000000000..4fb941531a7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobproperties.go @@ -0,0 +1,14 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobProperties struct { + Configuration *JobConfiguration `json:"configuration,omitempty"` + EnvironmentId *string `json:"environmentId,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + OutboundIPAddresses *[]string `json:"outboundIpAddresses,omitempty"` + ProvisioningState *JobProvisioningState `json:"provisioningState,omitempty"` + Template *JobTemplate `json:"template,omitempty"` + WorkloadProfileName *string `json:"workloadProfileName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobscale.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobscale.go new file mode 100644 index 00000000000..63b856e7ad6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobscale.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobScale struct { + MaxExecutions *int64 `json:"maxExecutions,omitempty"` + MinExecutions *int64 `json:"minExecutions,omitempty"` + PollingInterval *int64 `json:"pollingInterval,omitempty"` + Rules *[]JobScaleRule `json:"rules,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobscalerule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobscalerule.go new file mode 100644 index 00000000000..98e5555c2fd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobscalerule.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *interface{} `json:"metadata,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_jobtemplate.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobtemplate.go new file mode 100644 index 00000000000..9474be5f0d8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_jobtemplate.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobTemplate struct { + Containers *[]Container `json:"containers,omitempty"` + InitContainers *[]BaseContainer `json:"initContainers,omitempty"` + Volumes *[]Volume `json:"volumes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_kedaconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_kedaconfiguration.go new file mode 100644 index 00000000000..fd1cbc3ab25 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_kedaconfiguration.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KedaConfiguration struct { + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_loganalyticsconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_loganalyticsconfiguration.go new file mode 100644 index 00000000000..6b3d70a2547 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_loganalyticsconfiguration.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsConfiguration struct { + CustomerId *string `json:"customerId,omitempty"` + SharedKey *string `json:"sharedKey,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironment.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironment.go new file mode 100644 index 00000000000..506b862a53f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironment.go @@ -0,0 +1,21 @@ +package diagnostics + +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 ManagedEnvironment struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedEnvironmentProperties `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/containerapps/2025-01-01/diagnostics/model_managedenvironmentproperties.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentproperties.go new file mode 100644 index 00000000000..e6e11d7d44d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentproperties.go @@ -0,0 +1,24 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentProperties struct { + AppLogsConfiguration *AppLogsConfiguration `json:"appLogsConfiguration,omitempty"` + CustomDomainConfiguration *CustomDomainConfiguration `json:"customDomainConfiguration,omitempty"` + DaprAIConnectionString *string `json:"daprAIConnectionString,omitempty"` + DaprAIInstrumentationKey *string `json:"daprAIInstrumentationKey,omitempty"` + DaprConfiguration *DaprConfiguration `json:"daprConfiguration,omitempty"` + DefaultDomain *string `json:"defaultDomain,omitempty"` + DeploymentErrors *string `json:"deploymentErrors,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + InfrastructureResourceGroup *string `json:"infrastructureResourceGroup,omitempty"` + KedaConfiguration *KedaConfiguration `json:"kedaConfiguration,omitempty"` + PeerAuthentication *ManagedEnvironmentPropertiesPeerAuthentication `json:"peerAuthentication,omitempty"` + PeerTrafficConfiguration *ManagedEnvironmentPropertiesPeerTrafficConfiguration `json:"peerTrafficConfiguration,omitempty"` + ProvisioningState *EnvironmentProvisioningState `json:"provisioningState,omitempty"` + StaticIP *string `json:"staticIp,omitempty"` + VnetConfiguration *VnetConfiguration `json:"vnetConfiguration,omitempty"` + WorkloadProfiles *[]WorkloadProfile `json:"workloadProfiles,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeerauthentication.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeerauthentication.go new file mode 100644 index 00000000000..dfaf7fc5ee0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeerauthentication.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentPropertiesPeerAuthentication struct { + Mtls *Mtls `json:"mtls,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfiguration.go new file mode 100644 index 00000000000..4d3803b94a2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfiguration.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentPropertiesPeerTrafficConfiguration struct { + Encryption *ManagedEnvironmentPropertiesPeerTrafficConfigurationEncryption `json:"encryption,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go new file mode 100644 index 00000000000..b0f11534e0b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentPropertiesPeerTrafficConfigurationEncryption struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_mtls.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_mtls.go new file mode 100644 index 00000000000..4d08ea1e46f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_mtls.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Mtls struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_queuescalerule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_queuescalerule.go new file mode 100644 index 00000000000..d6766f4d290 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_queuescalerule.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueueScaleRule struct { + AccountName *string `json:"accountName,omitempty"` + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + QueueLength *int64 `json:"queueLength,omitempty"` + QueueName *string `json:"queueName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_registrycredentials.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_registrycredentials.go new file mode 100644 index 00000000000..8ea29de9709 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_registrycredentials.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryCredentials struct { + Identity *string `json:"identity,omitempty"` + PasswordSecretRef *string `json:"passwordSecretRef,omitempty"` + Server *string `json:"server,omitempty"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_revision.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_revision.go new file mode 100644 index 00000000000..c34756ce75b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_revision.go @@ -0,0 +1,16 @@ +package diagnostics + +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 Revision struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RevisionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_revisionproperties.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_revisionproperties.go new file mode 100644 index 00000000000..2fe29894e02 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_revisionproperties.go @@ -0,0 +1,48 @@ +package diagnostics + +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 RevisionProperties struct { + Active *bool `json:"active,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + Fqdn *string `json:"fqdn,omitempty"` + HealthState *RevisionHealthState `json:"healthState,omitempty"` + LastActiveTime *string `json:"lastActiveTime,omitempty"` + ProvisioningError *string `json:"provisioningError,omitempty"` + ProvisioningState *RevisionProvisioningState `json:"provisioningState,omitempty"` + Replicas *int64 `json:"replicas,omitempty"` + RunningState *RevisionRunningState `json:"runningState,omitempty"` + Template *Template `json:"template,omitempty"` + TrafficWeight *int64 `json:"trafficWeight,omitempty"` +} + +func (o *RevisionProperties) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RevisionProperties) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} + +func (o *RevisionProperties) GetLastActiveTimeAsTime() (*time.Time, error) { + if o.LastActiveTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastActiveTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RevisionProperties) SetLastActiveTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastActiveTime = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_runtime.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_runtime.go new file mode 100644 index 00000000000..c69676e07b3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_runtime.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Runtime struct { + Java *RuntimeJava `json:"java,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_runtimejava.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_runtimejava.go new file mode 100644 index 00000000000..0e79de08b8c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_runtimejava.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RuntimeJava struct { + EnableMetrics *bool `json:"enableMetrics,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_scale.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_scale.go new file mode 100644 index 00000000000..f6de25d2337 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_scale.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Scale struct { + CooldownPeriod *int64 `json:"cooldownPeriod,omitempty"` + MaxReplicas *int64 `json:"maxReplicas,omitempty"` + MinReplicas *int64 `json:"minReplicas,omitempty"` + PollingInterval *int64 `json:"pollingInterval,omitempty"` + Rules *[]ScaleRule `json:"rules,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_scalerule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_scalerule.go new file mode 100644 index 00000000000..9155fee0b3d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_scalerule.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRule struct { + AzureQueue *QueueScaleRule `json:"azureQueue,omitempty"` + Custom *CustomScaleRule `json:"custom,omitempty"` + HTTP *HTTPScaleRule `json:"http,omitempty"` + Name *string `json:"name,omitempty"` + Tcp *TcpScaleRule `json:"tcp,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_scaleruleauth.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_scaleruleauth.go new file mode 100644 index 00000000000..6fb4bc302f7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_scaleruleauth.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRuleAuth struct { + SecretRef *string `json:"secretRef,omitempty"` + TriggerParameter *string `json:"triggerParameter,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_secret.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_secret.go new file mode 100644 index 00000000000..5552c0fb8b3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_secret.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Secret struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_secretvolumeitem.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_secretvolumeitem.go new file mode 100644 index 00000000000..ca25f4a1e5f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_secretvolumeitem.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretVolumeItem struct { + Path *string `json:"path,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_service.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_service.go new file mode 100644 index 00000000000..5ef6553aca5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_service.go @@ -0,0 +1,8 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Service struct { + Type string `json:"type"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_servicebind.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_servicebind.go new file mode 100644 index 00000000000..f04e0404c8a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_servicebind.go @@ -0,0 +1,9 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceBind struct { + Name *string `json:"name,omitempty"` + ServiceId *string `json:"serviceId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_tcpscalerule.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_tcpscalerule.go new file mode 100644 index 00000000000..b00fc4c8921 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_tcpscalerule.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TcpScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_template.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_template.go new file mode 100644 index 00000000000..3208fd170a2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_template.go @@ -0,0 +1,14 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Template struct { + Containers *[]Container `json:"containers,omitempty"` + InitContainers *[]BaseContainer `json:"initContainers,omitempty"` + RevisionSuffix *string `json:"revisionSuffix,omitempty"` + Scale *Scale `json:"scale,omitempty"` + ServiceBinds *[]ServiceBind `json:"serviceBinds,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + Volumes *[]Volume `json:"volumes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_trafficweight.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_trafficweight.go new file mode 100644 index 00000000000..2472dfcfbcd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_trafficweight.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficWeight struct { + Label *string `json:"label,omitempty"` + LatestRevision *bool `json:"latestRevision,omitempty"` + RevisionName *string `json:"revisionName,omitempty"` + Weight *int64 `json:"weight,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_vnetconfiguration.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_vnetconfiguration.go new file mode 100644 index 00000000000..40c7c67e702 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_vnetconfiguration.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VnetConfiguration struct { + DockerBridgeCidr *string `json:"dockerBridgeCidr,omitempty"` + InfrastructureSubnetId *string `json:"infrastructureSubnetId,omitempty"` + Internal *bool `json:"internal,omitempty"` + PlatformReservedCidr *string `json:"platformReservedCidr,omitempty"` + PlatformReservedDnsIP *string `json:"platformReservedDnsIP,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_volume.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_volume.go new file mode 100644 index 00000000000..3ef596dfe70 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_volume.go @@ -0,0 +1,12 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Volume struct { + MountOptions *string `json:"mountOptions,omitempty"` + Name *string `json:"name,omitempty"` + Secrets *[]SecretVolumeItem `json:"secrets,omitempty"` + StorageName *string `json:"storageName,omitempty"` + StorageType *StorageType `json:"storageType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_volumemount.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_volumemount.go new file mode 100644 index 00000000000..7c3a7d2aa8c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_volumemount.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VolumeMount struct { + MountPath *string `json:"mountPath,omitempty"` + SubPath *string `json:"subPath,omitempty"` + VolumeName *string `json:"volumeName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/model_workloadprofile.go b/resource-manager/containerapps/2025-01-01/diagnostics/model_workloadprofile.go new file mode 100644 index 00000000000..88283d198f1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/model_workloadprofile.go @@ -0,0 +1,11 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadProfile struct { + MaximumCount *int64 `json:"maximumCount,omitempty"` + MinimumCount *int64 `json:"minimumCount,omitempty"` + Name string `json:"name"` + WorkloadProfileType string `json:"workloadProfileType"` +} diff --git a/resource-manager/containerapps/2025-01-01/diagnostics/predicates.go b/resource-manager/containerapps/2025-01-01/diagnostics/predicates.go new file mode 100644 index 00000000000..f8895351db6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/predicates.go @@ -0,0 +1,50 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DiagnosticsOperationPredicate) Matches(input Diagnostics) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type RevisionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RevisionOperationPredicate) Matches(input Revision) 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/containerapps/2025-01-01/diagnostics/version.go b/resource-manager/containerapps/2025-01-01/diagnostics/version.go new file mode 100644 index 00000000000..d399fc684fd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/diagnostics/version.go @@ -0,0 +1,10 @@ +package diagnostics + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/diagnostics/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/README.md b/resource-manager/containerapps/2025-01-01/javacomponents/README.md new file mode 100644 index 00000000000..ad70e9d7504 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/javacomponents` Documentation + +The `javacomponents` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/javacomponents" +``` + + +### Client Initialization + +```go +client := javacomponents.NewJavaComponentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JavaComponentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := javacomponents.NewJavaComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "javaComponentName") + +payload := javacomponents.JavaComponent{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `JavaComponentsClient.Delete` + +```go +ctx := context.TODO() +id := javacomponents.NewJavaComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "javaComponentName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JavaComponentsClient.Get` + +```go +ctx := context.TODO() +id := javacomponents.NewJavaComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "javaComponentName") + +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: `JavaComponentsClient.List` + +```go +ctx := context.TODO() +id := javacomponents.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// 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: `JavaComponentsClient.Update` + +```go +ctx := context.TODO() +id := javacomponents.NewJavaComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "javaComponentName") + +payload := javacomponents.JavaComponent{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/client.go b/resource-manager/containerapps/2025-01-01/javacomponents/client.go new file mode 100644 index 00000000000..d02ba0844ff --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/client.go @@ -0,0 +1,26 @@ +package javacomponents + +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 JavaComponentsClient struct { + Client *resourcemanager.Client +} + +func NewJavaComponentsClientWithBaseURI(sdkApi sdkEnv.Api) (*JavaComponentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "javacomponents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JavaComponentsClient: %+v", err) + } + + return &JavaComponentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/constants.go b/resource-manager/containerapps/2025-01-01/javacomponents/constants.go new file mode 100644 index 00000000000..278af0b3ab2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/constants.go @@ -0,0 +1,104 @@ +package javacomponents + +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 JavaComponentProvisioningState string + +const ( + JavaComponentProvisioningStateCanceled JavaComponentProvisioningState = "Canceled" + JavaComponentProvisioningStateDeleting JavaComponentProvisioningState = "Deleting" + JavaComponentProvisioningStateFailed JavaComponentProvisioningState = "Failed" + JavaComponentProvisioningStateInProgress JavaComponentProvisioningState = "InProgress" + JavaComponentProvisioningStateSucceeded JavaComponentProvisioningState = "Succeeded" +) + +func PossibleValuesForJavaComponentProvisioningState() []string { + return []string{ + string(JavaComponentProvisioningStateCanceled), + string(JavaComponentProvisioningStateDeleting), + string(JavaComponentProvisioningStateFailed), + string(JavaComponentProvisioningStateInProgress), + string(JavaComponentProvisioningStateSucceeded), + } +} + +func (s *JavaComponentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJavaComponentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJavaComponentProvisioningState(input string) (*JavaComponentProvisioningState, error) { + vals := map[string]JavaComponentProvisioningState{ + "canceled": JavaComponentProvisioningStateCanceled, + "deleting": JavaComponentProvisioningStateDeleting, + "failed": JavaComponentProvisioningStateFailed, + "inprogress": JavaComponentProvisioningStateInProgress, + "succeeded": JavaComponentProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JavaComponentProvisioningState(input) + return &out, nil +} + +type JavaComponentType string + +const ( + JavaComponentTypeSpringBootAdmin JavaComponentType = "SpringBootAdmin" + JavaComponentTypeSpringCloudConfig JavaComponentType = "SpringCloudConfig" + JavaComponentTypeSpringCloudEureka JavaComponentType = "SpringCloudEureka" +) + +func PossibleValuesForJavaComponentType() []string { + return []string{ + string(JavaComponentTypeSpringBootAdmin), + string(JavaComponentTypeSpringCloudConfig), + string(JavaComponentTypeSpringCloudEureka), + } +} + +func (s *JavaComponentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJavaComponentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJavaComponentType(input string) (*JavaComponentType, error) { + vals := map[string]JavaComponentType{ + "springbootadmin": JavaComponentTypeSpringBootAdmin, + "springcloudconfig": JavaComponentTypeSpringCloudConfig, + "springcloudeureka": JavaComponentTypeSpringCloudEureka, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JavaComponentType(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent.go b/resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent.go new file mode 100644 index 00000000000..9022042fe5e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent.go @@ -0,0 +1,139 @@ +package javacomponents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JavaComponentId{}) +} + +var _ resourceids.ResourceId = &JavaComponentId{} + +// JavaComponentId is a struct representing the Resource ID for a Java Component +type JavaComponentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + JavaComponentName string +} + +// NewJavaComponentID returns a new JavaComponentId struct +func NewJavaComponentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, javaComponentName string) JavaComponentId { + return JavaComponentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + JavaComponentName: javaComponentName, + } +} + +// ParseJavaComponentID parses 'input' into a JavaComponentId +func ParseJavaComponentID(input string) (*JavaComponentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JavaComponentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JavaComponentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJavaComponentIDInsensitively parses 'input' case-insensitively into a JavaComponentId +// note: this method should only be used for API response data and not user input +func ParseJavaComponentIDInsensitively(input string) (*JavaComponentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JavaComponentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JavaComponentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JavaComponentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.JavaComponentName, ok = input.Parsed["javaComponentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "javaComponentName", input) + } + + return nil +} + +// ValidateJavaComponentID checks that 'input' can be parsed as a Java Component ID +func ValidateJavaComponentID(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 := ParseJavaComponentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Java Component ID +func (id JavaComponentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/javaComponents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.JavaComponentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Java Component ID +func (id JavaComponentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticJavaComponents", "javaComponents", "javaComponents"), + resourceids.UserSpecifiedSegment("javaComponentName", "javaComponentName"), + } +} + +// String returns a human-readable description of this Java Component ID +func (id JavaComponentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Java Component Name: %q", id.JavaComponentName), + } + return fmt.Sprintf("Java Component (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent_test.go b/resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent_test.go new file mode 100644 index 00000000000..fabcc9cb227 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/id_javacomponent_test.go @@ -0,0 +1,327 @@ +package javacomponents + +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 = &JavaComponentId{} + +func TestNewJavaComponentID(t *testing.T) { + id := NewJavaComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "javaComponentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.JavaComponentName != "javaComponentName" { + t.Fatalf("Expected %q but got %q for Segment 'JavaComponentName'", id.JavaComponentName, "javaComponentName") + } +} + +func TestFormatJavaComponentID(t *testing.T) { + actual := NewJavaComponentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "javaComponentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents/javaComponentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJavaComponentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JavaComponentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents/javaComponentName", + Expected: &JavaComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + JavaComponentName: "javaComponentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents/javaComponentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJavaComponentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.JavaComponentName != v.Expected.JavaComponentName { + t.Fatalf("Expected %q but got %q for JavaComponentName", v.Expected.JavaComponentName, actual.JavaComponentName) + } + + } +} + +func TestParseJavaComponentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JavaComponentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/jAvAcOmPoNeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents/javaComponentName", + Expected: &JavaComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + JavaComponentName: "javaComponentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/javaComponents/javaComponentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/jAvAcOmPoNeNtS/jAvAcOmPoNeNtNaMe", + Expected: &JavaComponentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + JavaComponentName: "jAvAcOmPoNeNtNaMe", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/jAvAcOmPoNeNtS/jAvAcOmPoNeNtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJavaComponentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.JavaComponentName != v.Expected.JavaComponentName { + t.Fatalf("Expected %q but got %q for JavaComponentName", v.Expected.JavaComponentName, actual.JavaComponentName) + } + + } +} + +func TestSegmentsForJavaComponentId(t *testing.T) { + segments := JavaComponentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JavaComponentId 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/containerapps/2025-01-01/javacomponents/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment.go new file mode 100644 index 00000000000..c815734c19a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment.go @@ -0,0 +1,130 @@ +package javacomponents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment_test.go new file mode 100644 index 00000000000..673ab32d0a4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package javacomponents + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/javacomponents/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/javacomponents/method_createorupdate.go new file mode 100644 index 00000000000..b54b6f10333 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/method_createorupdate.go @@ -0,0 +1,75 @@ +package javacomponents + +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 *JavaComponent +} + +// CreateOrUpdate ... +func (c JavaComponentsClient) CreateOrUpdate(ctx context.Context, id JavaComponentId, input JavaComponent) (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 JavaComponentsClient) CreateOrUpdateThenPoll(ctx context.Context, id JavaComponentId, input JavaComponent) 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/containerapps/2025-01-01/javacomponents/method_delete.go b/resource-manager/containerapps/2025-01-01/javacomponents/method_delete.go new file mode 100644 index 00000000000..532c3a1b52d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/method_delete.go @@ -0,0 +1,70 @@ +package javacomponents + +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 JavaComponentsClient) Delete(ctx context.Context, id JavaComponentId) (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 JavaComponentsClient) DeleteThenPoll(ctx context.Context, id JavaComponentId) 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/containerapps/2025-01-01/javacomponents/method_get.go b/resource-manager/containerapps/2025-01-01/javacomponents/method_get.go new file mode 100644 index 00000000000..2dc708149bf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/method_get.go @@ -0,0 +1,53 @@ +package javacomponents + +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 *JavaComponent +} + +// Get ... +func (c JavaComponentsClient) Get(ctx context.Context, id JavaComponentId) (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 JavaComponent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/method_list.go b/resource-manager/containerapps/2025-01-01/javacomponents/method_list.go new file mode 100644 index 00000000000..522196240be --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/method_list.go @@ -0,0 +1,105 @@ +package javacomponents + +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 *[]JavaComponent +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []JavaComponent +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c JavaComponentsClient) List(ctx context.Context, id ManagedEnvironmentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/javaComponents", 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 *[]JavaComponent `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 JavaComponentsClient) ListComplete(ctx context.Context, id ManagedEnvironmentId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, JavaComponentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JavaComponentsClient) ListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate JavaComponentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]JavaComponent, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/method_update.go b/resource-manager/containerapps/2025-01-01/javacomponents/method_update.go new file mode 100644 index 00000000000..65736d491ce --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/method_update.go @@ -0,0 +1,75 @@ +package javacomponents + +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 *JavaComponent +} + +// Update ... +func (c JavaComponentsClient) Update(ctx context.Context, id JavaComponentId, input JavaComponent) (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 JavaComponentsClient) UpdateThenPoll(ctx context.Context, id JavaComponentId, input JavaComponent) 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/containerapps/2025-01-01/javacomponents/model_javacomponent.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponent.go new file mode 100644 index 00000000000..93267af89e2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponent.go @@ -0,0 +1,53 @@ +package javacomponents + +import ( + "encoding/json" + "fmt" + + "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 JavaComponent struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties JavaComponentProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &JavaComponent{} + +func (s *JavaComponent) UnmarshalJSON(bytes []byte) error { + var decoded struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling JavaComponent into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := UnmarshalJavaComponentPropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'JavaComponent': %+v", err) + } + s.Properties = impl + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentconfigurationproperty.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentconfigurationproperty.go new file mode 100644 index 00000000000..07092ccbd89 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentconfigurationproperty.go @@ -0,0 +1,9 @@ +package javacomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JavaComponentConfigurationProperty struct { + PropertyName *string `json:"propertyName,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentingress.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentingress.go new file mode 100644 index 00000000000..4a716a1e0c5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentingress.go @@ -0,0 +1,8 @@ +package javacomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JavaComponentIngress struct { + Fqdn *string `json:"fqdn,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentproperties.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentproperties.go new file mode 100644 index 00000000000..6295891c297 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentproperties.go @@ -0,0 +1,95 @@ +package javacomponents + +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 JavaComponentProperties interface { + JavaComponentProperties() BaseJavaComponentPropertiesImpl +} + +var _ JavaComponentProperties = BaseJavaComponentPropertiesImpl{} + +type BaseJavaComponentPropertiesImpl struct { + ComponentType JavaComponentType `json:"componentType"` + Configurations *[]JavaComponentConfigurationProperty `json:"configurations,omitempty"` + ProvisioningState *JavaComponentProvisioningState `json:"provisioningState,omitempty"` + Scale *JavaComponentPropertiesScale `json:"scale,omitempty"` + ServiceBinds *[]JavaComponentServiceBind `json:"serviceBinds,omitempty"` +} + +func (s BaseJavaComponentPropertiesImpl) JavaComponentProperties() BaseJavaComponentPropertiesImpl { + return s +} + +var _ JavaComponentProperties = RawJavaComponentPropertiesImpl{} + +// RawJavaComponentPropertiesImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawJavaComponentPropertiesImpl struct { + javaComponentProperties BaseJavaComponentPropertiesImpl + Type string + Values map[string]interface{} +} + +func (s RawJavaComponentPropertiesImpl) JavaComponentProperties() BaseJavaComponentPropertiesImpl { + return s.javaComponentProperties +} + +func UnmarshalJavaComponentPropertiesImplementation(input []byte) (JavaComponentProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling JavaComponentProperties into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["componentType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "SpringBootAdmin") { + var out SpringBootAdminComponent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SpringBootAdminComponent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SpringCloudConfig") { + var out SpringCloudConfigComponent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SpringCloudConfigComponent: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SpringCloudEureka") { + var out SpringCloudEurekaComponent + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SpringCloudEurekaComponent: %+v", err) + } + return out, nil + } + + var parent BaseJavaComponentPropertiesImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseJavaComponentPropertiesImpl: %+v", err) + } + + return RawJavaComponentPropertiesImpl{ + javaComponentProperties: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentpropertiesscale.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentpropertiesscale.go new file mode 100644 index 00000000000..f4dbac2e3a2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentpropertiesscale.go @@ -0,0 +1,9 @@ +package javacomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JavaComponentPropertiesScale struct { + MaxReplicas *int64 `json:"maxReplicas,omitempty"` + MinReplicas *int64 `json:"minReplicas,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentservicebind.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentservicebind.go new file mode 100644 index 00000000000..224bc9cc4c5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_javacomponentservicebind.go @@ -0,0 +1,9 @@ +package javacomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JavaComponentServiceBind struct { + Name *string `json:"name,omitempty"` + ServiceId *string `json:"serviceId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_springbootadmincomponent.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_springbootadmincomponent.go new file mode 100644 index 00000000000..19d21efa41d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_springbootadmincomponent.go @@ -0,0 +1,58 @@ +package javacomponents + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ JavaComponentProperties = SpringBootAdminComponent{} + +type SpringBootAdminComponent struct { + Ingress *JavaComponentIngress `json:"ingress,omitempty"` + + // Fields inherited from JavaComponentProperties + + ComponentType JavaComponentType `json:"componentType"` + Configurations *[]JavaComponentConfigurationProperty `json:"configurations,omitempty"` + ProvisioningState *JavaComponentProvisioningState `json:"provisioningState,omitempty"` + Scale *JavaComponentPropertiesScale `json:"scale,omitempty"` + ServiceBinds *[]JavaComponentServiceBind `json:"serviceBinds,omitempty"` +} + +func (s SpringBootAdminComponent) JavaComponentProperties() BaseJavaComponentPropertiesImpl { + return BaseJavaComponentPropertiesImpl{ + ComponentType: s.ComponentType, + Configurations: s.Configurations, + ProvisioningState: s.ProvisioningState, + Scale: s.Scale, + ServiceBinds: s.ServiceBinds, + } +} + +var _ json.Marshaler = SpringBootAdminComponent{} + +func (s SpringBootAdminComponent) MarshalJSON() ([]byte, error) { + type wrapper SpringBootAdminComponent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SpringBootAdminComponent: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SpringBootAdminComponent: %+v", err) + } + + decoded["componentType"] = "SpringBootAdmin" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SpringBootAdminComponent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudconfigcomponent.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudconfigcomponent.go new file mode 100644 index 00000000000..649615c6033 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudconfigcomponent.go @@ -0,0 +1,57 @@ +package javacomponents + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ JavaComponentProperties = SpringCloudConfigComponent{} + +type SpringCloudConfigComponent struct { + + // Fields inherited from JavaComponentProperties + + ComponentType JavaComponentType `json:"componentType"` + Configurations *[]JavaComponentConfigurationProperty `json:"configurations,omitempty"` + ProvisioningState *JavaComponentProvisioningState `json:"provisioningState,omitempty"` + Scale *JavaComponentPropertiesScale `json:"scale,omitempty"` + ServiceBinds *[]JavaComponentServiceBind `json:"serviceBinds,omitempty"` +} + +func (s SpringCloudConfigComponent) JavaComponentProperties() BaseJavaComponentPropertiesImpl { + return BaseJavaComponentPropertiesImpl{ + ComponentType: s.ComponentType, + Configurations: s.Configurations, + ProvisioningState: s.ProvisioningState, + Scale: s.Scale, + ServiceBinds: s.ServiceBinds, + } +} + +var _ json.Marshaler = SpringCloudConfigComponent{} + +func (s SpringCloudConfigComponent) MarshalJSON() ([]byte, error) { + type wrapper SpringCloudConfigComponent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SpringCloudConfigComponent: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SpringCloudConfigComponent: %+v", err) + } + + decoded["componentType"] = "SpringCloudConfig" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SpringCloudConfigComponent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudeurekacomponent.go b/resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudeurekacomponent.go new file mode 100644 index 00000000000..183dfc46856 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/model_springcloudeurekacomponent.go @@ -0,0 +1,58 @@ +package javacomponents + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ JavaComponentProperties = SpringCloudEurekaComponent{} + +type SpringCloudEurekaComponent struct { + Ingress *JavaComponentIngress `json:"ingress,omitempty"` + + // Fields inherited from JavaComponentProperties + + ComponentType JavaComponentType `json:"componentType"` + Configurations *[]JavaComponentConfigurationProperty `json:"configurations,omitempty"` + ProvisioningState *JavaComponentProvisioningState `json:"provisioningState,omitempty"` + Scale *JavaComponentPropertiesScale `json:"scale,omitempty"` + ServiceBinds *[]JavaComponentServiceBind `json:"serviceBinds,omitempty"` +} + +func (s SpringCloudEurekaComponent) JavaComponentProperties() BaseJavaComponentPropertiesImpl { + return BaseJavaComponentPropertiesImpl{ + ComponentType: s.ComponentType, + Configurations: s.Configurations, + ProvisioningState: s.ProvisioningState, + Scale: s.Scale, + ServiceBinds: s.ServiceBinds, + } +} + +var _ json.Marshaler = SpringCloudEurekaComponent{} + +func (s SpringCloudEurekaComponent) MarshalJSON() ([]byte, error) { + type wrapper SpringCloudEurekaComponent + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SpringCloudEurekaComponent: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SpringCloudEurekaComponent: %+v", err) + } + + decoded["componentType"] = "SpringCloudEureka" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SpringCloudEurekaComponent: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/containerapps/2025-01-01/javacomponents/predicates.go b/resource-manager/containerapps/2025-01-01/javacomponents/predicates.go new file mode 100644 index 00000000000..6363fc691b2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/predicates.go @@ -0,0 +1,27 @@ +package javacomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JavaComponentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JavaComponentOperationPredicate) Matches(input JavaComponent) 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/containerapps/2025-01-01/javacomponents/version.go b/resource-manager/containerapps/2025-01-01/javacomponents/version.go new file mode 100644 index 00000000000..8413059a006 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/javacomponents/version.go @@ -0,0 +1,10 @@ +package javacomponents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/javacomponents/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/README.md b/resource-manager/containerapps/2025-01-01/jobs/README.md new file mode 100644 index 00000000000..49f69ff1058 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/README.md @@ -0,0 +1,261 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/jobs` Documentation + +The `jobs` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/jobs" +``` + + +### Client Initialization + +```go +client := jobs.NewJobsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +payload := jobs.Job{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobsClient.Delete` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobsClient.ExecutionsList` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +// alternatively `client.ExecutionsList(ctx, id, jobs.DefaultExecutionsListOperationOptions())` can be used to do batched pagination +items, err := client.ExecutionsListComplete(ctx, id, jobs.DefaultExecutionsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobsClient.Get` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +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: `JobsClient.GetDetector` + +```go +ctx := context.TODO() +id := jobs.NewDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorName") + +read, err := client.GetDetector(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobsClient.JobExecution` + +```go +ctx := context.TODO() +id := jobs.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "executionName") + +read, err := client.JobExecution(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobsClient.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: `JobsClient.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: `JobsClient.ListDetectors` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +// alternatively `client.ListDetectors(ctx, id)` can be used to do batched pagination +items, err := client.ListDetectorsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobsClient.ListSecrets` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +read, err := client.ListSecrets(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobsClient.ProxyGet` + +```go +ctx := context.TODO() +id := jobs.NewDetectorPropertyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorPropertyName") + +read, err := client.ProxyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobsClient.Start` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +payload := jobs.JobExecutionTemplate{ + // ... +} + + +if err := client.StartThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobsClient.StopExecution` + +```go +ctx := context.TODO() +id := jobs.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "executionName") + +if err := client.StopExecutionThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobsClient.StopMultipleExecutions` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +// alternatively `client.StopMultipleExecutions(ctx, id)` can be used to do batched pagination +items, err := client.StopMultipleExecutionsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobsClient.Update` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + +payload := jobs.JobPatchProperties{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerapps/2025-01-01/jobs/client.go b/resource-manager/containerapps/2025-01-01/jobs/client.go new file mode 100644 index 00000000000..762c577e9e1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/client.go @@ -0,0 +1,26 @@ +package jobs + +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 JobsClient struct { + Client *resourcemanager.Client +} + +func NewJobsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobsClient: %+v", err) + } + + return &JobsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/constants.go b/resource-manager/containerapps/2025-01-01/jobs/constants.go new file mode 100644 index 00000000000..58116c1b34d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/constants.go @@ -0,0 +1,339 @@ +package jobs + +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 IdentitySettingsLifeCycle string + +const ( + IdentitySettingsLifeCycleAll IdentitySettingsLifeCycle = "All" + IdentitySettingsLifeCycleInit IdentitySettingsLifeCycle = "Init" + IdentitySettingsLifeCycleMain IdentitySettingsLifeCycle = "Main" + IdentitySettingsLifeCycleNone IdentitySettingsLifeCycle = "None" +) + +func PossibleValuesForIdentitySettingsLifeCycle() []string { + return []string{ + string(IdentitySettingsLifeCycleAll), + string(IdentitySettingsLifeCycleInit), + string(IdentitySettingsLifeCycleMain), + string(IdentitySettingsLifeCycleNone), + } +} + +func (s *IdentitySettingsLifeCycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentitySettingsLifeCycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentitySettingsLifeCycle(input string) (*IdentitySettingsLifeCycle, error) { + vals := map[string]IdentitySettingsLifeCycle{ + "all": IdentitySettingsLifeCycleAll, + "init": IdentitySettingsLifeCycleInit, + "main": IdentitySettingsLifeCycleMain, + "none": IdentitySettingsLifeCycleNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentitySettingsLifeCycle(input) + return &out, nil +} + +type JobExecutionRunningState string + +const ( + JobExecutionRunningStateDegraded JobExecutionRunningState = "Degraded" + JobExecutionRunningStateFailed JobExecutionRunningState = "Failed" + JobExecutionRunningStateProcessing JobExecutionRunningState = "Processing" + JobExecutionRunningStateRunning JobExecutionRunningState = "Running" + JobExecutionRunningStateStopped JobExecutionRunningState = "Stopped" + JobExecutionRunningStateSucceeded JobExecutionRunningState = "Succeeded" + JobExecutionRunningStateUnknown JobExecutionRunningState = "Unknown" +) + +func PossibleValuesForJobExecutionRunningState() []string { + return []string{ + string(JobExecutionRunningStateDegraded), + string(JobExecutionRunningStateFailed), + string(JobExecutionRunningStateProcessing), + string(JobExecutionRunningStateRunning), + string(JobExecutionRunningStateStopped), + string(JobExecutionRunningStateSucceeded), + string(JobExecutionRunningStateUnknown), + } +} + +func (s *JobExecutionRunningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobExecutionRunningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobExecutionRunningState(input string) (*JobExecutionRunningState, error) { + vals := map[string]JobExecutionRunningState{ + "degraded": JobExecutionRunningStateDegraded, + "failed": JobExecutionRunningStateFailed, + "processing": JobExecutionRunningStateProcessing, + "running": JobExecutionRunningStateRunning, + "stopped": JobExecutionRunningStateStopped, + "succeeded": JobExecutionRunningStateSucceeded, + "unknown": JobExecutionRunningStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobExecutionRunningState(input) + return &out, nil +} + +type JobProvisioningState string + +const ( + JobProvisioningStateCanceled JobProvisioningState = "Canceled" + JobProvisioningStateDeleting JobProvisioningState = "Deleting" + JobProvisioningStateFailed JobProvisioningState = "Failed" + JobProvisioningStateInProgress JobProvisioningState = "InProgress" + JobProvisioningStateSucceeded JobProvisioningState = "Succeeded" +) + +func PossibleValuesForJobProvisioningState() []string { + return []string{ + string(JobProvisioningStateCanceled), + string(JobProvisioningStateDeleting), + string(JobProvisioningStateFailed), + string(JobProvisioningStateInProgress), + string(JobProvisioningStateSucceeded), + } +} + +func (s *JobProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobProvisioningState(input string) (*JobProvisioningState, error) { + vals := map[string]JobProvisioningState{ + "canceled": JobProvisioningStateCanceled, + "deleting": JobProvisioningStateDeleting, + "failed": JobProvisioningStateFailed, + "inprogress": JobProvisioningStateInProgress, + "succeeded": JobProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobProvisioningState(input) + return &out, nil +} + +type Scheme string + +const ( + SchemeHTTP Scheme = "HTTP" + SchemeHTTPS Scheme = "HTTPS" +) + +func PossibleValuesForScheme() []string { + return []string{ + string(SchemeHTTP), + string(SchemeHTTPS), + } +} + +func (s *Scheme) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheme(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheme(input string) (*Scheme, error) { + vals := map[string]Scheme{ + "http": SchemeHTTP, + "https": SchemeHTTPS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Scheme(input) + return &out, nil +} + +type StorageType string + +const ( + StorageTypeAzureFile StorageType = "AzureFile" + StorageTypeEmptyDir StorageType = "EmptyDir" + StorageTypeNfsAzureFile StorageType = "NfsAzureFile" + StorageTypeSecret StorageType = "Secret" +) + +func PossibleValuesForStorageType() []string { + return []string{ + string(StorageTypeAzureFile), + string(StorageTypeEmptyDir), + string(StorageTypeNfsAzureFile), + string(StorageTypeSecret), + } +} + +func (s *StorageType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageType(input string) (*StorageType, error) { + vals := map[string]StorageType{ + "azurefile": StorageTypeAzureFile, + "emptydir": StorageTypeEmptyDir, + "nfsazurefile": StorageTypeNfsAzureFile, + "secret": StorageTypeSecret, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageType(input) + return &out, nil +} + +type TriggerType string + +const ( + TriggerTypeEvent TriggerType = "Event" + TriggerTypeManual TriggerType = "Manual" + TriggerTypeSchedule TriggerType = "Schedule" +) + +func PossibleValuesForTriggerType() []string { + return []string{ + string(TriggerTypeEvent), + string(TriggerTypeManual), + string(TriggerTypeSchedule), + } +} + +func (s *TriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggerType(input string) (*TriggerType, error) { + vals := map[string]TriggerType{ + "event": TriggerTypeEvent, + "manual": TriggerTypeManual, + "schedule": TriggerTypeSchedule, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggerType(input) + return &out, nil +} + +type Type string + +const ( + TypeLiveness Type = "Liveness" + TypeReadiness Type = "Readiness" + TypeStartup Type = "Startup" +) + +func PossibleValuesForType() []string { + return []string{ + string(TypeLiveness), + string(TypeReadiness), + string(TypeStartup), + } +} + +func (s *Type) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseType(input string) (*Type, error) { + vals := map[string]Type{ + "liveness": TypeLiveness, + "readiness": TypeReadiness, + "startup": TypeStartup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Type(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/id_detector.go b/resource-manager/containerapps/2025-01-01/jobs/id_detector.go new file mode 100644 index 00000000000..f25116af8c8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_detector.go @@ -0,0 +1,139 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DetectorId{}) +} + +var _ resourceids.ResourceId = &DetectorId{} + +// DetectorId is a struct representing the Resource ID for a Detector +type DetectorId struct { + SubscriptionId string + ResourceGroupName string + JobName string + DetectorName string +} + +// NewDetectorID returns a new DetectorId struct +func NewDetectorID(subscriptionId string, resourceGroupName string, jobName string, detectorName string) DetectorId { + return DetectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + DetectorName: detectorName, + } +} + +// ParseDetectorID parses 'input' into a DetectorId +func ParseDetectorID(input string) (*DetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDetectorIDInsensitively parses 'input' case-insensitively into a DetectorId +// note: this method should only be used for API response data and not user input +func ParseDetectorIDInsensitively(input string) (*DetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DetectorId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.DetectorName, ok = input.Parsed["detectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorName", input) + } + + return nil +} + +// ValidateDetectorID checks that 'input' can be parsed as a Detector ID +func ValidateDetectorID(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 := ParseDetectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Detector ID +func (id DetectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s/detectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName, id.DetectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Detector ID +func (id DetectorId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticDetectors", "detectors", "detectors"), + resourceids.UserSpecifiedSegment("detectorName", "detectorName"), + } +} + +// String returns a human-readable description of this Detector ID +func (id DetectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Detector Name: %q", id.DetectorName), + } + return fmt.Sprintf("Detector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/id_detector_test.go b/resource-manager/containerapps/2025-01-01/jobs/id_detector_test.go new file mode 100644 index 00000000000..1bf090460ec --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_detector_test.go @@ -0,0 +1,327 @@ +package jobs + +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 = &DetectorId{} + +func TestNewDetectorID(t *testing.T) { + id := NewDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.DetectorName != "detectorName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorName'", id.DetectorName, "detectorName") + } +} + +func TestFormatDetectorID(t *testing.T) { + actual := NewDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDetectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName", + Expected: &DetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestParseDetectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName", + Expected: &DetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectors/detectorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRs/dEtEcToRnAmE", + Expected: &DetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + DetectorName: "dEtEcToRnAmE", + }, + }, + { + // 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.aPp/jObS/jObNaMe/dEtEcToRs/dEtEcToRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestSegmentsForDetectorId(t *testing.T) { + segments := DetectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DetectorId 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/containerapps/2025-01-01/jobs/id_detectorproperty.go b/resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty.go new file mode 100644 index 00000000000..49d9bea5bb9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty.go @@ -0,0 +1,139 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DetectorPropertyId{}) +} + +var _ resourceids.ResourceId = &DetectorPropertyId{} + +// DetectorPropertyId is a struct representing the Resource ID for a Detector Property +type DetectorPropertyId struct { + SubscriptionId string + ResourceGroupName string + JobName string + DetectorPropertyName string +} + +// NewDetectorPropertyID returns a new DetectorPropertyId struct +func NewDetectorPropertyID(subscriptionId string, resourceGroupName string, jobName string, detectorPropertyName string) DetectorPropertyId { + return DetectorPropertyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + DetectorPropertyName: detectorPropertyName, + } +} + +// ParseDetectorPropertyID parses 'input' into a DetectorPropertyId +func ParseDetectorPropertyID(input string) (*DetectorPropertyId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorPropertyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorPropertyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDetectorPropertyIDInsensitively parses 'input' case-insensitively into a DetectorPropertyId +// note: this method should only be used for API response data and not user input +func ParseDetectorPropertyIDInsensitively(input string) (*DetectorPropertyId, error) { + parser := resourceids.NewParserFromResourceIdType(&DetectorPropertyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DetectorPropertyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DetectorPropertyId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.DetectorPropertyName, ok = input.Parsed["detectorPropertyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorPropertyName", input) + } + + return nil +} + +// ValidateDetectorPropertyID checks that 'input' can be parsed as a Detector Property ID +func ValidateDetectorPropertyID(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 := ParseDetectorPropertyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Detector Property ID +func (id DetectorPropertyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s/detectorProperties/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName, id.DetectorPropertyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Detector Property ID +func (id DetectorPropertyId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticDetectorProperties", "detectorProperties", "detectorProperties"), + resourceids.UserSpecifiedSegment("detectorPropertyName", "detectorPropertyName"), + } +} + +// String returns a human-readable description of this Detector Property ID +func (id DetectorPropertyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Detector Property Name: %q", id.DetectorPropertyName), + } + return fmt.Sprintf("Detector Property (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty_test.go b/resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty_test.go new file mode 100644 index 00000000000..ad40b146bba --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_detectorproperty_test.go @@ -0,0 +1,327 @@ +package jobs + +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 = &DetectorPropertyId{} + +func TestNewDetectorPropertyID(t *testing.T) { + id := NewDetectorPropertyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorPropertyName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.DetectorPropertyName != "detectorPropertyName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorPropertyName'", id.DetectorPropertyName, "detectorPropertyName") + } +} + +func TestFormatDetectorPropertyID(t *testing.T) { + actual := NewDetectorPropertyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "detectorPropertyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDetectorPropertyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorPropertyId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName", + Expected: &DetectorPropertyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorPropertyName: "detectorPropertyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorPropertyID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorPropertyName != v.Expected.DetectorPropertyName { + t.Fatalf("Expected %q but got %q for DetectorPropertyName", v.Expected.DetectorPropertyName, actual.DetectorPropertyName) + } + + } +} + +func TestParseDetectorPropertyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DetectorPropertyId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRpRoPeRtIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName", + Expected: &DetectorPropertyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + DetectorPropertyName: "detectorPropertyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/detectorProperties/detectorPropertyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/dEtEcToRpRoPeRtIeS/dEtEcToRpRoPeRtYnAmE", + Expected: &DetectorPropertyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + DetectorPropertyName: "dEtEcToRpRoPeRtYnAmE", + }, + }, + { + // 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.aPp/jObS/jObNaMe/dEtEcToRpRoPeRtIeS/dEtEcToRpRoPeRtYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDetectorPropertyIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.DetectorPropertyName != v.Expected.DetectorPropertyName { + t.Fatalf("Expected %q but got %q for DetectorPropertyName", v.Expected.DetectorPropertyName, actual.DetectorPropertyName) + } + + } +} + +func TestSegmentsForDetectorPropertyId(t *testing.T) { + segments := DetectorPropertyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DetectorPropertyId 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/containerapps/2025-01-01/jobs/id_execution.go b/resource-manager/containerapps/2025-01-01/jobs/id_execution.go new file mode 100644 index 00000000000..de2369fda60 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_execution.go @@ -0,0 +1,139 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExecutionId{}) +} + +var _ resourceids.ResourceId = &ExecutionId{} + +// ExecutionId is a struct representing the Resource ID for a Execution +type ExecutionId struct { + SubscriptionId string + ResourceGroupName string + JobName string + ExecutionName string +} + +// NewExecutionID returns a new ExecutionId struct +func NewExecutionID(subscriptionId string, resourceGroupName string, jobName string, executionName string) ExecutionId { + return ExecutionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + ExecutionName: executionName, + } +} + +// ParseExecutionID parses 'input' into a ExecutionId +func ParseExecutionID(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExecutionIDInsensitively parses 'input' case-insensitively into a ExecutionId +// note: this method should only be used for API response data and not user input +func ParseExecutionIDInsensitively(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExecutionId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.ExecutionName, ok = input.Parsed["executionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "executionName", input) + } + + return nil +} + +// ValidateExecutionID checks that 'input' can be parsed as a Execution ID +func ValidateExecutionID(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 := ParseExecutionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Execution ID +func (id ExecutionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s/executions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName, id.ExecutionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Execution ID +func (id ExecutionId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("executionName", "executionName"), + } +} + +// String returns a human-readable description of this Execution ID +func (id ExecutionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Execution Name: %q", id.ExecutionName), + } + return fmt.Sprintf("Execution (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/id_execution_test.go b/resource-manager/containerapps/2025-01-01/jobs/id_execution_test.go new file mode 100644 index 00000000000..259f8df1ae3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_execution_test.go @@ -0,0 +1,327 @@ +package jobs + +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 = &ExecutionId{} + +func TestNewExecutionID(t *testing.T) { + id := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "executionName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.ExecutionName != "executionName" { + t.Fatalf("Expected %q but got %q for Segment 'ExecutionName'", id.ExecutionName, "executionName") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName", "executionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions/executionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExecutionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions/executionName", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + ExecutionName: "executionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions/executionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.ExecutionName != v.Expected.ExecutionName { + t.Fatalf("Expected %q but got %q for ExecutionName", v.Expected.ExecutionName, actual.ExecutionName) + } + + } +} + +func TestParseExecutionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions/executionName", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + ExecutionName: "executionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/executions/executionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe/eXeCuTiOnS/eXeCuTiOnNaMe", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + ExecutionName: "eXeCuTiOnNaMe", + }, + }, + { + // 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.aPp/jObS/jObNaMe/eXeCuTiOnS/eXeCuTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.ExecutionName != v.Expected.ExecutionName { + t.Fatalf("Expected %q but got %q for ExecutionName", v.Expected.ExecutionName, actual.ExecutionName) + } + + } +} + +func TestSegmentsForExecutionId(t *testing.T) { + segments := ExecutionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExecutionId 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/containerapps/2025-01-01/jobs/id_job.go b/resource-manager/containerapps/2025-01-01/jobs/id_job.go new file mode 100644 index 00000000000..e84704f7f48 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_job.go @@ -0,0 +1,130 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobId{}) +} + +var _ resourceids.ResourceId = &JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobId) 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.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + return nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/id_job_test.go b/resource-manager/containerapps/2025-01-01/jobs/id_job_test.go new file mode 100644 index 00000000000..5e0ffae1af7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/id_job_test.go @@ -0,0 +1,282 @@ +package jobs + +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 = &JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName") + + 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.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "jobName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/jobs/jobName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/jObS/jObNaMe", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + JobName: "jObNaMe", + }, + }, + { + // 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.aPp/jObS/jObNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/containerapps/2025-01-01/jobs/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/jobs/method_createorupdate.go new file mode 100644 index 00000000000..ef6e9f361f5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_createorupdate.go @@ -0,0 +1,75 @@ +package jobs + +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 *Job +} + +// CreateOrUpdate ... +func (c JobsClient) CreateOrUpdate(ctx context.Context, id JobId, input Job) (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 JobsClient) CreateOrUpdateThenPoll(ctx context.Context, id JobId, input Job) 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/containerapps/2025-01-01/jobs/method_delete.go b/resource-manager/containerapps/2025-01-01/jobs/method_delete.go new file mode 100644 index 00000000000..8523d87d6af --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_delete.go @@ -0,0 +1,71 @@ +package jobs + +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 JobsClient) Delete(ctx context.Context, id JobId) (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 JobsClient) DeleteThenPoll(ctx context.Context, id JobId) 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/containerapps/2025-01-01/jobs/method_executionslist.go b/resource-manager/containerapps/2025-01-01/jobs/method_executionslist.go new file mode 100644 index 00000000000..98280e2c319 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_executionslist.go @@ -0,0 +1,134 @@ +package jobs + +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 ExecutionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type ExecutionsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type ExecutionsListOperationOptions struct { + Filter *string +} + +func DefaultExecutionsListOperationOptions() ExecutionsListOperationOptions { + return ExecutionsListOperationOptions{} +} + +func (o ExecutionsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ExecutionsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ExecutionsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ExecutionsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ExecutionsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ExecutionsList ... +func (c JobsClient) ExecutionsList(ctx context.Context, id JobId, options ExecutionsListOperationOptions) (result ExecutionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ExecutionsListCustomPager{}, + Path: fmt.Sprintf("%s/executions", 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 *[]JobExecution `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExecutionsListComplete retrieves all the results into a single object +func (c JobsClient) ExecutionsListComplete(ctx context.Context, id JobId, options ExecutionsListOperationOptions) (ExecutionsListCompleteResult, error) { + return c.ExecutionsListCompleteMatchingPredicate(ctx, id, options, JobExecutionOperationPredicate{}) +} + +// ExecutionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobsClient) ExecutionsListCompleteMatchingPredicate(ctx context.Context, id JobId, options ExecutionsListOperationOptions, predicate JobExecutionOperationPredicate) (result ExecutionsListCompleteResult, err error) { + items := make([]JobExecution, 0) + + resp, err := c.ExecutionsList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExecutionsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_get.go b/resource-manager/containerapps/2025-01-01/jobs/method_get.go new file mode 100644 index 00000000000..92dd9e2cf39 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_get.go @@ -0,0 +1,53 @@ +package jobs + +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 *Job +} + +// Get ... +func (c JobsClient) Get(ctx context.Context, id JobId) (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 Job + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_getdetector.go b/resource-manager/containerapps/2025-01-01/jobs/method_getdetector.go new file mode 100644 index 00000000000..d2957d9afaf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_getdetector.go @@ -0,0 +1,53 @@ +package jobs + +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 GetDetectorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Diagnostics +} + +// GetDetector ... +func (c JobsClient) GetDetector(ctx context.Context, id DetectorId) (result GetDetectorOperationResponse, 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 Diagnostics + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_jobexecution.go b/resource-manager/containerapps/2025-01-01/jobs/method_jobexecution.go new file mode 100644 index 00000000000..d305cdb2c5a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_jobexecution.go @@ -0,0 +1,53 @@ +package jobs + +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 JobExecutionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *JobExecution +} + +// JobExecution ... +func (c JobsClient) JobExecution(ctx context.Context, id ExecutionId) (result JobExecutionOperationResponse, 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 JobExecution + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_listbyresourcegroup.go b/resource-manager/containerapps/2025-01-01/jobs/method_listbyresourcegroup.go new file mode 100644 index 00000000000..0596f8a764b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package jobs + +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 *[]Job +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Job +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c JobsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/jobs", 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 *[]Job `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 JobsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, JobOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate JobOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Job, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_listbysubscription.go b/resource-manager/containerapps/2025-01-01/jobs/method_listbysubscription.go new file mode 100644 index 00000000000..682abb825f0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_listbysubscription.go @@ -0,0 +1,106 @@ +package jobs + +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 *[]Job +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Job +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c JobsClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/jobs", 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 *[]Job `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 JobsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, JobOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate JobOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Job, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_listdetectors.go b/resource-manager/containerapps/2025-01-01/jobs/method_listdetectors.go new file mode 100644 index 00000000000..ce52fa3e8b6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_listdetectors.go @@ -0,0 +1,105 @@ +package jobs + +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 ListDetectorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Diagnostics +} + +type ListDetectorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Diagnostics +} + +type ListDetectorsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListDetectorsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListDetectors ... +func (c JobsClient) ListDetectors(ctx context.Context, id JobId) (result ListDetectorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListDetectorsCustomPager{}, + Path: fmt.Sprintf("%s/detectors", 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 *[]Diagnostics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListDetectorsComplete retrieves all the results into a single object +func (c JobsClient) ListDetectorsComplete(ctx context.Context, id JobId) (ListDetectorsCompleteResult, error) { + return c.ListDetectorsCompleteMatchingPredicate(ctx, id, DiagnosticsOperationPredicate{}) +} + +// ListDetectorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobsClient) ListDetectorsCompleteMatchingPredicate(ctx context.Context, id JobId, predicate DiagnosticsOperationPredicate) (result ListDetectorsCompleteResult, err error) { + items := make([]Diagnostics, 0) + + resp, err := c.ListDetectors(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListDetectorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_listsecrets.go b/resource-manager/containerapps/2025-01-01/jobs/method_listsecrets.go new file mode 100644 index 00000000000..6d9e1f870c1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_listsecrets.go @@ -0,0 +1,54 @@ +package jobs + +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 ListSecretsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *JobSecretsCollection +} + +// ListSecrets ... +func (c JobsClient) ListSecrets(ctx context.Context, id JobId) (result ListSecretsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSecrets", 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 JobSecretsCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_proxyget.go b/resource-manager/containerapps/2025-01-01/jobs/method_proxyget.go new file mode 100644 index 00000000000..ae55334e586 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_proxyget.go @@ -0,0 +1,53 @@ +package jobs + +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 ProxyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Job +} + +// ProxyGet ... +func (c JobsClient) ProxyGet(ctx context.Context, id DetectorPropertyId) (result ProxyGetOperationResponse, 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 Job + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_start.go b/resource-manager/containerapps/2025-01-01/jobs/method_start.go new file mode 100644 index 00000000000..9be83c5ebf0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_start.go @@ -0,0 +1,75 @@ +package jobs + +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 StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *JobExecutionBase +} + +// Start ... +func (c JobsClient) Start(ctx context.Context, id JobId, input JobExecutionTemplate) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 +} + +// StartThenPoll performs Start then polls until it's completed +func (c JobsClient) StartThenPoll(ctx context.Context, id JobId, input JobExecutionTemplate) error { + result, err := c.Start(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_stopexecution.go b/resource-manager/containerapps/2025-01-01/jobs/method_stopexecution.go new file mode 100644 index 00000000000..47c37cf69a7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_stopexecution.go @@ -0,0 +1,70 @@ +package jobs + +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 StopExecutionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// StopExecution ... +func (c JobsClient) StopExecution(ctx context.Context, id ExecutionId) (result StopExecutionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", 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 +} + +// StopExecutionThenPoll performs StopExecution then polls until it's completed +func (c JobsClient) StopExecutionThenPoll(ctx context.Context, id ExecutionId) error { + result, err := c.StopExecution(ctx, id) + if err != nil { + return fmt.Errorf("performing StopExecution: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after StopExecution: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_stopmultipleexecutions.go b/resource-manager/containerapps/2025-01-01/jobs/method_stopmultipleexecutions.go new file mode 100644 index 00000000000..415f7ddca74 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_stopmultipleexecutions.go @@ -0,0 +1,89 @@ +package jobs + +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 StopMultipleExecutionsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type StopMultipleExecutionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type StopMultipleExecutionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *StopMultipleExecutionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// StopMultipleExecutions ... +func (c JobsClient) StopMultipleExecutions(ctx context.Context, id JobId) (result StopMultipleExecutionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &StopMultipleExecutionsCustomPager{}, + Path: fmt.Sprintf("%s/stop", 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 +} + +// StopMultipleExecutionsThenPoll performs StopMultipleExecutions then polls until it's completed +func (c JobsClient) StopMultipleExecutionsThenPoll(ctx context.Context, id JobId) error { + result, err := c.StopMultipleExecutions(ctx, id) + if err != nil { + return fmt.Errorf("performing StopMultipleExecutions: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after StopMultipleExecutions: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/method_update.go b/resource-manager/containerapps/2025-01-01/jobs/method_update.go new file mode 100644 index 00000000000..b88a194a95e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/method_update.go @@ -0,0 +1,75 @@ +package jobs + +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 *Job +} + +// Update ... +func (c JobsClient) Update(ctx context.Context, id JobId, input JobPatchProperties) (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 JobsClient) UpdateThenPoll(ctx context.Context, id JobId, input JobPatchProperties) 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/containerapps/2025-01-01/jobs/model_basecontainer.go b/resource-manager/containerapps/2025-01-01/jobs/model_basecontainer.go new file mode 100644 index 00000000000..e2472facf92 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_basecontainer.go @@ -0,0 +1,14 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseContainer struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_container.go b/resource-manager/containerapps/2025-01-01/jobs/model_container.go new file mode 100644 index 00000000000..803c30e898e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_container.go @@ -0,0 +1,15 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Container struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Probes *[]ContainerAppProbe `json:"probes,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` + VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobe.go b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobe.go new file mode 100644 index 00000000000..e89f40cc897 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobe.go @@ -0,0 +1,16 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbe struct { + FailureThreshold *int64 `json:"failureThreshold,omitempty"` + HTTPGet *ContainerAppProbeHTTPGet `json:"httpGet,omitempty"` + InitialDelaySeconds *int64 `json:"initialDelaySeconds,omitempty"` + PeriodSeconds *int64 `json:"periodSeconds,omitempty"` + SuccessThreshold *int64 `json:"successThreshold,omitempty"` + TcpSocket *ContainerAppProbeTcpSocket `json:"tcpSocket,omitempty"` + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"` + Type *Type `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpget.go b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpget.go new file mode 100644 index 00000000000..1ab675e4593 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpget.go @@ -0,0 +1,12 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGet struct { + HTTPHeaders *[]ContainerAppProbeHTTPGetHTTPHeadersInlined `json:"httpHeaders,omitempty"` + Host *string `json:"host,omitempty"` + Path *string `json:"path,omitempty"` + Port int64 `json:"port"` + Scheme *Scheme `json:"scheme,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpgethttpheadersinlined.go b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpgethttpheadersinlined.go new file mode 100644 index 00000000000..becc34945ce --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobehttpgethttpheadersinlined.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeHTTPGetHTTPHeadersInlined struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobetcpsocket.go b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobetcpsocket.go new file mode 100644 index 00000000000..e9e583e3982 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_containerappprobetcpsocket.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerAppProbeTcpSocket struct { + Host *string `json:"host,omitempty"` + Port int64 `json:"port"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_containerresources.go b/resource-manager/containerapps/2025-01-01/jobs/model_containerresources.go new file mode 100644 index 00000000000..f48b9f76786 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_containerresources.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerResources struct { + Cpu *float64 `json:"cpu,omitempty"` + EphemeralStorage *string `json:"ephemeralStorage,omitempty"` + Memory *string `json:"memory,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadata.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadata.go new file mode 100644 index 00000000000..06c119bbae1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadata.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadata struct { + PropertyBag *[]DiagnosticDataProviderMetadataPropertyBagInlined `json:"propertyBag,omitempty"` + ProviderName *string `json:"providerName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadatapropertybaginlined.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadatapropertybaginlined.go new file mode 100644 index 00000000000..04a6fbcd52e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdataprovidermetadatapropertybaginlined.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadataPropertyBagInlined struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponsecolumn.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponsecolumn.go new file mode 100644 index 00000000000..a26027ca613 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponsecolumn.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseColumn struct { + ColumnName *string `json:"columnName,omitempty"` + ColumnType *string `json:"columnType,omitempty"` + DataType *string `json:"dataType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponseobject.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponseobject.go new file mode 100644 index 00000000000..b69b892b9ed --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticdatatableresponseobject.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseObject struct { + Columns *[]DiagnosticDataTableResponseColumn `json:"columns,omitempty"` + Rows *[]interface{} `json:"rows,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticrendering.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticrendering.go new file mode 100644 index 00000000000..157c4b30835 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticrendering.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticRendering struct { + Description *string `json:"description,omitempty"` + IsVisible *bool `json:"isVisible,omitempty"` + Title *string `json:"title,omitempty"` + Type *int64 `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnostics.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnostics.go new file mode 100644 index 00000000000..7ae29be0ad6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnostics.go @@ -0,0 +1,16 @@ +package jobs + +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 Diagnostics struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdataapiresponse.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdataapiresponse.go new file mode 100644 index 00000000000..57329a4aea3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdataapiresponse.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDataApiResponse struct { + RenderingProperties *DiagnosticRendering `json:"renderingProperties,omitempty"` + Table *DiagnosticDataTableResponseObject `json:"table,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdefinition.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdefinition.go new file mode 100644 index 00000000000..9ffb303aaae --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsdefinition.go @@ -0,0 +1,16 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDefinition struct { + AnalysisTypes *[]string `json:"analysisTypes,omitempty"` + Author *string `json:"author,omitempty"` + Category *string `json:"category,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Score *float64 `json:"score,omitempty"` + SupportTopicList *[]DiagnosticSupportTopic `json:"supportTopicList,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsproperties.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsproperties.go new file mode 100644 index 00000000000..a6012a1a0dd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsproperties.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsProperties struct { + DataProviderMetadata *DiagnosticDataProviderMetadata `json:"dataProviderMetadata,omitempty"` + Dataset *[]DiagnosticsDataApiResponse `json:"dataset,omitempty"` + Metadata *DiagnosticsDefinition `json:"metadata,omitempty"` + Status *DiagnosticsStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsstatus.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsstatus.go new file mode 100644 index 00000000000..0ff1fe8b90c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsstatus.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsStatus struct { + Message *string `json:"message,omitempty"` + StatusId *int64 `json:"statusId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsupporttopic.go b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsupporttopic.go new file mode 100644 index 00000000000..a68cb40cb63 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_diagnosticsupporttopic.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSupportTopic struct { + Id *string `json:"id,omitempty"` + PesId *string `json:"pesId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_environmentvar.go b/resource-manager/containerapps/2025-01-01/jobs/model_environmentvar.go new file mode 100644 index 00000000000..ca2a887d4a4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_environmentvar.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentVar struct { + Name *string `json:"name,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_identitysettings.go b/resource-manager/containerapps/2025-01-01/jobs/model_identitysettings.go new file mode 100644 index 00000000000..8ab254c0e99 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_identitysettings.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentitySettings struct { + Identity string `json:"identity"` + Lifecycle *IdentitySettingsLifeCycle `json:"lifecycle,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_job.go b/resource-manager/containerapps/2025-01-01/jobs/model_job.go new file mode 100644 index 00000000000..ba41ac0c4a3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_job.go @@ -0,0 +1,20 @@ +package jobs + +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 Job struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *JobProperties `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/containerapps/2025-01-01/jobs/model_jobconfiguration.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfiguration.go new file mode 100644 index 00000000000..a440282f069 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfiguration.go @@ -0,0 +1,16 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfiguration struct { + EventTriggerConfig *JobConfigurationEventTriggerConfig `json:"eventTriggerConfig,omitempty"` + IdentitySettings *[]IdentitySettings `json:"identitySettings,omitempty"` + ManualTriggerConfig *JobConfigurationManualTriggerConfig `json:"manualTriggerConfig,omitempty"` + Registries *[]RegistryCredentials `json:"registries,omitempty"` + ReplicaRetryLimit *int64 `json:"replicaRetryLimit,omitempty"` + ReplicaTimeout int64 `json:"replicaTimeout"` + ScheduleTriggerConfig *JobConfigurationScheduleTriggerConfig `json:"scheduleTriggerConfig,omitempty"` + Secrets *[]Secret `json:"secrets,omitempty"` + TriggerType TriggerType `json:"triggerType"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationeventtriggerconfig.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationeventtriggerconfig.go new file mode 100644 index 00000000000..a50616ad9c4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationeventtriggerconfig.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfigurationEventTriggerConfig struct { + Parallelism *int64 `json:"parallelism,omitempty"` + ReplicaCompletionCount *int64 `json:"replicaCompletionCount,omitempty"` + Scale *JobScale `json:"scale,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationmanualtriggerconfig.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationmanualtriggerconfig.go new file mode 100644 index 00000000000..bb4bd29d5ac --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationmanualtriggerconfig.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfigurationManualTriggerConfig struct { + Parallelism *int64 `json:"parallelism,omitempty"` + ReplicaCompletionCount *int64 `json:"replicaCompletionCount,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationscheduletriggerconfig.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationscheduletriggerconfig.go new file mode 100644 index 00000000000..6e82bdb6621 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobconfigurationscheduletriggerconfig.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobConfigurationScheduleTriggerConfig struct { + CronExpression string `json:"cronExpression"` + Parallelism *int64 `json:"parallelism,omitempty"` + ReplicaCompletionCount *int64 `json:"replicaCompletionCount,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobexecution.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecution.go new file mode 100644 index 00000000000..04a28d5b095 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecution.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecution struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobExecutionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionbase.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionbase.go new file mode 100644 index 00000000000..b6bf9e5b55b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionbase.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionBase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutioncontainer.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutioncontainer.go new file mode 100644 index 00000000000..709af1fd836 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutioncontainer.go @@ -0,0 +1,13 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionContainer struct { + Args *[]string `json:"args,omitempty"` + Command *[]string `json:"command,omitempty"` + Env *[]EnvironmentVar `json:"env,omitempty"` + Image *string `json:"image,omitempty"` + Name *string `json:"name,omitempty"` + Resources *ContainerResources `json:"resources,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionproperties.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionproperties.go new file mode 100644 index 00000000000..2587bfd7515 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutionproperties.go @@ -0,0 +1,41 @@ +package jobs + +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 JobExecutionProperties struct { + EndTime *string `json:"endTime,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *JobExecutionRunningState `json:"status,omitempty"` + Template *JobExecutionTemplate `json:"template,omitempty"` +} + +func (o *JobExecutionProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobExecutionProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutiontemplate.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutiontemplate.go new file mode 100644 index 00000000000..b7f77c77693 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobexecutiontemplate.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionTemplate struct { + Containers *[]JobExecutionContainer `json:"containers,omitempty"` + InitContainers *[]JobExecutionContainer `json:"initContainers,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobpatchproperties.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobpatchproperties.go new file mode 100644 index 00000000000..38da76cd7f4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobpatchproperties.go @@ -0,0 +1,14 @@ +package jobs + +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 JobPatchProperties struct { + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *JobPatchPropertiesProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobpatchpropertiesproperties.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobpatchpropertiesproperties.go new file mode 100644 index 00000000000..c1d2ed337c2 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobpatchpropertiesproperties.go @@ -0,0 +1,12 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobPatchPropertiesProperties struct { + Configuration *JobConfiguration `json:"configuration,omitempty"` + EnvironmentId *string `json:"environmentId,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + OutboundIPAddresses *[]string `json:"outboundIpAddresses,omitempty"` + Template *JobTemplate `json:"template,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobproperties.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobproperties.go new file mode 100644 index 00000000000..9865a06d79f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobproperties.go @@ -0,0 +1,14 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobProperties struct { + Configuration *JobConfiguration `json:"configuration,omitempty"` + EnvironmentId *string `json:"environmentId,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + OutboundIPAddresses *[]string `json:"outboundIpAddresses,omitempty"` + ProvisioningState *JobProvisioningState `json:"provisioningState,omitempty"` + Template *JobTemplate `json:"template,omitempty"` + WorkloadProfileName *string `json:"workloadProfileName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobscale.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobscale.go new file mode 100644 index 00000000000..c13b18eea1b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobscale.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobScale struct { + MaxExecutions *int64 `json:"maxExecutions,omitempty"` + MinExecutions *int64 `json:"minExecutions,omitempty"` + PollingInterval *int64 `json:"pollingInterval,omitempty"` + Rules *[]JobScaleRule `json:"rules,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobscalerule.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobscalerule.go new file mode 100644 index 00000000000..5ee06f9d1fa --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobscalerule.go @@ -0,0 +1,12 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobScaleRule struct { + Auth *[]ScaleRuleAuth `json:"auth,omitempty"` + Identity *string `json:"identity,omitempty"` + Metadata *interface{} `json:"metadata,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobsecretscollection.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobsecretscollection.go new file mode 100644 index 00000000000..9844058eda6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobsecretscollection.go @@ -0,0 +1,8 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSecretsCollection struct { + Value []Secret `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_jobtemplate.go b/resource-manager/containerapps/2025-01-01/jobs/model_jobtemplate.go new file mode 100644 index 00000000000..6e9bce871a9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_jobtemplate.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobTemplate struct { + Containers *[]Container `json:"containers,omitempty"` + InitContainers *[]BaseContainer `json:"initContainers,omitempty"` + Volumes *[]Volume `json:"volumes,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_registrycredentials.go b/resource-manager/containerapps/2025-01-01/jobs/model_registrycredentials.go new file mode 100644 index 00000000000..c82f4c12456 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_registrycredentials.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryCredentials struct { + Identity *string `json:"identity,omitempty"` + PasswordSecretRef *string `json:"passwordSecretRef,omitempty"` + Server *string `json:"server,omitempty"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_scaleruleauth.go b/resource-manager/containerapps/2025-01-01/jobs/model_scaleruleauth.go new file mode 100644 index 00000000000..92b41db202a --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_scaleruleauth.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScaleRuleAuth struct { + SecretRef *string `json:"secretRef,omitempty"` + TriggerParameter *string `json:"triggerParameter,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_secret.go b/resource-manager/containerapps/2025-01-01/jobs/model_secret.go new file mode 100644 index 00000000000..ceb107ac443 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_secret.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Secret struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_secretvolumeitem.go b/resource-manager/containerapps/2025-01-01/jobs/model_secretvolumeitem.go new file mode 100644 index 00000000000..bfa219692a9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_secretvolumeitem.go @@ -0,0 +1,9 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretVolumeItem struct { + Path *string `json:"path,omitempty"` + SecretRef *string `json:"secretRef,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_volume.go b/resource-manager/containerapps/2025-01-01/jobs/model_volume.go new file mode 100644 index 00000000000..4414f8230a1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_volume.go @@ -0,0 +1,12 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Volume struct { + MountOptions *string `json:"mountOptions,omitempty"` + Name *string `json:"name,omitempty"` + Secrets *[]SecretVolumeItem `json:"secrets,omitempty"` + StorageName *string `json:"storageName,omitempty"` + StorageType *StorageType `json:"storageType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/model_volumemount.go b/resource-manager/containerapps/2025-01-01/jobs/model_volumemount.go new file mode 100644 index 00000000000..2274bfc6b08 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/model_volumemount.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VolumeMount struct { + MountPath *string `json:"mountPath,omitempty"` + SubPath *string `json:"subPath,omitempty"` + VolumeName *string `json:"volumeName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/jobs/predicates.go b/resource-manager/containerapps/2025-01-01/jobs/predicates.go new file mode 100644 index 00000000000..d558cc7f436 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/predicates.go @@ -0,0 +1,78 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DiagnosticsOperationPredicate) Matches(input Diagnostics) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type JobOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p JobOperationPredicate) Matches(input Job) 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 +} + +type JobExecutionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobExecutionOperationPredicate) Matches(input JobExecution) 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/containerapps/2025-01-01/jobs/version.go b/resource-manager/containerapps/2025-01-01/jobs/version.go new file mode 100644 index 00000000000..25929062310 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/jobs/version.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobs/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/README.md b/resource-manager/containerapps/2025-01-01/managedcertificates/README.md new file mode 100644 index 00000000000..cddd995d681 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/README.md @@ -0,0 +1,107 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedcertificates` Documentation + +The `managedcertificates` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedcertificates" +``` + + +### Client Initialization + +```go +client := managedcertificates.NewManagedCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedCertificatesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedcertificates.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +payload := managedcertificates.ManagedCertificate{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedCertificatesClient.Delete` + +```go +ctx := context.TODO() +id := managedcertificates.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedCertificatesClient.Get` + +```go +ctx := context.TODO() +id := managedcertificates.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +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: `ManagedCertificatesClient.List` + +```go +ctx := context.TODO() +id := managedcertificates.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// 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: `ManagedCertificatesClient.Update` + +```go +ctx := context.TODO() +id := managedcertificates.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +payload := managedcertificates.ManagedCertificatePatch{ + // ... +} + + +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/containerapps/2025-01-01/managedcertificates/client.go b/resource-manager/containerapps/2025-01-01/managedcertificates/client.go new file mode 100644 index 00000000000..bbb557ef073 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/client.go @@ -0,0 +1,26 @@ +package managedcertificates + +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 ManagedCertificatesClient struct { + Client *resourcemanager.Client +} + +func NewManagedCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedCertificatesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedcertificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedCertificatesClient: %+v", err) + } + + return &ManagedCertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/constants.go b/resource-manager/containerapps/2025-01-01/managedcertificates/constants.go new file mode 100644 index 00000000000..cf87213c665 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/constants.go @@ -0,0 +1,104 @@ +package managedcertificates + +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 CertificateProvisioningState string + +const ( + CertificateProvisioningStateCanceled CertificateProvisioningState = "Canceled" + CertificateProvisioningStateDeleteFailed CertificateProvisioningState = "DeleteFailed" + CertificateProvisioningStateFailed CertificateProvisioningState = "Failed" + CertificateProvisioningStatePending CertificateProvisioningState = "Pending" + CertificateProvisioningStateSucceeded CertificateProvisioningState = "Succeeded" +) + +func PossibleValuesForCertificateProvisioningState() []string { + return []string{ + string(CertificateProvisioningStateCanceled), + string(CertificateProvisioningStateDeleteFailed), + string(CertificateProvisioningStateFailed), + string(CertificateProvisioningStatePending), + string(CertificateProvisioningStateSucceeded), + } +} + +func (s *CertificateProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateProvisioningState(input string) (*CertificateProvisioningState, error) { + vals := map[string]CertificateProvisioningState{ + "canceled": CertificateProvisioningStateCanceled, + "deletefailed": CertificateProvisioningStateDeleteFailed, + "failed": CertificateProvisioningStateFailed, + "pending": CertificateProvisioningStatePending, + "succeeded": CertificateProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateProvisioningState(input) + return &out, nil +} + +type ManagedCertificateDomainControlValidation string + +const ( + ManagedCertificateDomainControlValidationCNAME ManagedCertificateDomainControlValidation = "CNAME" + ManagedCertificateDomainControlValidationHTTP ManagedCertificateDomainControlValidation = "HTTP" + ManagedCertificateDomainControlValidationTXT ManagedCertificateDomainControlValidation = "TXT" +) + +func PossibleValuesForManagedCertificateDomainControlValidation() []string { + return []string{ + string(ManagedCertificateDomainControlValidationCNAME), + string(ManagedCertificateDomainControlValidationHTTP), + string(ManagedCertificateDomainControlValidationTXT), + } +} + +func (s *ManagedCertificateDomainControlValidation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedCertificateDomainControlValidation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedCertificateDomainControlValidation(input string) (*ManagedCertificateDomainControlValidation, error) { + vals := map[string]ManagedCertificateDomainControlValidation{ + "cname": ManagedCertificateDomainControlValidationCNAME, + "http": ManagedCertificateDomainControlValidationHTTP, + "txt": ManagedCertificateDomainControlValidationTXT, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedCertificateDomainControlValidation(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate.go b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate.go new file mode 100644 index 00000000000..f3ed5ed197f --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate.go @@ -0,0 +1,139 @@ +package managedcertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedCertificateId{}) +} + +var _ resourceids.ResourceId = &ManagedCertificateId{} + +// ManagedCertificateId is a struct representing the Resource ID for a Managed Certificate +type ManagedCertificateId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + ManagedCertificateName string +} + +// NewManagedCertificateID returns a new ManagedCertificateId struct +func NewManagedCertificateID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, managedCertificateName string) ManagedCertificateId { + return ManagedCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + ManagedCertificateName: managedCertificateName, + } +} + +// ParseManagedCertificateID parses 'input' into a ManagedCertificateId +func ParseManagedCertificateID(input string) (*ManagedCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedCertificateIDInsensitively parses 'input' case-insensitively into a ManagedCertificateId +// note: this method should only be used for API response data and not user input +func ParseManagedCertificateIDInsensitively(input string) (*ManagedCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedCertificateId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.ManagedCertificateName, ok = input.Parsed["managedCertificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedCertificateName", input) + } + + return nil +} + +// ValidateManagedCertificateID checks that 'input' can be parsed as a Managed Certificate ID +func ValidateManagedCertificateID(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 := ParseManagedCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Certificate ID +func (id ManagedCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/managedCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.ManagedCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Certificate ID +func (id ManagedCertificateId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticManagedCertificates", "managedCertificates", "managedCertificates"), + resourceids.UserSpecifiedSegment("managedCertificateName", "managedCertificateName"), + } +} + +// String returns a human-readable description of this Managed Certificate ID +func (id ManagedCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Managed Certificate Name: %q", id.ManagedCertificateName), + } + return fmt.Sprintf("Managed Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate_test.go b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate_test.go new file mode 100644 index 00000000000..b22355e3dde --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedcertificate_test.go @@ -0,0 +1,327 @@ +package managedcertificates + +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 = &ManagedCertificateId{} + +func TestNewManagedCertificateID(t *testing.T) { + id := NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.ManagedCertificateName != "managedCertificateName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedCertificateName'", id.ManagedCertificateName, "managedCertificateName") + } +} + +func TestFormatManagedCertificateID(t *testing.T) { + actual := NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName", + Expected: &ManagedCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + ManagedCertificateName: "managedCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedCertificateID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.ManagedCertificateName != v.Expected.ManagedCertificateName { + t.Fatalf("Expected %q but got %q for ManagedCertificateName", v.Expected.ManagedCertificateName, actual.ManagedCertificateName) + } + + } +} + +func TestParseManagedCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/mAnAgEdCeRtIfIcAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName", + Expected: &ManagedCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + ManagedCertificateName: "managedCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/mAnAgEdCeRtIfIcAtEs/mAnAgEdCeRtIfIcAtEnAmE", + Expected: &ManagedCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + ManagedCertificateName: "mAnAgEdCeRtIfIcAtEnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/mAnAgEdCeRtIfIcAtEs/mAnAgEdCeRtIfIcAtEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedCertificateIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.ManagedCertificateName != v.Expected.ManagedCertificateName { + t.Fatalf("Expected %q but got %q for ManagedCertificateName", v.Expected.ManagedCertificateName, actual.ManagedCertificateName) + } + + } +} + +func TestSegmentsForManagedCertificateId(t *testing.T) { + segments := ManagedCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedCertificateId 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/containerapps/2025-01-01/managedcertificates/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment.go new file mode 100644 index 00000000000..1e87b57c6ff --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment.go @@ -0,0 +1,130 @@ +package managedcertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment_test.go new file mode 100644 index 00000000000..b21a37c9029 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package managedcertificates + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/managedcertificates/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/managedcertificates/method_createorupdate.go new file mode 100644 index 00000000000..e94da589871 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/method_createorupdate.go @@ -0,0 +1,75 @@ +package managedcertificates + +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 *ManagedCertificate +} + +// CreateOrUpdate ... +func (c ManagedCertificatesClient) CreateOrUpdate(ctx context.Context, id ManagedCertificateId, input ManagedCertificate) (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 ManagedCertificatesClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedCertificateId, input ManagedCertificate) 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/containerapps/2025-01-01/managedcertificates/method_delete.go b/resource-manager/containerapps/2025-01-01/managedcertificates/method_delete.go new file mode 100644 index 00000000000..14acf6d7f88 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/method_delete.go @@ -0,0 +1,47 @@ +package managedcertificates + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedCertificatesClient) Delete(ctx context.Context, id ManagedCertificateId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/method_get.go b/resource-manager/containerapps/2025-01-01/managedcertificates/method_get.go new file mode 100644 index 00000000000..04cfdd52374 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/method_get.go @@ -0,0 +1,53 @@ +package managedcertificates + +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 *ManagedCertificate +} + +// Get ... +func (c ManagedCertificatesClient) Get(ctx context.Context, id ManagedCertificateId) (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 ManagedCertificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/method_list.go b/resource-manager/containerapps/2025-01-01/managedcertificates/method_list.go new file mode 100644 index 00000000000..d0b02d0a3ee --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/method_list.go @@ -0,0 +1,105 @@ +package managedcertificates + +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 *[]ManagedCertificate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedCertificate +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ManagedCertificatesClient) List(ctx context.Context, id ManagedEnvironmentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/managedCertificates", 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 *[]ManagedCertificate `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 ManagedCertificatesClient) ListComplete(ctx context.Context, id ManagedEnvironmentId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ManagedCertificateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedCertificatesClient) ListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate ManagedCertificateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ManagedCertificate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/method_update.go b/resource-manager/containerapps/2025-01-01/managedcertificates/method_update.go new file mode 100644 index 00000000000..a517009cae7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/method_update.go @@ -0,0 +1,57 @@ +package managedcertificates + +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 *ManagedCertificate +} + +// Update ... +func (c ManagedCertificatesClient) Update(ctx context.Context, id ManagedCertificateId, input ManagedCertificatePatch) (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 ManagedCertificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificate.go b/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificate.go new file mode 100644 index 00000000000..5e6732f19ce --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificate.go @@ -0,0 +1,18 @@ +package managedcertificates + +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 ManagedCertificate struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedCertificateProperties `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/containerapps/2025-01-01/managedcertificates/model_managedcertificatepatch.go b/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificatepatch.go new file mode 100644 index 00000000000..856b680a8f5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificatepatch.go @@ -0,0 +1,8 @@ +package managedcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedCertificatePatch struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificateproperties.go b/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificateproperties.go new file mode 100644 index 00000000000..6c1d6afb577 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/model_managedcertificateproperties.go @@ -0,0 +1,12 @@ +package managedcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedCertificateProperties struct { + DomainControlValidation *ManagedCertificateDomainControlValidation `json:"domainControlValidation,omitempty"` + Error *string `json:"error,omitempty"` + ProvisioningState *CertificateProvisioningState `json:"provisioningState,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + ValidationToken *string `json:"validationToken,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedcertificates/predicates.go b/resource-manager/containerapps/2025-01-01/managedcertificates/predicates.go new file mode 100644 index 00000000000..08e68d7dbf0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/predicates.go @@ -0,0 +1,32 @@ +package managedcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedCertificateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedCertificateOperationPredicate) Matches(input ManagedCertificate) 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/containerapps/2025-01-01/managedcertificates/version.go b/resource-manager/containerapps/2025-01-01/managedcertificates/version.go new file mode 100644 index 00000000000..024e51c299b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedcertificates/version.go @@ -0,0 +1,10 @@ +package managedcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedcertificates/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/README.md b/resource-manager/containerapps/2025-01-01/managedenvironments/README.md new file mode 100644 index 00000000000..c21c5f855aa --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/README.md @@ -0,0 +1,398 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironments` Documentation + +The `managedenvironments` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironments" +``` + + +### Client Initialization + +```go +client := managedenvironments.NewManagedEnvironmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedEnvironmentsClient.CertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := managedenvironments.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +payload := managedenvironments.Certificate{ + // ... +} + + +read, err := client.CertificatesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.CertificatesDelete` + +```go +ctx := context.TODO() +id := managedenvironments.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +read, err := client.CertificatesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.CertificatesGet` + +```go +ctx := context.TODO() +id := managedenvironments.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +read, err := client.CertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.CertificatesList` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// alternatively `client.CertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.CertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.CertificatesUpdate` + +```go +ctx := context.TODO() +id := managedenvironments.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + +payload := managedenvironments.CertificatePatch{ + // ... +} + + +read, err := client.CertificatesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +payload := managedenvironments.ManagedEnvironment{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.Delete` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.DiagnosticsGetRoot` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +read, err := client.DiagnosticsGetRoot(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.Get` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +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: `ManagedEnvironmentsClient.GetAuthToken` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +read, err := client.GetAuthToken(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.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: `ManagedEnvironmentsClient.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: `ManagedEnvironmentsClient.ListWorkloadProfileStates` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// alternatively `client.ListWorkloadProfileStates(ctx, id)` can be used to do batched pagination +items, err := client.ListWorkloadProfileStatesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedCertificatesCreateOrUpdate` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +payload := managedenvironments.ManagedCertificate{ + // ... +} + + +if err := client.ManagedCertificatesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedCertificatesDelete` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +read, err := client.ManagedCertificatesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedCertificatesGet` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +read, err := client.ManagedCertificatesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedCertificatesList` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// alternatively `client.ManagedCertificatesList(ctx, id)` can be used to do batched pagination +items, err := client.ManagedCertificatesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedCertificatesUpdate` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + +payload := managedenvironments.ManagedCertificatePatch{ + // ... +} + + +read, err := client.ManagedCertificatesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedEnvironmentDiagnosticsGetDetector` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "detectorName") + +read, err := client.ManagedEnvironmentDiagnosticsGetDetector(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.ManagedEnvironmentDiagnosticsListDetectors` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// alternatively `client.ManagedEnvironmentDiagnosticsListDetectors(ctx, id)` can be used to do batched pagination +items, err := client.ManagedEnvironmentDiagnosticsListDetectorsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.NamespacesCheckNameAvailability` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +payload := managedenvironments.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.NamespacesCheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsClient.Update` + +```go +ctx := context.TODO() +id := managedenvironments.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +payload := managedenvironments.ManagedEnvironment{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/client.go b/resource-manager/containerapps/2025-01-01/managedenvironments/client.go new file mode 100644 index 00000000000..b7d8992fa30 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/client.go @@ -0,0 +1,26 @@ +package managedenvironments + +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 ManagedEnvironmentsClient struct { + Client *resourcemanager.Client +} + +func NewManagedEnvironmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedEnvironmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedenvironments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedEnvironmentsClient: %+v", err) + } + + return &ManagedEnvironmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/constants.go b/resource-manager/containerapps/2025-01-01/managedenvironments/constants.go new file mode 100644 index 00000000000..012abd06faa --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/constants.go @@ -0,0 +1,210 @@ +package managedenvironments + +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 CertificateProvisioningState string + +const ( + CertificateProvisioningStateCanceled CertificateProvisioningState = "Canceled" + CertificateProvisioningStateDeleteFailed CertificateProvisioningState = "DeleteFailed" + CertificateProvisioningStateFailed CertificateProvisioningState = "Failed" + CertificateProvisioningStatePending CertificateProvisioningState = "Pending" + CertificateProvisioningStateSucceeded CertificateProvisioningState = "Succeeded" +) + +func PossibleValuesForCertificateProvisioningState() []string { + return []string{ + string(CertificateProvisioningStateCanceled), + string(CertificateProvisioningStateDeleteFailed), + string(CertificateProvisioningStateFailed), + string(CertificateProvisioningStatePending), + string(CertificateProvisioningStateSucceeded), + } +} + +func (s *CertificateProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateProvisioningState(input string) (*CertificateProvisioningState, error) { + vals := map[string]CertificateProvisioningState{ + "canceled": CertificateProvisioningStateCanceled, + "deletefailed": CertificateProvisioningStateDeleteFailed, + "failed": CertificateProvisioningStateFailed, + "pending": CertificateProvisioningStatePending, + "succeeded": CertificateProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateProvisioningState(input) + return &out, nil +} + +type CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} + +type EnvironmentProvisioningState string + +const ( + EnvironmentProvisioningStateCanceled EnvironmentProvisioningState = "Canceled" + EnvironmentProvisioningStateFailed EnvironmentProvisioningState = "Failed" + EnvironmentProvisioningStateInfrastructureSetupComplete EnvironmentProvisioningState = "InfrastructureSetupComplete" + EnvironmentProvisioningStateInfrastructureSetupInProgress EnvironmentProvisioningState = "InfrastructureSetupInProgress" + EnvironmentProvisioningStateInitializationInProgress EnvironmentProvisioningState = "InitializationInProgress" + EnvironmentProvisioningStateScheduledForDelete EnvironmentProvisioningState = "ScheduledForDelete" + EnvironmentProvisioningStateSucceeded EnvironmentProvisioningState = "Succeeded" + EnvironmentProvisioningStateUpgradeFailed EnvironmentProvisioningState = "UpgradeFailed" + EnvironmentProvisioningStateUpgradeRequested EnvironmentProvisioningState = "UpgradeRequested" + EnvironmentProvisioningStateWaiting EnvironmentProvisioningState = "Waiting" +) + +func PossibleValuesForEnvironmentProvisioningState() []string { + return []string{ + string(EnvironmentProvisioningStateCanceled), + string(EnvironmentProvisioningStateFailed), + string(EnvironmentProvisioningStateInfrastructureSetupComplete), + string(EnvironmentProvisioningStateInfrastructureSetupInProgress), + string(EnvironmentProvisioningStateInitializationInProgress), + string(EnvironmentProvisioningStateScheduledForDelete), + string(EnvironmentProvisioningStateSucceeded), + string(EnvironmentProvisioningStateUpgradeFailed), + string(EnvironmentProvisioningStateUpgradeRequested), + string(EnvironmentProvisioningStateWaiting), + } +} + +func (s *EnvironmentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnvironmentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnvironmentProvisioningState(input string) (*EnvironmentProvisioningState, error) { + vals := map[string]EnvironmentProvisioningState{ + "canceled": EnvironmentProvisioningStateCanceled, + "failed": EnvironmentProvisioningStateFailed, + "infrastructuresetupcomplete": EnvironmentProvisioningStateInfrastructureSetupComplete, + "infrastructuresetupinprogress": EnvironmentProvisioningStateInfrastructureSetupInProgress, + "initializationinprogress": EnvironmentProvisioningStateInitializationInProgress, + "scheduledfordelete": EnvironmentProvisioningStateScheduledForDelete, + "succeeded": EnvironmentProvisioningStateSucceeded, + "upgradefailed": EnvironmentProvisioningStateUpgradeFailed, + "upgraderequested": EnvironmentProvisioningStateUpgradeRequested, + "waiting": EnvironmentProvisioningStateWaiting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnvironmentProvisioningState(input) + return &out, nil +} + +type ManagedCertificateDomainControlValidation string + +const ( + ManagedCertificateDomainControlValidationCNAME ManagedCertificateDomainControlValidation = "CNAME" + ManagedCertificateDomainControlValidationHTTP ManagedCertificateDomainControlValidation = "HTTP" + ManagedCertificateDomainControlValidationTXT ManagedCertificateDomainControlValidation = "TXT" +) + +func PossibleValuesForManagedCertificateDomainControlValidation() []string { + return []string{ + string(ManagedCertificateDomainControlValidationCNAME), + string(ManagedCertificateDomainControlValidationHTTP), + string(ManagedCertificateDomainControlValidationTXT), + } +} + +func (s *ManagedCertificateDomainControlValidation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedCertificateDomainControlValidation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedCertificateDomainControlValidation(input string) (*ManagedCertificateDomainControlValidation, error) { + vals := map[string]ManagedCertificateDomainControlValidation{ + "cname": ManagedCertificateDomainControlValidationCNAME, + "http": ManagedCertificateDomainControlValidationHTTP, + "txt": ManagedCertificateDomainControlValidationTXT, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedCertificateDomainControlValidation(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate.go new file mode 100644 index 00000000000..193012b6d19 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate.go @@ -0,0 +1,139 @@ +package managedenvironments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CertificateId{}) +} + +var _ resourceids.ResourceId = &CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CertificateId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.CertificateName, ok = input.Parsed["certificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "certificateName", input) + } + + return nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(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 := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateName"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate_test.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate_test.go new file mode 100644 index 00000000000..93c0065d1e4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_certificate_test.go @@ -0,0 +1,327 @@ +package managedenvironments + +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 = &CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.CertificateName != "certificateName" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateName") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "certificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + CertificateName: "certificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/certificates/certificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + CertificateName: "cErTiFiCaTeNaMe", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/cErTiFiCaTeS/cErTiFiCaTeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId 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/containerapps/2025-01-01/managedenvironments/id_managedcertificate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate.go new file mode 100644 index 00000000000..59ca7e0eed9 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate.go @@ -0,0 +1,139 @@ +package managedenvironments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedCertificateId{}) +} + +var _ resourceids.ResourceId = &ManagedCertificateId{} + +// ManagedCertificateId is a struct representing the Resource ID for a Managed Certificate +type ManagedCertificateId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + ManagedCertificateName string +} + +// NewManagedCertificateID returns a new ManagedCertificateId struct +func NewManagedCertificateID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, managedCertificateName string) ManagedCertificateId { + return ManagedCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + ManagedCertificateName: managedCertificateName, + } +} + +// ParseManagedCertificateID parses 'input' into a ManagedCertificateId +func ParseManagedCertificateID(input string) (*ManagedCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedCertificateIDInsensitively parses 'input' case-insensitively into a ManagedCertificateId +// note: this method should only be used for API response data and not user input +func ParseManagedCertificateIDInsensitively(input string) (*ManagedCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedCertificateId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.ManagedCertificateName, ok = input.Parsed["managedCertificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedCertificateName", input) + } + + return nil +} + +// ValidateManagedCertificateID checks that 'input' can be parsed as a Managed Certificate ID +func ValidateManagedCertificateID(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 := ParseManagedCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Certificate ID +func (id ManagedCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/managedCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.ManagedCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Certificate ID +func (id ManagedCertificateId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticManagedCertificates", "managedCertificates", "managedCertificates"), + resourceids.UserSpecifiedSegment("managedCertificateName", "managedCertificateName"), + } +} + +// String returns a human-readable description of this Managed Certificate ID +func (id ManagedCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Managed Certificate Name: %q", id.ManagedCertificateName), + } + return fmt.Sprintf("Managed Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate_test.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate_test.go new file mode 100644 index 00000000000..e60382d764b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedcertificate_test.go @@ -0,0 +1,327 @@ +package managedenvironments + +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 = &ManagedCertificateId{} + +func TestNewManagedCertificateID(t *testing.T) { + id := NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.ManagedCertificateName != "managedCertificateName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedCertificateName'", id.ManagedCertificateName, "managedCertificateName") + } +} + +func TestFormatManagedCertificateID(t *testing.T) { + actual := NewManagedCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "managedCertificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName", + Expected: &ManagedCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + ManagedCertificateName: "managedCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedCertificateID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.ManagedCertificateName != v.Expected.ManagedCertificateName { + t.Fatalf("Expected %q but got %q for ManagedCertificateName", v.Expected.ManagedCertificateName, actual.ManagedCertificateName) + } + + } +} + +func TestParseManagedCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedCertificateId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/mAnAgEdCeRtIfIcAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName", + Expected: &ManagedCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + ManagedCertificateName: "managedCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/managedCertificates/managedCertificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/mAnAgEdCeRtIfIcAtEs/mAnAgEdCeRtIfIcAtEnAmE", + Expected: &ManagedCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + ManagedCertificateName: "mAnAgEdCeRtIfIcAtEnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/mAnAgEdCeRtIfIcAtEs/mAnAgEdCeRtIfIcAtEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedCertificateIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.ManagedCertificateName != v.Expected.ManagedCertificateName { + t.Fatalf("Expected %q but got %q for ManagedCertificateName", v.Expected.ManagedCertificateName, actual.ManagedCertificateName) + } + + } +} + +func TestSegmentsForManagedCertificateId(t *testing.T) { + segments := ManagedCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedCertificateId 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/containerapps/2025-01-01/managedenvironments/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment.go new file mode 100644 index 00000000000..125d668f9b7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment.go @@ -0,0 +1,130 @@ +package managedenvironments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment_test.go new file mode 100644 index 00000000000..498a8e63f64 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package managedenvironments + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector.go new file mode 100644 index 00000000000..cac551d356c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector.go @@ -0,0 +1,139 @@ +package managedenvironments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentDetectorId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentDetectorId{} + +// ManagedEnvironmentDetectorId is a struct representing the Resource ID for a Managed Environment Detector +type ManagedEnvironmentDetectorId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + DetectorName string +} + +// NewManagedEnvironmentDetectorID returns a new ManagedEnvironmentDetectorId struct +func NewManagedEnvironmentDetectorID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, detectorName string) ManagedEnvironmentDetectorId { + return ManagedEnvironmentDetectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + DetectorName: detectorName, + } +} + +// ParseManagedEnvironmentDetectorID parses 'input' into a ManagedEnvironmentDetectorId +func ParseManagedEnvironmentDetectorID(input string) (*ManagedEnvironmentDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentDetectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentDetectorIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentDetectorId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentDetectorIDInsensitively(input string) (*ManagedEnvironmentDetectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentDetectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentDetectorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentDetectorId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.DetectorName, ok = input.Parsed["detectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "detectorName", input) + } + + return nil +} + +// ValidateManagedEnvironmentDetectorID checks that 'input' can be parsed as a Managed Environment Detector ID +func ValidateManagedEnvironmentDetectorID(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 := ParseManagedEnvironmentDetectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment Detector ID +func (id ManagedEnvironmentDetectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/detectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.DetectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment Detector ID +func (id ManagedEnvironmentDetectorId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticDetectors", "detectors", "detectors"), + resourceids.UserSpecifiedSegment("detectorName", "detectorName"), + } +} + +// String returns a human-readable description of this Managed Environment Detector ID +func (id ManagedEnvironmentDetectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Detector Name: %q", id.DetectorName), + } + return fmt.Sprintf("Managed Environment Detector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector_test.go b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector_test.go new file mode 100644 index 00000000000..4aeba97785b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/id_managedenvironmentdetector_test.go @@ -0,0 +1,327 @@ +package managedenvironments + +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 = &ManagedEnvironmentDetectorId{} + +func TestNewManagedEnvironmentDetectorID(t *testing.T) { + id := NewManagedEnvironmentDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "detectorName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.DetectorName != "detectorName" { + t.Fatalf("Expected %q but got %q for Segment 'DetectorName'", id.DetectorName, "detectorName") + } +} + +func TestFormatManagedEnvironmentDetectorID(t *testing.T) { + actual := NewManagedEnvironmentDetectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "detectorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentDetectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName", + Expected: &ManagedEnvironmentDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentDetectorID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestParseManagedEnvironmentDetectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentDetectorId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dEtEcToRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName", + Expected: &ManagedEnvironmentDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + DetectorName: "detectorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/detectors/detectorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dEtEcToRs/dEtEcToRnAmE", + Expected: &ManagedEnvironmentDetectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + DetectorName: "dEtEcToRnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/dEtEcToRs/dEtEcToRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentDetectorIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.DetectorName != v.Expected.DetectorName { + t.Fatalf("Expected %q but got %q for DetectorName", v.Expected.DetectorName, actual.DetectorName) + } + + } +} + +func TestSegmentsForManagedEnvironmentDetectorId(t *testing.T) { + segments := ManagedEnvironmentDetectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentDetectorId 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/containerapps/2025-01-01/managedenvironments/method_certificatescreateorupdate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatescreateorupdate.go new file mode 100644 index 00000000000..6e71a190b18 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatescreateorupdate.go @@ -0,0 +1,57 @@ +package managedenvironments + +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 CertificatesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CertificatesCreateOrUpdate ... +func (c ManagedEnvironmentsClient) CertificatesCreateOrUpdate(ctx context.Context, id CertificateId, input Certificate) (result CertificatesCreateOrUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesdelete.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesdelete.go new file mode 100644 index 00000000000..d1abc892fb4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesdelete.go @@ -0,0 +1,47 @@ +package managedenvironments + +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 CertificatesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CertificatesDelete ... +func (c ManagedEnvironmentsClient) CertificatesDelete(ctx context.Context, id CertificateId) (result CertificatesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesget.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesget.go new file mode 100644 index 00000000000..9c379c868c5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesget.go @@ -0,0 +1,53 @@ +package managedenvironments + +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 CertificatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CertificatesGet ... +func (c ManagedEnvironmentsClient) CertificatesGet(ctx context.Context, id CertificateId) (result CertificatesGetOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificateslist.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificateslist.go new file mode 100644 index 00000000000..5190bc30812 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificateslist.go @@ -0,0 +1,105 @@ +package managedenvironments + +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 CertificatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Certificate +} + +type CertificatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Certificate +} + +type CertificatesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *CertificatesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// CertificatesList ... +func (c ManagedEnvironmentsClient) CertificatesList(ctx context.Context, id ManagedEnvironmentId) (result CertificatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &CertificatesListCustomPager{}, + Path: fmt.Sprintf("%s/certificates", 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 *[]Certificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CertificatesListComplete retrieves all the results into a single object +func (c ManagedEnvironmentsClient) CertificatesListComplete(ctx context.Context, id ManagedEnvironmentId) (CertificatesListCompleteResult, error) { + return c.CertificatesListCompleteMatchingPredicate(ctx, id, CertificateOperationPredicate{}) +} + +// CertificatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedEnvironmentsClient) CertificatesListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate CertificateOperationPredicate) (result CertificatesListCompleteResult, err error) { + items := make([]Certificate, 0) + + resp, err := c.CertificatesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = CertificatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesupdate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesupdate.go new file mode 100644 index 00000000000..64f05973e55 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_certificatesupdate.go @@ -0,0 +1,57 @@ +package managedenvironments + +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 CertificatesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Certificate +} + +// CertificatesUpdate ... +func (c ManagedEnvironmentsClient) CertificatesUpdate(ctx context.Context, id CertificateId, input CertificatePatch) (result CertificatesUpdateOperationResponse, 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 Certificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_createorupdate.go new file mode 100644 index 00000000000..c48ed229fa4 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_createorupdate.go @@ -0,0 +1,75 @@ +package managedenvironments + +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 *ManagedEnvironment +} + +// CreateOrUpdate ... +func (c ManagedEnvironmentsClient) CreateOrUpdate(ctx context.Context, id ManagedEnvironmentId, input ManagedEnvironment) (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 ManagedEnvironmentsClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedEnvironmentId, input ManagedEnvironment) 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/containerapps/2025-01-01/managedenvironments/method_delete.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_delete.go new file mode 100644 index 00000000000..3027fc878dd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_delete.go @@ -0,0 +1,71 @@ +package managedenvironments + +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 ManagedEnvironmentsClient) Delete(ctx context.Context, id ManagedEnvironmentId) (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 ManagedEnvironmentsClient) DeleteThenPoll(ctx context.Context, id ManagedEnvironmentId) 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/containerapps/2025-01-01/managedenvironments/method_diagnosticsgetroot.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_diagnosticsgetroot.go new file mode 100644 index 00000000000..f41bb5dd697 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_diagnosticsgetroot.go @@ -0,0 +1,54 @@ +package managedenvironments + +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 DiagnosticsGetRootOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedEnvironment +} + +// DiagnosticsGetRoot ... +func (c ManagedEnvironmentsClient) DiagnosticsGetRoot(ctx context.Context, id ManagedEnvironmentId) (result DiagnosticsGetRootOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/detectorProperties/rootApi", 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 ManagedEnvironment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_get.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_get.go new file mode 100644 index 00000000000..5c821baf637 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_get.go @@ -0,0 +1,53 @@ +package managedenvironments + +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 *ManagedEnvironment +} + +// Get ... +func (c ManagedEnvironmentsClient) Get(ctx context.Context, id ManagedEnvironmentId) (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 ManagedEnvironment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_getauthtoken.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_getauthtoken.go new file mode 100644 index 00000000000..fac4db2d554 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_getauthtoken.go @@ -0,0 +1,54 @@ +package managedenvironments + +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 GetAuthTokenOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnvironmentAuthToken +} + +// GetAuthToken ... +func (c ManagedEnvironmentsClient) GetAuthToken(ctx context.Context, id ManagedEnvironmentId) (result GetAuthTokenOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getAuthtoken", 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 EnvironmentAuthToken + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_listbyresourcegroup.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_listbyresourcegroup.go new file mode 100644 index 00000000000..6cfee3f3fe3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package managedenvironments + +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 *[]ManagedEnvironment +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedEnvironment +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ManagedEnvironmentsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/managedEnvironments", 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 *[]ManagedEnvironment `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 ManagedEnvironmentsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ManagedEnvironmentOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedEnvironmentsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ManagedEnvironmentOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ManagedEnvironment, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_listbysubscription.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_listbysubscription.go new file mode 100644 index 00000000000..3d61d3c8895 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_listbysubscription.go @@ -0,0 +1,106 @@ +package managedenvironments + +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 *[]ManagedEnvironment +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedEnvironment +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c ManagedEnvironmentsClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.App/managedEnvironments", 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 *[]ManagedEnvironment `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 ManagedEnvironmentsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ManagedEnvironmentOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedEnvironmentsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ManagedEnvironmentOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]ManagedEnvironment, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_listworkloadprofilestates.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_listworkloadprofilestates.go new file mode 100644 index 00000000000..efbaceb1ea8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_listworkloadprofilestates.go @@ -0,0 +1,105 @@ +package managedenvironments + +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 ListWorkloadProfileStatesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WorkloadProfileStates +} + +type ListWorkloadProfileStatesCompleteResult struct { + LatestHttpResponse *http.Response + Items []WorkloadProfileStates +} + +type ListWorkloadProfileStatesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListWorkloadProfileStatesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListWorkloadProfileStates ... +func (c ManagedEnvironmentsClient) ListWorkloadProfileStates(ctx context.Context, id ManagedEnvironmentId) (result ListWorkloadProfileStatesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListWorkloadProfileStatesCustomPager{}, + Path: fmt.Sprintf("%s/workloadProfileStates", 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 *[]WorkloadProfileStates `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListWorkloadProfileStatesComplete retrieves all the results into a single object +func (c ManagedEnvironmentsClient) ListWorkloadProfileStatesComplete(ctx context.Context, id ManagedEnvironmentId) (ListWorkloadProfileStatesCompleteResult, error) { + return c.ListWorkloadProfileStatesCompleteMatchingPredicate(ctx, id, WorkloadProfileStatesOperationPredicate{}) +} + +// ListWorkloadProfileStatesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedEnvironmentsClient) ListWorkloadProfileStatesCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate WorkloadProfileStatesOperationPredicate) (result ListWorkloadProfileStatesCompleteResult, err error) { + items := make([]WorkloadProfileStates, 0) + + resp, err := c.ListWorkloadProfileStates(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListWorkloadProfileStatesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatescreateorupdate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatescreateorupdate.go new file mode 100644 index 00000000000..f97b8b9cbb8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatescreateorupdate.go @@ -0,0 +1,75 @@ +package managedenvironments + +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 ManagedCertificatesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedCertificate +} + +// ManagedCertificatesCreateOrUpdate ... +func (c ManagedEnvironmentsClient) ManagedCertificatesCreateOrUpdate(ctx context.Context, id ManagedCertificateId, input ManagedCertificate) (result ManagedCertificatesCreateOrUpdateOperationResponse, 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 +} + +// ManagedCertificatesCreateOrUpdateThenPoll performs ManagedCertificatesCreateOrUpdate then polls until it's completed +func (c ManagedEnvironmentsClient) ManagedCertificatesCreateOrUpdateThenPoll(ctx context.Context, id ManagedCertificateId, input ManagedCertificate) error { + result, err := c.ManagedCertificatesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ManagedCertificatesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ManagedCertificatesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesdelete.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesdelete.go new file mode 100644 index 00000000000..48f92220083 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesdelete.go @@ -0,0 +1,47 @@ +package managedenvironments + +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 ManagedCertificatesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ManagedCertificatesDelete ... +func (c ManagedEnvironmentsClient) ManagedCertificatesDelete(ctx context.Context, id ManagedCertificateId) (result ManagedCertificatesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesget.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesget.go new file mode 100644 index 00000000000..c1768ca5b9b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesget.go @@ -0,0 +1,53 @@ +package managedenvironments + +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 ManagedCertificatesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedCertificate +} + +// ManagedCertificatesGet ... +func (c ManagedEnvironmentsClient) ManagedCertificatesGet(ctx context.Context, id ManagedCertificateId) (result ManagedCertificatesGetOperationResponse, 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 ManagedCertificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificateslist.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificateslist.go new file mode 100644 index 00000000000..857aea4250e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificateslist.go @@ -0,0 +1,105 @@ +package managedenvironments + +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 ManagedCertificatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedCertificate +} + +type ManagedCertificatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedCertificate +} + +type ManagedCertificatesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ManagedCertificatesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ManagedCertificatesList ... +func (c ManagedEnvironmentsClient) ManagedCertificatesList(ctx context.Context, id ManagedEnvironmentId) (result ManagedCertificatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ManagedCertificatesListCustomPager{}, + Path: fmt.Sprintf("%s/managedCertificates", 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 *[]ManagedCertificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ManagedCertificatesListComplete retrieves all the results into a single object +func (c ManagedEnvironmentsClient) ManagedCertificatesListComplete(ctx context.Context, id ManagedEnvironmentId) (ManagedCertificatesListCompleteResult, error) { + return c.ManagedCertificatesListCompleteMatchingPredicate(ctx, id, ManagedCertificateOperationPredicate{}) +} + +// ManagedCertificatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedEnvironmentsClient) ManagedCertificatesListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate ManagedCertificateOperationPredicate) (result ManagedCertificatesListCompleteResult, err error) { + items := make([]ManagedCertificate, 0) + + resp, err := c.ManagedCertificatesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ManagedCertificatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesupdate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesupdate.go new file mode 100644 index 00000000000..3a177ed8d30 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedcertificatesupdate.go @@ -0,0 +1,57 @@ +package managedenvironments + +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 ManagedCertificatesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedCertificate +} + +// ManagedCertificatesUpdate ... +func (c ManagedEnvironmentsClient) ManagedCertificatesUpdate(ctx context.Context, id ManagedCertificateId, input ManagedCertificatePatch) (result ManagedCertificatesUpdateOperationResponse, 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 ManagedCertificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticsgetdetector.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticsgetdetector.go new file mode 100644 index 00000000000..8097358a0b8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticsgetdetector.go @@ -0,0 +1,53 @@ +package managedenvironments + +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 ManagedEnvironmentDiagnosticsGetDetectorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Diagnostics +} + +// ManagedEnvironmentDiagnosticsGetDetector ... +func (c ManagedEnvironmentsClient) ManagedEnvironmentDiagnosticsGetDetector(ctx context.Context, id ManagedEnvironmentDetectorId) (result ManagedEnvironmentDiagnosticsGetDetectorOperationResponse, 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 Diagnostics + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticslistdetectors.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticslistdetectors.go new file mode 100644 index 00000000000..eaa37d6d08b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_managedenvironmentdiagnosticslistdetectors.go @@ -0,0 +1,105 @@ +package managedenvironments + +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 ManagedEnvironmentDiagnosticsListDetectorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Diagnostics +} + +type ManagedEnvironmentDiagnosticsListDetectorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Diagnostics +} + +type ManagedEnvironmentDiagnosticsListDetectorsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ManagedEnvironmentDiagnosticsListDetectorsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ManagedEnvironmentDiagnosticsListDetectors ... +func (c ManagedEnvironmentsClient) ManagedEnvironmentDiagnosticsListDetectors(ctx context.Context, id ManagedEnvironmentId) (result ManagedEnvironmentDiagnosticsListDetectorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ManagedEnvironmentDiagnosticsListDetectorsCustomPager{}, + Path: fmt.Sprintf("%s/detectors", 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 *[]Diagnostics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ManagedEnvironmentDiagnosticsListDetectorsComplete retrieves all the results into a single object +func (c ManagedEnvironmentsClient) ManagedEnvironmentDiagnosticsListDetectorsComplete(ctx context.Context, id ManagedEnvironmentId) (ManagedEnvironmentDiagnosticsListDetectorsCompleteResult, error) { + return c.ManagedEnvironmentDiagnosticsListDetectorsCompleteMatchingPredicate(ctx, id, DiagnosticsOperationPredicate{}) +} + +// ManagedEnvironmentDiagnosticsListDetectorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedEnvironmentsClient) ManagedEnvironmentDiagnosticsListDetectorsCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate DiagnosticsOperationPredicate) (result ManagedEnvironmentDiagnosticsListDetectorsCompleteResult, err error) { + items := make([]Diagnostics, 0) + + resp, err := c.ManagedEnvironmentDiagnosticsListDetectors(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ManagedEnvironmentDiagnosticsListDetectorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_namespaceschecknameavailability.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_namespaceschecknameavailability.go new file mode 100644 index 00000000000..f2c52cfc7bb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_namespaceschecknameavailability.go @@ -0,0 +1,58 @@ +package managedenvironments + +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 NamespacesCheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// NamespacesCheckNameAvailability ... +func (c ManagedEnvironmentsClient) NamespacesCheckNameAvailability(ctx context.Context, id ManagedEnvironmentId, input CheckNameAvailabilityRequest) (result NamespacesCheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/method_update.go b/resource-manager/containerapps/2025-01-01/managedenvironments/method_update.go new file mode 100644 index 00000000000..68a3258e308 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/method_update.go @@ -0,0 +1,75 @@ +package managedenvironments + +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 *ManagedEnvironment +} + +// Update ... +func (c ManagedEnvironmentsClient) Update(ctx context.Context, id ManagedEnvironmentId, input ManagedEnvironment) (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 ManagedEnvironmentsClient) UpdateThenPoll(ctx context.Context, id ManagedEnvironmentId, input ManagedEnvironment) 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/containerapps/2025-01-01/managedenvironments/model_applogsconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_applogsconfiguration.go new file mode 100644 index 00000000000..abdf9f78657 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_applogsconfiguration.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AppLogsConfiguration struct { + Destination *string `json:"destination,omitempty"` + LogAnalyticsConfiguration *LogAnalyticsConfiguration `json:"logAnalyticsConfiguration,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificate.go new file mode 100644 index 00000000000..484fed38c23 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificate.go @@ -0,0 +1,18 @@ +package managedenvironments + +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 Certificate struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *CertificateProperties `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/containerapps/2025-01-01/managedenvironments/model_certificatekeyvaultproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatekeyvaultproperties.go new file mode 100644 index 00000000000..7cf010d99ff --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatekeyvaultproperties.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateKeyVaultProperties struct { + Identity *string `json:"identity,omitempty"` + KeyVaultURL *string `json:"keyVaultUrl,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatepatch.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatepatch.go new file mode 100644 index 00000000000..2dac1ee3ef3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificatepatch.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificatePatch struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificateproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificateproperties.go new file mode 100644 index 00000000000..8cadb3309df --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_certificateproperties.go @@ -0,0 +1,49 @@ +package managedenvironments + +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 CertificateProperties struct { + CertificateKeyVaultProperties *CertificateKeyVaultProperties `json:"certificateKeyVaultProperties,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + IssueDate *string `json:"issueDate,omitempty"` + Issuer *string `json:"issuer,omitempty"` + Password *string `json:"password,omitempty"` + ProvisioningState *CertificateProvisioningState `json:"provisioningState,omitempty"` + PublicKeyHash *string `json:"publicKeyHash,omitempty"` + SubjectAlternativeNames *[]string `json:"subjectAlternativeNames,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Valid *bool `json:"valid,omitempty"` + Value *string `json:"value,omitempty"` +} + +func (o *CertificateProperties) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateProperties) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} + +func (o *CertificateProperties) GetIssueDateAsTime() (*time.Time, error) { + if o.IssueDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.IssueDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateProperties) SetIssueDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.IssueDate = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityrequest.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..d294561f4e0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityresponse.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..4543ac719ef --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_customdomainconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_customdomainconfiguration.go new file mode 100644 index 00000000000..715d672d9df --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_customdomainconfiguration.go @@ -0,0 +1,33 @@ +package managedenvironments + +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 CustomDomainConfiguration struct { + CertificateKeyVaultProperties *CertificateKeyVaultProperties `json:"certificateKeyVaultProperties,omitempty"` + CertificatePassword *string `json:"certificatePassword,omitempty"` + CertificateValue *string `json:"certificateValue,omitempty"` + CustomDomainVerificationId *string `json:"customDomainVerificationId,omitempty"` + DnsSuffix *string `json:"dnsSuffix,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` +} + +func (o *CustomDomainConfiguration) GetExpirationDateAsTime() (*time.Time, error) { + if o.ExpirationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CustomDomainConfiguration) SetExpirationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationDate = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_daprconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_daprconfiguration.go new file mode 100644 index 00000000000..53bd17d3757 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_daprconfiguration.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DaprConfiguration struct { + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadata.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadata.go new file mode 100644 index 00000000000..4370d2d5424 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadata.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadata struct { + PropertyBag *[]DiagnosticDataProviderMetadataPropertyBagInlined `json:"propertyBag,omitempty"` + ProviderName *string `json:"providerName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadatapropertybaginlined.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadatapropertybaginlined.go new file mode 100644 index 00000000000..4d896361710 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdataprovidermetadatapropertybaginlined.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataProviderMetadataPropertyBagInlined struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponsecolumn.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponsecolumn.go new file mode 100644 index 00000000000..ab6b5a67c29 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponsecolumn.go @@ -0,0 +1,10 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseColumn struct { + ColumnName *string `json:"columnName,omitempty"` + ColumnType *string `json:"columnType,omitempty"` + DataType *string `json:"dataType,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponseobject.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponseobject.go new file mode 100644 index 00000000000..27daeba457d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticdatatableresponseobject.go @@ -0,0 +1,10 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticDataTableResponseObject struct { + Columns *[]DiagnosticDataTableResponseColumn `json:"columns,omitempty"` + Rows *[]interface{} `json:"rows,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticrendering.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticrendering.go new file mode 100644 index 00000000000..12c6de84296 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticrendering.go @@ -0,0 +1,11 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticRendering struct { + Description *string `json:"description,omitempty"` + IsVisible *bool `json:"isVisible,omitempty"` + Title *string `json:"title,omitempty"` + Type *int64 `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnostics.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnostics.go new file mode 100644 index 00000000000..206b21e02c0 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnostics.go @@ -0,0 +1,16 @@ +package managedenvironments + +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 Diagnostics struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DiagnosticsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdataapiresponse.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdataapiresponse.go new file mode 100644 index 00000000000..f03854afb04 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdataapiresponse.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDataApiResponse struct { + RenderingProperties *DiagnosticRendering `json:"renderingProperties,omitempty"` + Table *DiagnosticDataTableResponseObject `json:"table,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdefinition.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdefinition.go new file mode 100644 index 00000000000..4b111825f40 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsdefinition.go @@ -0,0 +1,16 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsDefinition struct { + AnalysisTypes *[]string `json:"analysisTypes,omitempty"` + Author *string `json:"author,omitempty"` + Category *string `json:"category,omitempty"` + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Score *float64 `json:"score,omitempty"` + SupportTopicList *[]DiagnosticSupportTopic `json:"supportTopicList,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsproperties.go new file mode 100644 index 00000000000..b8b0624147b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsproperties.go @@ -0,0 +1,11 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsProperties struct { + DataProviderMetadata *DiagnosticDataProviderMetadata `json:"dataProviderMetadata,omitempty"` + Dataset *[]DiagnosticsDataApiResponse `json:"dataset,omitempty"` + Metadata *DiagnosticsDefinition `json:"metadata,omitempty"` + Status *DiagnosticsStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsstatus.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsstatus.go new file mode 100644 index 00000000000..bff7d6b2f93 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsstatus.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticsStatus struct { + Message *string `json:"message,omitempty"` + StatusId *int64 `json:"statusId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsupporttopic.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsupporttopic.go new file mode 100644 index 00000000000..3402c1969af --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_diagnosticsupporttopic.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiagnosticSupportTopic struct { + Id *string `json:"id,omitempty"` + PesId *string `json:"pesId,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtoken.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtoken.go new file mode 100644 index 00000000000..500c9d59643 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtoken.go @@ -0,0 +1,18 @@ +package managedenvironments + +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 EnvironmentAuthToken struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *EnvironmentAuthTokenProperties `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/containerapps/2025-01-01/managedenvironments/model_environmentauthtokenproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtokenproperties.go new file mode 100644 index 00000000000..78e904953fd --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_environmentauthtokenproperties.go @@ -0,0 +1,27 @@ +package managedenvironments + +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 EnvironmentAuthTokenProperties struct { + Expires *string `json:"expires,omitempty"` + Token *string `json:"token,omitempty"` +} + +func (o *EnvironmentAuthTokenProperties) GetExpiresAsTime() (*time.Time, error) { + if o.Expires == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expires, "2006-01-02T15:04:05Z07:00") +} + +func (o *EnvironmentAuthTokenProperties) SetExpiresAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expires = &formatted +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_kedaconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_kedaconfiguration.go new file mode 100644 index 00000000000..16513cb6808 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_kedaconfiguration.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KedaConfiguration struct { + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_loganalyticsconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_loganalyticsconfiguration.go new file mode 100644 index 00000000000..f521fb6729d --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_loganalyticsconfiguration.go @@ -0,0 +1,9 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsConfiguration struct { + CustomerId *string `json:"customerId,omitempty"` + SharedKey *string `json:"sharedKey,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificate.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificate.go new file mode 100644 index 00000000000..7e1f1e64b10 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificate.go @@ -0,0 +1,18 @@ +package managedenvironments + +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 ManagedCertificate struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedCertificateProperties `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/containerapps/2025-01-01/managedenvironments/model_managedcertificatepatch.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificatepatch.go new file mode 100644 index 00000000000..4f8a0d6af6b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificatepatch.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedCertificatePatch struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificateproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificateproperties.go new file mode 100644 index 00000000000..b67b5aec719 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedcertificateproperties.go @@ -0,0 +1,12 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedCertificateProperties struct { + DomainControlValidation *ManagedCertificateDomainControlValidation `json:"domainControlValidation,omitempty"` + Error *string `json:"error,omitempty"` + ProvisioningState *CertificateProvisioningState `json:"provisioningState,omitempty"` + SubjectName *string `json:"subjectName,omitempty"` + ValidationToken *string `json:"validationToken,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironment.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironment.go new file mode 100644 index 00000000000..eba8aa89eeb --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironment.go @@ -0,0 +1,21 @@ +package managedenvironments + +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 ManagedEnvironment struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedEnvironmentProperties `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/containerapps/2025-01-01/managedenvironments/model_managedenvironmentproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentproperties.go new file mode 100644 index 00000000000..07ed752ece1 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentproperties.go @@ -0,0 +1,24 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentProperties struct { + AppLogsConfiguration *AppLogsConfiguration `json:"appLogsConfiguration,omitempty"` + CustomDomainConfiguration *CustomDomainConfiguration `json:"customDomainConfiguration,omitempty"` + DaprAIConnectionString *string `json:"daprAIConnectionString,omitempty"` + DaprAIInstrumentationKey *string `json:"daprAIInstrumentationKey,omitempty"` + DaprConfiguration *DaprConfiguration `json:"daprConfiguration,omitempty"` + DefaultDomain *string `json:"defaultDomain,omitempty"` + DeploymentErrors *string `json:"deploymentErrors,omitempty"` + EventStreamEndpoint *string `json:"eventStreamEndpoint,omitempty"` + InfrastructureResourceGroup *string `json:"infrastructureResourceGroup,omitempty"` + KedaConfiguration *KedaConfiguration `json:"kedaConfiguration,omitempty"` + PeerAuthentication *ManagedEnvironmentPropertiesPeerAuthentication `json:"peerAuthentication,omitempty"` + PeerTrafficConfiguration *ManagedEnvironmentPropertiesPeerTrafficConfiguration `json:"peerTrafficConfiguration,omitempty"` + ProvisioningState *EnvironmentProvisioningState `json:"provisioningState,omitempty"` + StaticIP *string `json:"staticIp,omitempty"` + VnetConfiguration *VnetConfiguration `json:"vnetConfiguration,omitempty"` + WorkloadProfiles *[]WorkloadProfile `json:"workloadProfiles,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeerauthentication.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeerauthentication.go new file mode 100644 index 00000000000..3a549e03594 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeerauthentication.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentPropertiesPeerAuthentication struct { + Mtls *Mtls `json:"mtls,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfiguration.go new file mode 100644 index 00000000000..780049df980 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfiguration.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentPropertiesPeerTrafficConfiguration struct { + Encryption *ManagedEnvironmentPropertiesPeerTrafficConfigurationEncryption `json:"encryption,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go new file mode 100644 index 00000000000..06027684e92 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_managedenvironmentpropertiespeertrafficconfigurationencryption.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentPropertiesPeerTrafficConfigurationEncryption struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_mtls.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_mtls.go new file mode 100644 index 00000000000..a3a25e87695 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_mtls.go @@ -0,0 +1,8 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Mtls struct { + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_vnetconfiguration.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_vnetconfiguration.go new file mode 100644 index 00000000000..014a2857454 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_vnetconfiguration.go @@ -0,0 +1,12 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VnetConfiguration struct { + DockerBridgeCidr *string `json:"dockerBridgeCidr,omitempty"` + InfrastructureSubnetId *string `json:"infrastructureSubnetId,omitempty"` + Internal *bool `json:"internal,omitempty"` + PlatformReservedCidr *string `json:"platformReservedCidr,omitempty"` + PlatformReservedDnsIP *string `json:"platformReservedDnsIP,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofile.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofile.go new file mode 100644 index 00000000000..bcf34bbba5b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofile.go @@ -0,0 +1,11 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadProfile struct { + MaximumCount *int64 `json:"maximumCount,omitempty"` + MinimumCount *int64 `json:"minimumCount,omitempty"` + Name string `json:"name"` + WorkloadProfileType string `json:"workloadProfileType"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestates.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestates.go new file mode 100644 index 00000000000..e0db3501de7 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestates.go @@ -0,0 +1,16 @@ +package managedenvironments + +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 WorkloadProfileStates struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkloadProfileStatesProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestatesproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestatesproperties.go new file mode 100644 index 00000000000..e5e7acb2d49 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/model_workloadprofilestatesproperties.go @@ -0,0 +1,10 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadProfileStatesProperties struct { + CurrentCount *int64 `json:"currentCount,omitempty"` + MaximumCount *int64 `json:"maximumCount,omitempty"` + MinimumCount *int64 `json:"minimumCount,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironments/predicates.go b/resource-manager/containerapps/2025-01-01/managedenvironments/predicates.go new file mode 100644 index 00000000000..47decb01f0c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/predicates.go @@ -0,0 +1,139 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p CertificateOperationPredicate) Matches(input Certificate) 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 +} + +type DiagnosticsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DiagnosticsOperationPredicate) Matches(input Diagnostics) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ManagedCertificateOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedCertificateOperationPredicate) Matches(input ManagedCertificate) 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 +} + +type ManagedEnvironmentOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ManagedEnvironmentOperationPredicate) Matches(input ManagedEnvironment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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 +} + +type WorkloadProfileStatesOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WorkloadProfileStatesOperationPredicate) Matches(input WorkloadProfileStates) 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/containerapps/2025-01-01/managedenvironments/version.go b/resource-manager/containerapps/2025-01-01/managedenvironments/version.go new file mode 100644 index 00000000000..4f017ef7336 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironments/version.go @@ -0,0 +1,10 @@ +package managedenvironments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedenvironments/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/README.md b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/README.md new file mode 100644 index 00000000000..59404824448 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages` Documentation + +The `managedenvironmentsstorages` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages" +``` + + +### Client Initialization + +```go +client := managedenvironmentsstorages.NewManagedEnvironmentsStoragesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedEnvironmentsStoragesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedenvironmentsstorages.NewStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "storageName") + +payload := managedenvironmentsstorages.ManagedEnvironmentStorage{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsStoragesClient.Delete` + +```go +ctx := context.TODO() +id := managedenvironmentsstorages.NewStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "storageName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedEnvironmentsStoragesClient.Get` + +```go +ctx := context.TODO() +id := managedenvironmentsstorages.NewStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "storageName") + +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: `ManagedEnvironmentsStoragesClient.List` + +```go +ctx := context.TODO() +id := managedenvironmentsstorages.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/client.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/client.go new file mode 100644 index 00000000000..7b39b5e0e38 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/client.go @@ -0,0 +1,26 @@ +package managedenvironmentsstorages + +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 ManagedEnvironmentsStoragesClient struct { + Client *resourcemanager.Client +} + +func NewManagedEnvironmentsStoragesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedEnvironmentsStoragesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedenvironmentsstorages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedEnvironmentsStoragesClient: %+v", err) + } + + return &ManagedEnvironmentsStoragesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/constants.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/constants.go new file mode 100644 index 00000000000..ea9d6dcf5bf --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/constants.go @@ -0,0 +1,51 @@ +package managedenvironmentsstorages + +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 AccessMode string + +const ( + AccessModeReadOnly AccessMode = "ReadOnly" + AccessModeReadWrite AccessMode = "ReadWrite" +) + +func PossibleValuesForAccessMode() []string { + return []string{ + string(AccessModeReadOnly), + string(AccessModeReadWrite), + } +} + +func (s *AccessMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessMode(input string) (*AccessMode, error) { + vals := map[string]AccessMode{ + "readonly": AccessModeReadOnly, + "readwrite": AccessModeReadWrite, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessMode(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment.go new file mode 100644 index 00000000000..1c3e4c89d91 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment.go @@ -0,0 +1,130 @@ +package managedenvironmentsstorages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment_test.go new file mode 100644 index 00000000000..3b2c0c8b236 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package managedenvironmentsstorages + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/managedenvironmentsstorages/id_storage.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage.go new file mode 100644 index 00000000000..720c4333d52 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage.go @@ -0,0 +1,139 @@ +package managedenvironmentsstorages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StorageId{}) +} + +var _ resourceids.ResourceId = &StorageId{} + +// StorageId is a struct representing the Resource ID for a Storage +type StorageId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string + StorageName string +} + +// NewStorageID returns a new StorageId struct +func NewStorageID(subscriptionId string, resourceGroupName string, managedEnvironmentName string, storageName string) StorageId { + return StorageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + StorageName: storageName, + } +} + +// ParseStorageID parses 'input' into a StorageId +func ParseStorageID(input string) (*StorageId, error) { + parser := resourceids.NewParserFromResourceIdType(&StorageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StorageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStorageIDInsensitively parses 'input' case-insensitively into a StorageId +// note: this method should only be used for API response data and not user input +func ParseStorageIDInsensitively(input string) (*StorageId, error) { + parser := resourceids.NewParserFromResourceIdType(&StorageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StorageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StorageId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + if id.StorageName, ok = input.Parsed["storageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "storageName", input) + } + + return nil +} + +// ValidateStorageID checks that 'input' can be parsed as a Storage ID +func ValidateStorageID(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 := ParseStorageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Storage ID +func (id StorageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s/storages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName, id.StorageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Storage ID +func (id StorageId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + resourceids.StaticSegment("staticStorages", "storages", "storages"), + resourceids.UserSpecifiedSegment("storageName", "storageName"), + } +} + +// String returns a human-readable description of this Storage ID +func (id StorageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + fmt.Sprintf("Storage Name: %q", id.StorageName), + } + return fmt.Sprintf("Storage (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage_test.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage_test.go new file mode 100644 index 00000000000..4cac9e97b98 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/id_storage_test.go @@ -0,0 +1,327 @@ +package managedenvironmentsstorages + +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 = &StorageId{} + +func TestNewStorageID(t *testing.T) { + id := NewStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "storageName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } + + if id.StorageName != "storageName" { + t.Fatalf("Expected %q but got %q for Segment 'StorageName'", id.StorageName, "storageName") + } +} + +func TestFormatStorageID(t *testing.T) { + actual := NewStorageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName", "storageName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages/storageName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStorageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StorageId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages/storageName", + Expected: &StorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + StorageName: "storageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages/storageName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStorageID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.StorageName != v.Expected.StorageName { + t.Fatalf("Expected %q but got %q for StorageName", v.Expected.StorageName, actual.StorageName) + } + + } +} + +func TestParseStorageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StorageId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/sToRaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages/storageName", + Expected: &StorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + StorageName: "storageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/storages/storageName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/sToRaGeS/sToRaGeNaMe", + Expected: &StorageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + StorageName: "sToRaGeNaMe", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/sToRaGeS/sToRaGeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStorageIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + if actual.StorageName != v.Expected.StorageName { + t.Fatalf("Expected %q but got %q for StorageName", v.Expected.StorageName, actual.StorageName) + } + + } +} + +func TestSegmentsForStorageId(t *testing.T) { + segments := StorageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StorageId 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/containerapps/2025-01-01/managedenvironmentsstorages/method_createorupdate.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_createorupdate.go new file mode 100644 index 00000000000..6111332ea74 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_createorupdate.go @@ -0,0 +1,57 @@ +package managedenvironmentsstorages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedEnvironmentStorage +} + +// CreateOrUpdate ... +func (c ManagedEnvironmentsStoragesClient) CreateOrUpdate(ctx context.Context, id StorageId, input ManagedEnvironmentStorage) (result CreateOrUpdateOperationResponse, 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 ManagedEnvironmentStorage + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_delete.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_delete.go new file mode 100644 index 00000000000..46330ae42f3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_delete.go @@ -0,0 +1,47 @@ +package managedenvironmentsstorages + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedEnvironmentsStoragesClient) Delete(ctx context.Context, id StorageId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_get.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_get.go new file mode 100644 index 00000000000..97349d79481 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_get.go @@ -0,0 +1,53 @@ +package managedenvironmentsstorages + +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 *ManagedEnvironmentStorage +} + +// Get ... +func (c ManagedEnvironmentsStoragesClient) Get(ctx context.Context, id StorageId) (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 ManagedEnvironmentStorage + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_list.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_list.go new file mode 100644 index 00000000000..ff3a55a4b4e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/method_list.go @@ -0,0 +1,54 @@ +package managedenvironmentsstorages + +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 *ManagedEnvironmentStoragesCollection +} + +// List ... +func (c ManagedEnvironmentsStoragesClient) List(ctx context.Context, id ManagedEnvironmentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/storages", 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 ManagedEnvironmentStoragesCollection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_azurefileproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_azurefileproperties.go new file mode 100644 index 00000000000..e7a33554e85 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_azurefileproperties.go @@ -0,0 +1,11 @@ +package managedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureFileProperties struct { + AccessMode *AccessMode `json:"accessMode,omitempty"` + AccountKey *string `json:"accountKey,omitempty"` + AccountName *string `json:"accountName,omitempty"` + ShareName *string `json:"shareName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorage.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorage.go new file mode 100644 index 00000000000..3bc1545fd92 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorage.go @@ -0,0 +1,16 @@ +package managedenvironmentsstorages + +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 ManagedEnvironmentStorage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedEnvironmentStorageProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorageproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorageproperties.go new file mode 100644 index 00000000000..db21091d116 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstorageproperties.go @@ -0,0 +1,9 @@ +package managedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentStorageProperties struct { + AzureFile *AzureFileProperties `json:"azureFile,omitempty"` + NfsAzureFile *NfsAzureFileProperties `json:"nfsAzureFile,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstoragescollection.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstoragescollection.go new file mode 100644 index 00000000000..9e26cae077c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_managedenvironmentstoragescollection.go @@ -0,0 +1,8 @@ +package managedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedEnvironmentStoragesCollection struct { + Value []ManagedEnvironmentStorage `json:"value"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_nfsazurefileproperties.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_nfsazurefileproperties.go new file mode 100644 index 00000000000..14dce82b5e8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/model_nfsazurefileproperties.go @@ -0,0 +1,10 @@ +package managedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NfsAzureFileProperties struct { + AccessMode *AccessMode `json:"accessMode,omitempty"` + Server *string `json:"server,omitempty"` + ShareName *string `json:"shareName,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/version.go b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/version.go new file mode 100644 index 00000000000..e7974ae5106 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/managedenvironmentsstorages/version.go @@ -0,0 +1,10 @@ +package managedenvironmentsstorages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedenvironmentsstorages/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/subscriptions/client.go b/resource-manager/containerapps/2025-01-01/subscriptions/client.go new file mode 100644 index 00000000000..84c92b4fb13 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/subscriptions/client.go @@ -0,0 +1,26 @@ +package subscriptions + +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 SubscriptionsClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "subscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionsClient: %+v", err) + } + + return &SubscriptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/subscriptions/method_getcustomdomainverificationid.go b/resource-manager/containerapps/2025-01-01/subscriptions/method_getcustomdomainverificationid.go new file mode 100644 index 00000000000..197b8a7b43e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/subscriptions/method_getcustomdomainverificationid.go @@ -0,0 +1,55 @@ +package subscriptions + +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 GetCustomDomainVerificationIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *string +} + +// GetCustomDomainVerificationId ... +func (c SubscriptionsClient) GetCustomDomainVerificationId(ctx context.Context, id commonids.SubscriptionId) (result GetCustomDomainVerificationIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.App/getCustomDomainVerificationId", 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 string + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerapps/2025-01-01/subscriptions/version.go b/resource-manager/containerapps/2025-01-01/subscriptions/version.go new file mode 100644 index 00000000000..dd6f3dff404 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/subscriptions/version.go @@ -0,0 +1,10 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/subscriptions/2025-01-01" +} diff --git a/resource-manager/containerapps/2025-01-01/usages/README.md b/resource-manager/containerapps/2025-01-01/usages/README.md new file mode 100644 index 00000000000..8ebd97d3000 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/usages` Documentation + +The `usages` SDK allows for interaction with Azure Resource Manager `containerapps` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2025-01-01/usages" +``` + + +### Client Initialization + +```go +client := usages.NewUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsagesClient.List` + +```go +ctx := context.TODO() +id := usages.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// 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: `UsagesClient.ManagedEnvironmentUsagesList` + +```go +ctx := context.TODO() +id := usages.NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + +// alternatively `client.ManagedEnvironmentUsagesList(ctx, id)` can be used to do batched pagination +items, err := client.ManagedEnvironmentUsagesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerapps/2025-01-01/usages/client.go b/resource-manager/containerapps/2025-01-01/usages/client.go new file mode 100644 index 00000000000..5b6ce18413b --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/client.go @@ -0,0 +1,26 @@ +package usages + +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 UsagesClient struct { + Client *resourcemanager.Client +} + +func NewUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*UsagesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "usages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UsagesClient: %+v", err) + } + + return &UsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerapps/2025-01-01/usages/constants.go b/resource-manager/containerapps/2025-01-01/usages/constants.go new file mode 100644 index 00000000000..0d8916ba5aa --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/constants.go @@ -0,0 +1,48 @@ +package usages + +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 UsageUnit string + +const ( + UsageUnitCount UsageUnit = "Count" +) + +func PossibleValuesForUsageUnit() []string { + return []string{ + string(UsageUnitCount), + } +} + +func (s *UsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsageUnit(input string) (*UsageUnit, error) { + vals := map[string]UsageUnit{ + "count": UsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsageUnit(input) + return &out, nil +} diff --git a/resource-manager/containerapps/2025-01-01/usages/id_location.go b/resource-manager/containerapps/2025-01-01/usages/id_location.go new file mode 100644 index 00000000000..0d49964ff82 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/id_location.go @@ -0,0 +1,121 @@ +package usages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.App/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/usages/id_location_test.go b/resource-manager/containerapps/2025-01-01/usages/id_location_test.go new file mode 100644 index 00000000000..449191cb377 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/id_location_test.go @@ -0,0 +1,237 @@ +package usages + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.App/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aPp/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/containerapps/2025-01-01/usages/id_managedenvironment.go b/resource-manager/containerapps/2025-01-01/usages/id_managedenvironment.go new file mode 100644 index 00000000000..cb09115b8e8 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/id_managedenvironment.go @@ -0,0 +1,130 @@ +package usages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedEnvironmentId{}) +} + +var _ resourceids.ResourceId = &ManagedEnvironmentId{} + +// ManagedEnvironmentId is a struct representing the Resource ID for a Managed Environment +type ManagedEnvironmentId struct { + SubscriptionId string + ResourceGroupName string + ManagedEnvironmentName string +} + +// NewManagedEnvironmentID returns a new ManagedEnvironmentId struct +func NewManagedEnvironmentID(subscriptionId string, resourceGroupName string, managedEnvironmentName string) ManagedEnvironmentId { + return ManagedEnvironmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedEnvironmentName: managedEnvironmentName, + } +} + +// ParseManagedEnvironmentID parses 'input' into a ManagedEnvironmentId +func ParseManagedEnvironmentID(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedEnvironmentIDInsensitively parses 'input' case-insensitively into a ManagedEnvironmentId +// note: this method should only be used for API response data and not user input +func ParseManagedEnvironmentIDInsensitively(input string) (*ManagedEnvironmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedEnvironmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedEnvironmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedEnvironmentId) 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.ManagedEnvironmentName, ok = input.Parsed["managedEnvironmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedEnvironmentName", input) + } + + return nil +} + +// ValidateManagedEnvironmentID checks that 'input' can be parsed as a Managed Environment ID +func ValidateManagedEnvironmentID(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 := ParseManagedEnvironmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Environment ID +func (id ManagedEnvironmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.App/managedEnvironments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedEnvironmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Environment ID +func (id ManagedEnvironmentId) 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("staticMicrosoftApp", "Microsoft.App", "Microsoft.App"), + resourceids.StaticSegment("staticManagedEnvironments", "managedEnvironments", "managedEnvironments"), + resourceids.UserSpecifiedSegment("managedEnvironmentName", "managedEnvironmentName"), + } +} + +// String returns a human-readable description of this Managed Environment ID +func (id ManagedEnvironmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Environment Name: %q", id.ManagedEnvironmentName), + } + return fmt.Sprintf("Managed Environment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerapps/2025-01-01/usages/id_managedenvironment_test.go b/resource-manager/containerapps/2025-01-01/usages/id_managedenvironment_test.go new file mode 100644 index 00000000000..b32da7ba8b3 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/id_managedenvironment_test.go @@ -0,0 +1,282 @@ +package usages + +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 = &ManagedEnvironmentId{} + +func TestNewManagedEnvironmentID(t *testing.T) { + id := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName") + + 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.ManagedEnvironmentName != "managedEnvironmentName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedEnvironmentName'", id.ManagedEnvironmentName, "managedEnvironmentName") + } +} + +func TestFormatManagedEnvironmentID(t *testing.T) { + actual := NewManagedEnvironmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedEnvironmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedEnvironmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentID(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestParseManagedEnvironmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedEnvironmentId + }{ + { + // 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.App", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedEnvironmentName: "managedEnvironmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.App/managedEnvironments/managedEnvironmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE", + Expected: &ManagedEnvironmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedEnvironmentName: "mAnAgEdEnViRoNmEnTnAmE", + }, + }, + { + // 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.aPp/mAnAgEdEnViRoNmEnTs/mAnAgEdEnViRoNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedEnvironmentIDInsensitively(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.ManagedEnvironmentName != v.Expected.ManagedEnvironmentName { + t.Fatalf("Expected %q but got %q for ManagedEnvironmentName", v.Expected.ManagedEnvironmentName, actual.ManagedEnvironmentName) + } + + } +} + +func TestSegmentsForManagedEnvironmentId(t *testing.T) { + segments := ManagedEnvironmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedEnvironmentId 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/containerapps/2025-01-01/usages/method_list.go b/resource-manager/containerapps/2025-01-01/usages/method_list.go new file mode 100644 index 00000000000..76d13699e0c --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/method_list.go @@ -0,0 +1,105 @@ +package usages + +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 *[]Usage +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c UsagesClient) List(ctx context.Context, id LocationId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Usage `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 UsagesClient) ListComplete(ctx context.Context, id LocationId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UsagesClient) ListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate UsageOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/usages/method_managedenvironmentusageslist.go b/resource-manager/containerapps/2025-01-01/usages/method_managedenvironmentusageslist.go new file mode 100644 index 00000000000..fe03f6b8740 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/method_managedenvironmentusageslist.go @@ -0,0 +1,105 @@ +package usages + +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 ManagedEnvironmentUsagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ManagedEnvironmentUsagesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ManagedEnvironmentUsagesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ManagedEnvironmentUsagesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ManagedEnvironmentUsagesList ... +func (c UsagesClient) ManagedEnvironmentUsagesList(ctx context.Context, id ManagedEnvironmentId) (result ManagedEnvironmentUsagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ManagedEnvironmentUsagesListCustomPager{}, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ManagedEnvironmentUsagesListComplete retrieves all the results into a single object +func (c UsagesClient) ManagedEnvironmentUsagesListComplete(ctx context.Context, id ManagedEnvironmentId) (ManagedEnvironmentUsagesListCompleteResult, error) { + return c.ManagedEnvironmentUsagesListCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ManagedEnvironmentUsagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UsagesClient) ManagedEnvironmentUsagesListCompleteMatchingPredicate(ctx context.Context, id ManagedEnvironmentId, predicate UsageOperationPredicate) (result ManagedEnvironmentUsagesListCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ManagedEnvironmentUsagesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ManagedEnvironmentUsagesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerapps/2025-01-01/usages/model_usage.go b/resource-manager/containerapps/2025-01-01/usages/model_usage.go new file mode 100644 index 00000000000..3505a296b40 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/model_usage.go @@ -0,0 +1,11 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue float64 `json:"currentValue"` + Limit float64 `json:"limit"` + Name UsageName `json:"name"` + Unit UsageUnit `json:"unit"` +} diff --git a/resource-manager/containerapps/2025-01-01/usages/model_usagename.go b/resource-manager/containerapps/2025-01-01/usages/model_usagename.go new file mode 100644 index 00000000000..ff2d9cbdd3e --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/model_usagename.go @@ -0,0 +1,9 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerapps/2025-01-01/usages/predicates.go b/resource-manager/containerapps/2025-01-01/usages/predicates.go new file mode 100644 index 00000000000..48590d8b9f6 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/predicates.go @@ -0,0 +1,22 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageOperationPredicate struct { + CurrentValue *float64 + Limit *float64 +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.CurrentValue != nil && *p.CurrentValue != input.CurrentValue { + return false + } + + if p.Limit != nil && *p.Limit != input.Limit { + return false + } + + return true +} diff --git a/resource-manager/containerapps/2025-01-01/usages/version.go b/resource-manager/containerapps/2025-01-01/usages/version.go new file mode 100644 index 00000000000..d35e37473c5 --- /dev/null +++ b/resource-manager/containerapps/2025-01-01/usages/version.go @@ -0,0 +1,10 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/usages/2025-01-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/README.md b/resource-manager/dataprotection/2025-02-01/azurebackupjob/README.md new file mode 100644 index 00000000000..7caf41e6949 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/README.md @@ -0,0 +1,64 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/azurebackupjob` Documentation + +The `azurebackupjob` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/azurebackupjob" +``` + + +### Client Initialization + +```go +client := azurebackupjob.NewAzureBackupJobClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AzureBackupJobClient.ExportJobsOperationResultGet` + +```go +ctx := context.TODO() +id := azurebackupjob.NewOperationIdID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "operationId") + +read, err := client.ExportJobsOperationResultGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AzureBackupJobClient.ExportJobsTrigger` + +```go +ctx := context.TODO() +id := azurebackupjob.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +if err := client.ExportJobsTriggerThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AzureBackupJobClient.JobsGet` + +```go +ctx := context.TODO() +id := azurebackupjob.NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "jobId") + +read, err := client.JobsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/client.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/client.go new file mode 100644 index 00000000000..e8e66d81c81 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/client.go @@ -0,0 +1,26 @@ +package azurebackupjob + +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 AzureBackupJobClient struct { + Client *resourcemanager.Client +} + +func NewAzureBackupJobClientWithBaseURI(sdkApi sdkEnv.Api) (*AzureBackupJobClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "azurebackupjob", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AzureBackupJobClient: %+v", err) + } + + return &AzureBackupJobClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob.go new file mode 100644 index 00000000000..61310319446 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob.go @@ -0,0 +1,139 @@ +package azurebackupjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupJobId{}) +} + +var _ resourceids.ResourceId = &BackupJobId{} + +// BackupJobId is a struct representing the Resource ID for a Backup Job +type BackupJobId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + JobId string +} + +// NewBackupJobID returns a new BackupJobId struct +func NewBackupJobID(subscriptionId string, resourceGroupName string, backupVaultName string, jobId string) BackupJobId { + return BackupJobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + JobId: jobId, + } +} + +// ParseBackupJobID parses 'input' into a BackupJobId +func ParseBackupJobID(input string) (*BackupJobId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupJobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupJobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupJobIDInsensitively parses 'input' case-insensitively into a BackupJobId +// note: this method should only be used for API response data and not user input +func ParseBackupJobIDInsensitively(input string) (*BackupJobId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupJobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupJobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupJobId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.JobId, ok = input.Parsed["jobId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobId", input) + } + + return nil +} + +// ValidateBackupJobID checks that 'input' can be parsed as a Backup Job ID +func ValidateBackupJobID(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 := ParseBackupJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Job ID +func (id BackupJobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupJobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.JobId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Job ID +func (id BackupJobId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupJobs", "backupJobs", "backupJobs"), + resourceids.UserSpecifiedSegment("jobId", "jobId"), + } +} + +// String returns a human-readable description of this Backup Job ID +func (id BackupJobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Job: %q", id.JobId), + } + return fmt.Sprintf("Backup Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob_test.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob_test.go new file mode 100644 index 00000000000..41599abfb7e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupjob_test.go @@ -0,0 +1,327 @@ +package azurebackupjob + +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 = &BackupJobId{} + +func TestNewBackupJobID(t *testing.T) { + id := NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "jobId") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.JobId != "jobId" { + t.Fatalf("Expected %q but got %q for Segment 'JobId'", id.JobId, "jobId") + } +} + +func TestFormatBackupJobID(t *testing.T) { + actual := NewBackupJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "jobId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/jobId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupJobId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/jobId", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + JobId: "jobId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/jobId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupJobID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.JobId != v.Expected.JobId { + t.Fatalf("Expected %q but got %q for JobId", v.Expected.JobId, actual.JobId) + } + + } +} + +func TestParseBackupJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupJobId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/jobId", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + JobId: "jobId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/jobId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS/jObId", + Expected: &BackupJobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + JobId: "jObId", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS/jObId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupJobIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.JobId != v.Expected.JobId { + t.Fatalf("Expected %q but got %q for JobId", v.Expected.JobId, actual.JobId) + } + + } +} + +func TestSegmentsForBackupJobId(t *testing.T) { + segments := BackupJobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupJobId 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/dataprotection/2025-02-01/azurebackupjob/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault.go new file mode 100644 index 00000000000..60e15b184a4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault.go @@ -0,0 +1,130 @@ +package azurebackupjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault_test.go new file mode 100644 index 00000000000..c0e90f2c7e4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_backupvault_test.go @@ -0,0 +1,282 @@ +package azurebackupjob + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/azurebackupjob/id_operationid.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid.go new file mode 100644 index 00000000000..5ebcd8579b2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid.go @@ -0,0 +1,140 @@ +package azurebackupjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationIdId{}) +} + +var _ resourceids.ResourceId = &OperationIdId{} + +// OperationIdId is a struct representing the Resource ID for a Operation Id +type OperationIdId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + OperationId string +} + +// NewOperationIdID returns a new OperationIdId struct +func NewOperationIdID(subscriptionId string, resourceGroupName string, backupVaultName string, operationId string) OperationIdId { + return OperationIdId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + OperationId: operationId, + } +} + +// ParseOperationIdID parses 'input' into a OperationIdId +func ParseOperationIdID(input string) (*OperationIdId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationIdId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationIdId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIdIDInsensitively parses 'input' case-insensitively into a OperationIdId +// note: this method should only be used for API response data and not user input +func ParseOperationIdIDInsensitively(input string) (*OperationIdId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationIdId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationIdId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationIdId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationIdID checks that 'input' can be parsed as a Operation Id ID +func ValidateOperationIdID(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 := ParseOperationIdID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation Id ID +func (id OperationIdId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupJobs/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation Id ID +func (id OperationIdId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupJobs", "backupJobs", "backupJobs"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Operation Id ID +func (id OperationIdId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation Id (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid_test.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid_test.go new file mode 100644 index 00000000000..f4e747655e1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/id_operationid_test.go @@ -0,0 +1,342 @@ +package azurebackupjob + +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 = &OperationIdId{} + +func TestNewOperationIdID(t *testing.T) { + id := NewOperationIdID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "operationId") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatOperationIdID(t *testing.T) { + actual := NewOperationIdID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "operationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationIdID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationIdId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations/operationId", + Expected: &OperationIdId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIdID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIdIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationIdId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations/operationId", + Expected: &OperationIdId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupJobs/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS/oPeRaTiOnS/oPeRaTiOnId", + Expected: &OperationIdId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + OperationId: "oPeRaTiOnId", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPjObS/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIdIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationIdId(t *testing.T) { + segments := OperationIdId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationIdId 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/dataprotection/2025-02-01/azurebackupjob/method_exportjobsoperationresultget.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobsoperationresultget.go new file mode 100644 index 00000000000..4df7d900a99 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobsoperationresultget.go @@ -0,0 +1,54 @@ +package azurebackupjob + +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 ExportJobsOperationResultGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExportJobsResult +} + +// ExportJobsOperationResultGet ... +func (c AzureBackupJobClient) ExportJobsOperationResultGet(ctx context.Context, id OperationIdId) (result ExportJobsOperationResultGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ExportJobsResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobstrigger.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobstrigger.go new file mode 100644 index 00000000000..bd466398f8f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_exportjobstrigger.go @@ -0,0 +1,70 @@ +package azurebackupjob + +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 ExportJobsTriggerOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ExportJobsTrigger ... +func (c AzureBackupJobClient) ExportJobsTrigger(ctx context.Context, id BackupVaultId) (result ExportJobsTriggerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportBackupJobs", 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 +} + +// ExportJobsTriggerThenPoll performs ExportJobsTrigger then polls until it's completed +func (c AzureBackupJobClient) ExportJobsTriggerThenPoll(ctx context.Context, id BackupVaultId) error { + result, err := c.ExportJobsTrigger(ctx, id) + if err != nil { + return fmt.Errorf("performing ExportJobsTrigger: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ExportJobsTrigger: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_jobsget.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_jobsget.go new file mode 100644 index 00000000000..ea51644c134 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/method_jobsget.go @@ -0,0 +1,53 @@ +package azurebackupjob + +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 JobsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupJobResource +} + +// JobsGet ... +func (c AzureBackupJobClient) JobsGet(ctx context.Context, id BackupJobId) (result JobsGetOperationResponse, 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 AzureBackupJobResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjob.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjob.go new file mode 100644 index 00000000000..bded4dcf089 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjob.go @@ -0,0 +1,65 @@ +package azurebackupjob + +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 AzureBackupJob struct { + ActivityID string `json:"activityID"` + BackupInstanceFriendlyName string `json:"backupInstanceFriendlyName"` + BackupInstanceId *string `json:"backupInstanceId,omitempty"` + DataSourceId string `json:"dataSourceId"` + DataSourceLocation string `json:"dataSourceLocation"` + DataSourceName string `json:"dataSourceName"` + DataSourceSetName *string `json:"dataSourceSetName,omitempty"` + DataSourceType string `json:"dataSourceType"` + DestinationDataStoreName *string `json:"destinationDataStoreName,omitempty"` + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + ErrorDetails *[]UserFacingError `json:"errorDetails,omitempty"` + Etag *string `json:"etag,omitempty"` + ExtendedInfo *JobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered bool `json:"isUserTriggered"` + Operation string `json:"operation"` + OperationCategory string `json:"operationCategory"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProgressEnabled bool `json:"progressEnabled"` + ProgressURL *string `json:"progressUrl,omitempty"` + RehydrationPriority *string `json:"rehydrationPriority,omitempty"` + RestoreType *string `json:"restoreType,omitempty"` + SourceDataStoreName *string `json:"sourceDataStoreName,omitempty"` + SourceResourceGroup string `json:"sourceResourceGroup"` + SourceSubscriptionID string `json:"sourceSubscriptionID"` + StartTime string `json:"startTime"` + Status string `json:"status"` + SubscriptionId string `json:"subscriptionId"` + SupportedActions []string `json:"supportedActions"` + VaultName string `json:"vaultName"` +} + +func (o *AzureBackupJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureBackupJob) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjobresource.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjobresource.go new file mode 100644 index 00000000000..45faef86221 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_azurebackupjobresource.go @@ -0,0 +1,16 @@ +package azurebackupjob + +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 AzureBackupJobResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupJob `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_exportjobsresult.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_exportjobsresult.go new file mode 100644 index 00000000000..ae0bef75ce4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_exportjobsresult.go @@ -0,0 +1,11 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportJobsResult struct { + BlobSasKey *string `json:"blobSasKey,omitempty"` + BlobURL *string `json:"blobUrl,omitempty"` + ExcelFileBlobSasKey *string `json:"excelFileBlobSasKey,omitempty"` + ExcelFileBlobURL *string `json:"excelFileBlobUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_innererror.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_innererror.go new file mode 100644 index 00000000000..a44d4bdfa57 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_innererror.go @@ -0,0 +1,10 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobextendedinfo.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobextendedinfo.go new file mode 100644 index 00000000000..9c0edd02f99 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobextendedinfo.go @@ -0,0 +1,15 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExtendedInfo struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + BackupInstanceState *string `json:"backupInstanceState,omitempty"` + DataTransferredInBytes *float64 `json:"dataTransferredInBytes,omitempty"` + RecoveryDestination *string `json:"recoveryDestination,omitempty"` + SourceRecoverPoint *RestoreJobRecoveryPointDetails `json:"sourceRecoverPoint,omitempty"` + SubTasks *[]JobSubTask `json:"subTasks,omitempty"` + TargetRecoverPoint *RestoreJobRecoveryPointDetails `json:"targetRecoverPoint,omitempty"` + WarningDetails *[]UserFacingWarningDetail `json:"warningDetails,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobsubtask.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobsubtask.go new file mode 100644 index 00000000000..9d4f15e734d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_jobsubtask.go @@ -0,0 +1,12 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSubTask struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + TaskId int64 `json:"taskId"` + TaskName string `json:"taskName"` + TaskProgress *string `json:"taskProgress,omitempty"` + TaskStatus string `json:"taskStatus"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_restorejobrecoverypointdetails.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_restorejobrecoverypointdetails.go new file mode 100644 index 00000000000..3737e75b44e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_restorejobrecoverypointdetails.go @@ -0,0 +1,27 @@ +package azurebackupjob + +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 RestoreJobRecoveryPointDetails struct { + RecoveryPointID *string `json:"recoveryPointID,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` +} + +func (o *RestoreJobRecoveryPointDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoreJobRecoveryPointDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingerror.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingerror.go new file mode 100644 index 00000000000..0358f4179da --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingerror.go @@ -0,0 +1,16 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingwarningdetail.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingwarningdetail.go new file mode 100644 index 00000000000..f943b79da1d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/model_userfacingwarningdetail.go @@ -0,0 +1,9 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingWarningDetail struct { + ResourceName *string `json:"resourceName,omitempty"` + Warning UserFacingError `json:"warning"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjob/version.go b/resource-manager/dataprotection/2025-02-01/azurebackupjob/version.go new file mode 100644 index 00000000000..750b09e7166 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjob/version.go @@ -0,0 +1,10 @@ +package azurebackupjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/azurebackupjob/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/README.md b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/README.md new file mode 100644 index 00000000000..f526dbdff86 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/azurebackupjobs` Documentation + +The `azurebackupjobs` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/azurebackupjobs" +``` + + +### Client Initialization + +```go +client := azurebackupjobs.NewAzureBackupJobsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AzureBackupJobsClient.JobsList` + +```go +ctx := context.TODO() +id := azurebackupjobs.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +// alternatively `client.JobsList(ctx, id)` can be used to do batched pagination +items, err := client.JobsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/client.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/client.go new file mode 100644 index 00000000000..1028ad5240a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/client.go @@ -0,0 +1,26 @@ +package azurebackupjobs + +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 AzureBackupJobsClient struct { + Client *resourcemanager.Client +} + +func NewAzureBackupJobsClientWithBaseURI(sdkApi sdkEnv.Api) (*AzureBackupJobsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "azurebackupjobs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AzureBackupJobsClient: %+v", err) + } + + return &AzureBackupJobsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault.go new file mode 100644 index 00000000000..872d9e4671b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault.go @@ -0,0 +1,130 @@ +package azurebackupjobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault_test.go new file mode 100644 index 00000000000..ce956b8e296 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/id_backupvault_test.go @@ -0,0 +1,282 @@ +package azurebackupjobs + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/azurebackupjobs/method_jobslist.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/method_jobslist.go new file mode 100644 index 00000000000..016ccbbd75e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/method_jobslist.go @@ -0,0 +1,105 @@ +package azurebackupjobs + +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 JobsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureBackupJobResource +} + +type JobsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureBackupJobResource +} + +type JobsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *JobsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// JobsList ... +func (c AzureBackupJobsClient) JobsList(ctx context.Context, id BackupVaultId) (result JobsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &JobsListCustomPager{}, + Path: fmt.Sprintf("%s/backupJobs", 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 *[]AzureBackupJobResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// JobsListComplete retrieves all the results into a single object +func (c AzureBackupJobsClient) JobsListComplete(ctx context.Context, id BackupVaultId) (JobsListCompleteResult, error) { + return c.JobsListCompleteMatchingPredicate(ctx, id, AzureBackupJobResourceOperationPredicate{}) +} + +// JobsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AzureBackupJobsClient) JobsListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate AzureBackupJobResourceOperationPredicate) (result JobsListCompleteResult, err error) { + items := make([]AzureBackupJobResource, 0) + + resp, err := c.JobsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = JobsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjob.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjob.go new file mode 100644 index 00000000000..72b72465937 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjob.go @@ -0,0 +1,65 @@ +package azurebackupjobs + +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 AzureBackupJob struct { + ActivityID string `json:"activityID"` + BackupInstanceFriendlyName string `json:"backupInstanceFriendlyName"` + BackupInstanceId *string `json:"backupInstanceId,omitempty"` + DataSourceId string `json:"dataSourceId"` + DataSourceLocation string `json:"dataSourceLocation"` + DataSourceName string `json:"dataSourceName"` + DataSourceSetName *string `json:"dataSourceSetName,omitempty"` + DataSourceType string `json:"dataSourceType"` + DestinationDataStoreName *string `json:"destinationDataStoreName,omitempty"` + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + ErrorDetails *[]UserFacingError `json:"errorDetails,omitempty"` + Etag *string `json:"etag,omitempty"` + ExtendedInfo *JobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered bool `json:"isUserTriggered"` + Operation string `json:"operation"` + OperationCategory string `json:"operationCategory"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProgressEnabled bool `json:"progressEnabled"` + ProgressURL *string `json:"progressUrl,omitempty"` + RehydrationPriority *string `json:"rehydrationPriority,omitempty"` + RestoreType *string `json:"restoreType,omitempty"` + SourceDataStoreName *string `json:"sourceDataStoreName,omitempty"` + SourceResourceGroup string `json:"sourceResourceGroup"` + SourceSubscriptionID string `json:"sourceSubscriptionID"` + StartTime string `json:"startTime"` + Status string `json:"status"` + SubscriptionId string `json:"subscriptionId"` + SupportedActions []string `json:"supportedActions"` + VaultName string `json:"vaultName"` +} + +func (o *AzureBackupJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureBackupJob) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjobresource.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjobresource.go new file mode 100644 index 00000000000..17c72e55e47 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_azurebackupjobresource.go @@ -0,0 +1,16 @@ +package azurebackupjobs + +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 AzureBackupJobResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupJob `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_innererror.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_innererror.go new file mode 100644 index 00000000000..323f65bc431 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_innererror.go @@ -0,0 +1,10 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobextendedinfo.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobextendedinfo.go new file mode 100644 index 00000000000..2b210b62683 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobextendedinfo.go @@ -0,0 +1,15 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExtendedInfo struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + BackupInstanceState *string `json:"backupInstanceState,omitempty"` + DataTransferredInBytes *float64 `json:"dataTransferredInBytes,omitempty"` + RecoveryDestination *string `json:"recoveryDestination,omitempty"` + SourceRecoverPoint *RestoreJobRecoveryPointDetails `json:"sourceRecoverPoint,omitempty"` + SubTasks *[]JobSubTask `json:"subTasks,omitempty"` + TargetRecoverPoint *RestoreJobRecoveryPointDetails `json:"targetRecoverPoint,omitempty"` + WarningDetails *[]UserFacingWarningDetail `json:"warningDetails,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobsubtask.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobsubtask.go new file mode 100644 index 00000000000..0f42da0bc24 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_jobsubtask.go @@ -0,0 +1,12 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSubTask struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + TaskId int64 `json:"taskId"` + TaskName string `json:"taskName"` + TaskProgress *string `json:"taskProgress,omitempty"` + TaskStatus string `json:"taskStatus"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_restorejobrecoverypointdetails.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_restorejobrecoverypointdetails.go new file mode 100644 index 00000000000..569a995bb39 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_restorejobrecoverypointdetails.go @@ -0,0 +1,27 @@ +package azurebackupjobs + +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 RestoreJobRecoveryPointDetails struct { + RecoveryPointID *string `json:"recoveryPointID,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` +} + +func (o *RestoreJobRecoveryPointDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoreJobRecoveryPointDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingerror.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingerror.go new file mode 100644 index 00000000000..562e9fe4e79 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingerror.go @@ -0,0 +1,16 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingwarningdetail.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingwarningdetail.go new file mode 100644 index 00000000000..5fdf9d22cc7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/model_userfacingwarningdetail.go @@ -0,0 +1,9 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingWarningDetail struct { + ResourceName *string `json:"resourceName,omitempty"` + Warning UserFacingError `json:"warning"` +} diff --git a/resource-manager/dataprotection/2025-02-01/azurebackupjobs/predicates.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/predicates.go new file mode 100644 index 00000000000..5f79648ba7d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/predicates.go @@ -0,0 +1,27 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupJobResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupJobResourceOperationPredicate) Matches(input AzureBackupJobResource) 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/dataprotection/2025-02-01/azurebackupjobs/version.go b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/version.go new file mode 100644 index 00000000000..65951873885 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/azurebackupjobs/version.go @@ -0,0 +1,10 @@ +package azurebackupjobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/azurebackupjobs/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/README.md b/resource-manager/dataprotection/2025-02-01/backupinstances/README.md new file mode 100644 index 00000000000..2dd742741cd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/README.md @@ -0,0 +1,293 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupinstances` Documentation + +The `backupinstances` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupinstances" +``` + + +### Client Initialization + +```go +client := backupinstances.NewBackupInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupInstancesClient.AdhocBackup` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.TriggerBackupRequest{ + // ... +} + + +if err := client.AdhocBackupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.BackupInstanceResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, backupinstances.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.Delete` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +if err := client.DeleteThenPoll(ctx, id, backupinstances.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.Get` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +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: `BackupInstancesClient.List` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +// 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: `BackupInstancesClient.ResumeBackups` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +if err := client.ResumeBackupsThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ResumeProtection` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +if err := client.ResumeProtectionThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.StopProtection` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.StopProtectionRequest{ + // ... +} + + +if err := client.StopProtectionThenPoll(ctx, id, payload, backupinstances.DefaultStopProtectionOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.SuspendBackups` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.SuspendBackupRequest{ + // ... +} + + +if err := client.SuspendBackupsThenPoll(ctx, id, payload, backupinstances.DefaultSuspendBackupsOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.SyncBackupInstance` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.SyncBackupInstanceRequest{ + // ... +} + + +if err := client.SyncBackupInstanceThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.TriggerCrossRegionRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +payload := backupinstances.CrossRegionRestoreRequestObject{ + // ... +} + + +if err := client.TriggerCrossRegionRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.TriggerRehydrate` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.AzureBackupRehydrationRequest{ + // ... +} + + +if err := client.TriggerRehydrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.TriggerRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.AzureBackupRestoreRequest{ + // ... +} + + +if err := client.TriggerRestoreThenPoll(ctx, id, payload, backupinstances.DefaultTriggerRestoreOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateCrossRegionRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +payload := backupinstances.ValidateCrossRegionRestoreRequestObject{ + // ... +} + + +if err := client.ValidateCrossRegionRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateForBackup` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +payload := backupinstances.ValidateForBackupRequest{ + // ... +} + + +if err := client.ValidateForBackupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateForModifyBackup` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.ValidateForModifyBackupRequest{ + // ... +} + + +if err := client.ValidateForModifyBackupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupInstancesClient.ValidateForRestore` + +```go +ctx := context.TODO() +id := backupinstances.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := backupinstances.ValidateRestoreRequestObject{ + // ... +} + + +if err := client.ValidateForRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/client.go b/resource-manager/dataprotection/2025-02-01/backupinstances/client.go new file mode 100644 index 00000000000..d0c8a08b5f2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/client.go @@ -0,0 +1,26 @@ +package backupinstances + +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 BackupInstancesClient struct { + Client *resourcemanager.Client +} + +func NewBackupInstancesClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupInstancesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "backupinstances", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupInstancesClient: %+v", err) + } + + return &BackupInstancesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/constants.go b/resource-manager/dataprotection/2025-02-01/backupinstances/constants.go new file mode 100644 index 00000000000..ba15811e9d9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/constants.go @@ -0,0 +1,635 @@ +package backupinstances + +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 AKSVolumeTypes string + +const ( + AKSVolumeTypesAzureDisk AKSVolumeTypes = "AzureDisk" + AKSVolumeTypesAzureFileShareSMB AKSVolumeTypes = "AzureFileShareSMB" +) + +func PossibleValuesForAKSVolumeTypes() []string { + return []string{ + string(AKSVolumeTypesAzureDisk), + string(AKSVolumeTypesAzureFileShareSMB), + } +} + +func (s *AKSVolumeTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAKSVolumeTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAKSVolumeTypes(input string) (*AKSVolumeTypes, error) { + vals := map[string]AKSVolumeTypes{ + "azuredisk": AKSVolumeTypesAzureDisk, + "azurefilesharesmb": AKSVolumeTypesAzureFileShareSMB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AKSVolumeTypes(input) + return &out, nil +} + +type CurrentProtectionState string + +const ( + CurrentProtectionStateBackupSchedulesSuspended CurrentProtectionState = "BackupSchedulesSuspended" + CurrentProtectionStateConfiguringProtection CurrentProtectionState = "ConfiguringProtection" + CurrentProtectionStateConfiguringProtectionFailed CurrentProtectionState = "ConfiguringProtectionFailed" + CurrentProtectionStateInvalid CurrentProtectionState = "Invalid" + CurrentProtectionStateNotProtected CurrentProtectionState = "NotProtected" + CurrentProtectionStateProtectionConfigured CurrentProtectionState = "ProtectionConfigured" + CurrentProtectionStateProtectionError CurrentProtectionState = "ProtectionError" + CurrentProtectionStateProtectionStopped CurrentProtectionState = "ProtectionStopped" + CurrentProtectionStateRetentionSchedulesSuspended CurrentProtectionState = "RetentionSchedulesSuspended" + CurrentProtectionStateSoftDeleted CurrentProtectionState = "SoftDeleted" + CurrentProtectionStateSoftDeleting CurrentProtectionState = "SoftDeleting" + CurrentProtectionStateUpdatingProtection CurrentProtectionState = "UpdatingProtection" +) + +func PossibleValuesForCurrentProtectionState() []string { + return []string{ + string(CurrentProtectionStateBackupSchedulesSuspended), + string(CurrentProtectionStateConfiguringProtection), + string(CurrentProtectionStateConfiguringProtectionFailed), + string(CurrentProtectionStateInvalid), + string(CurrentProtectionStateNotProtected), + string(CurrentProtectionStateProtectionConfigured), + string(CurrentProtectionStateProtectionError), + string(CurrentProtectionStateProtectionStopped), + string(CurrentProtectionStateRetentionSchedulesSuspended), + string(CurrentProtectionStateSoftDeleted), + string(CurrentProtectionStateSoftDeleting), + string(CurrentProtectionStateUpdatingProtection), + } +} + +func (s *CurrentProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCurrentProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCurrentProtectionState(input string) (*CurrentProtectionState, error) { + vals := map[string]CurrentProtectionState{ + "backupschedulessuspended": CurrentProtectionStateBackupSchedulesSuspended, + "configuringprotection": CurrentProtectionStateConfiguringProtection, + "configuringprotectionfailed": CurrentProtectionStateConfiguringProtectionFailed, + "invalid": CurrentProtectionStateInvalid, + "notprotected": CurrentProtectionStateNotProtected, + "protectionconfigured": CurrentProtectionStateProtectionConfigured, + "protectionerror": CurrentProtectionStateProtectionError, + "protectionstopped": CurrentProtectionStateProtectionStopped, + "retentionschedulessuspended": CurrentProtectionStateRetentionSchedulesSuspended, + "softdeleted": CurrentProtectionStateSoftDeleted, + "softdeleting": CurrentProtectionStateSoftDeleting, + "updatingprotection": CurrentProtectionStateUpdatingProtection, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CurrentProtectionState(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +type ExistingResourcePolicy string + +const ( + ExistingResourcePolicyPatch ExistingResourcePolicy = "Patch" + ExistingResourcePolicySkip ExistingResourcePolicy = "Skip" +) + +func PossibleValuesForExistingResourcePolicy() []string { + return []string{ + string(ExistingResourcePolicyPatch), + string(ExistingResourcePolicySkip), + } +} + +func (s *ExistingResourcePolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExistingResourcePolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExistingResourcePolicy(input string) (*ExistingResourcePolicy, error) { + vals := map[string]ExistingResourcePolicy{ + "patch": ExistingResourcePolicyPatch, + "skip": ExistingResourcePolicySkip, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExistingResourcePolicy(input) + return &out, nil +} + +type PersistentVolumeRestoreMode string + +const ( + PersistentVolumeRestoreModeRestoreWithVolumeData PersistentVolumeRestoreMode = "RestoreWithVolumeData" + PersistentVolumeRestoreModeRestoreWithoutVolumeData PersistentVolumeRestoreMode = "RestoreWithoutVolumeData" +) + +func PossibleValuesForPersistentVolumeRestoreMode() []string { + return []string{ + string(PersistentVolumeRestoreModeRestoreWithVolumeData), + string(PersistentVolumeRestoreModeRestoreWithoutVolumeData), + } +} + +func (s *PersistentVolumeRestoreMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePersistentVolumeRestoreMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePersistentVolumeRestoreMode(input string) (*PersistentVolumeRestoreMode, error) { + vals := map[string]PersistentVolumeRestoreMode{ + "restorewithvolumedata": PersistentVolumeRestoreModeRestoreWithVolumeData, + "restorewithoutvolumedata": PersistentVolumeRestoreModeRestoreWithoutVolumeData, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PersistentVolumeRestoreMode(input) + return &out, nil +} + +type RecoveryOption string + +const ( + RecoveryOptionFailIfExists RecoveryOption = "FailIfExists" +) + +func PossibleValuesForRecoveryOption() []string { + return []string{ + string(RecoveryOptionFailIfExists), + } +} + +func (s *RecoveryOption) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecoveryOption(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecoveryOption(input string) (*RecoveryOption, error) { + vals := map[string]RecoveryOption{ + "failifexists": RecoveryOptionFailIfExists, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryOption(input) + return &out, nil +} + +type RehydrationPriority string + +const ( + RehydrationPriorityHigh RehydrationPriority = "High" + RehydrationPriorityInvalid RehydrationPriority = "Invalid" + RehydrationPriorityStandard RehydrationPriority = "Standard" +) + +func PossibleValuesForRehydrationPriority() []string { + return []string{ + string(RehydrationPriorityHigh), + string(RehydrationPriorityInvalid), + string(RehydrationPriorityStandard), + } +} + +func (s *RehydrationPriority) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRehydrationPriority(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRehydrationPriority(input string) (*RehydrationPriority, error) { + vals := map[string]RehydrationPriority{ + "high": RehydrationPriorityHigh, + "invalid": RehydrationPriorityInvalid, + "standard": RehydrationPriorityStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RehydrationPriority(input) + return &out, nil +} + +type ResourcePropertiesObjectType string + +const ( + ResourcePropertiesObjectTypeDefaultResourceProperties ResourcePropertiesObjectType = "DefaultResourceProperties" +) + +func PossibleValuesForResourcePropertiesObjectType() []string { + return []string{ + string(ResourcePropertiesObjectTypeDefaultResourceProperties), + } +} + +func (s *ResourcePropertiesObjectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourcePropertiesObjectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourcePropertiesObjectType(input string) (*ResourcePropertiesObjectType, error) { + vals := map[string]ResourcePropertiesObjectType{ + "defaultresourceproperties": ResourcePropertiesObjectTypeDefaultResourceProperties, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourcePropertiesObjectType(input) + return &out, nil +} + +type RestoreTargetLocationType string + +const ( + RestoreTargetLocationTypeAzureBlobs RestoreTargetLocationType = "AzureBlobs" + RestoreTargetLocationTypeAzureFiles RestoreTargetLocationType = "AzureFiles" + RestoreTargetLocationTypeInvalid RestoreTargetLocationType = "Invalid" +) + +func PossibleValuesForRestoreTargetLocationType() []string { + return []string{ + string(RestoreTargetLocationTypeAzureBlobs), + string(RestoreTargetLocationTypeAzureFiles), + string(RestoreTargetLocationTypeInvalid), + } +} + +func (s *RestoreTargetLocationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestoreTargetLocationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestoreTargetLocationType(input string) (*RestoreTargetLocationType, error) { + vals := map[string]RestoreTargetLocationType{ + "azureblobs": RestoreTargetLocationTypeAzureBlobs, + "azurefiles": RestoreTargetLocationTypeAzureFiles, + "invalid": RestoreTargetLocationTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreTargetLocationType(input) + return &out, nil +} + +type SecretStoreType string + +const ( + SecretStoreTypeAzureKeyVault SecretStoreType = "AzureKeyVault" + SecretStoreTypeInvalid SecretStoreType = "Invalid" +) + +func PossibleValuesForSecretStoreType() []string { + return []string{ + string(SecretStoreTypeAzureKeyVault), + string(SecretStoreTypeInvalid), + } +} + +func (s *SecretStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretStoreType(input string) (*SecretStoreType, error) { + vals := map[string]SecretStoreType{ + "azurekeyvault": SecretStoreTypeAzureKeyVault, + "invalid": SecretStoreTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretStoreType(input) + return &out, nil +} + +type SourceDataStoreType string + +const ( + SourceDataStoreTypeArchiveStore SourceDataStoreType = "ArchiveStore" + SourceDataStoreTypeOperationalStore SourceDataStoreType = "OperationalStore" + SourceDataStoreTypeSnapshotStore SourceDataStoreType = "SnapshotStore" + SourceDataStoreTypeVaultStore SourceDataStoreType = "VaultStore" +) + +func PossibleValuesForSourceDataStoreType() []string { + return []string{ + string(SourceDataStoreTypeArchiveStore), + string(SourceDataStoreTypeOperationalStore), + string(SourceDataStoreTypeSnapshotStore), + string(SourceDataStoreTypeVaultStore), + } +} + +func (s *SourceDataStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceDataStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceDataStoreType(input string) (*SourceDataStoreType, error) { + vals := map[string]SourceDataStoreType{ + "archivestore": SourceDataStoreTypeArchiveStore, + "operationalstore": SourceDataStoreTypeOperationalStore, + "snapshotstore": SourceDataStoreTypeSnapshotStore, + "vaultstore": SourceDataStoreTypeVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceDataStoreType(input) + return &out, nil +} + +type Status string + +const ( + StatusConfiguringProtection Status = "ConfiguringProtection" + StatusConfiguringProtectionFailed Status = "ConfiguringProtectionFailed" + StatusProtectionConfigured Status = "ProtectionConfigured" + StatusProtectionStopped Status = "ProtectionStopped" + StatusSoftDeleted Status = "SoftDeleted" + StatusSoftDeleting Status = "SoftDeleting" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConfiguringProtection), + string(StatusConfiguringProtectionFailed), + string(StatusProtectionConfigured), + string(StatusProtectionStopped), + string(StatusSoftDeleted), + string(StatusSoftDeleting), + } +} + +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{ + "configuringprotection": StatusConfiguringProtection, + "configuringprotectionfailed": StatusConfiguringProtectionFailed, + "protectionconfigured": StatusProtectionConfigured, + "protectionstopped": StatusProtectionStopped, + "softdeleted": StatusSoftDeleted, + "softdeleting": StatusSoftDeleting, + } + 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 SyncType string + +const ( + SyncTypeDefault SyncType = "Default" + SyncTypeForceResync SyncType = "ForceResync" +) + +func PossibleValuesForSyncType() []string { + return []string{ + string(SyncTypeDefault), + string(SyncTypeForceResync), + } +} + +func (s *SyncType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncType(input string) (*SyncType, error) { + vals := map[string]SyncType{ + "default": SyncTypeDefault, + "forceresync": SyncTypeForceResync, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncType(input) + return &out, nil +} + +type ValidationType string + +const ( + ValidationTypeDeepValidation ValidationType = "DeepValidation" + ValidationTypeShallowValidation ValidationType = "ShallowValidation" +) + +func PossibleValuesForValidationType() []string { + return []string{ + string(ValidationTypeDeepValidation), + string(ValidationTypeShallowValidation), + } +} + +func (s *ValidationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseValidationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseValidationType(input string) (*ValidationType, error) { + vals := map[string]ValidationType{ + "deepvalidation": ValidationTypeDeepValidation, + "shallowvalidation": ValidationTypeShallowValidation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance.go b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance.go new file mode 100644 index 00000000000..ba2f8ee0d24 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance.go @@ -0,0 +1,139 @@ +package backupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupInstanceId{}) +} + +var _ resourceids.ResourceId = &BackupInstanceId{} + +// BackupInstanceId is a struct representing the Resource ID for a Backup Instance +type BackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string +} + +// NewBackupInstanceID returns a new BackupInstanceId struct +func NewBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string) BackupInstanceId { + return BackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + } +} + +// ParseBackupInstanceID parses 'input' into a BackupInstanceId +func ParseBackupInstanceID(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupInstanceIDInsensitively parses 'input' case-insensitively into a BackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseBackupInstanceIDInsensitively(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupInstanceId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + return nil +} + +// ValidateBackupInstanceID checks that 'input' can be parsed as a Backup Instance ID +func ValidateBackupInstanceID(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 := ParseBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Instance ID +func (id BackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Instance ID +func (id BackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceName"), + } +} + +// String returns a human-readable description of this Backup Instance ID +func (id BackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + } + return fmt.Sprintf("Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance_test.go b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance_test.go new file mode 100644 index 00000000000..cf93cede095 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupinstance_test.go @@ -0,0 +1,327 @@ +package backupinstances + +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 = &BackupInstanceId{} + +func TestNewBackupInstanceID(t *testing.T) { + id := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.BackupInstanceName != "backupInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceName") + } +} + +func TestFormatBackupInstanceID(t *testing.T) { + actual := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestParseBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + BackupInstanceName: "bAcKuPiNsTaNcEnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestSegmentsForBackupInstanceId(t *testing.T) { + segments := BackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupInstanceId 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/dataprotection/2025-02-01/backupinstances/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault.go new file mode 100644 index 00000000000..342e7e6842d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault.go @@ -0,0 +1,130 @@ +package backupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault_test.go new file mode 100644 index 00000000000..a7e929d4ab1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/id_backupvault_test.go @@ -0,0 +1,282 @@ +package backupinstances + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/backupinstances/id_providerlocation.go b/resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation.go new file mode 100644 index 00000000000..5d023dc0eb9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation.go @@ -0,0 +1,130 @@ +package backupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation_test.go b/resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation_test.go new file mode 100644 index 00000000000..ef5e7d201b7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package backupinstances + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2025-02-01/backupinstances/method_adhocbackup.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_adhocbackup.go new file mode 100644 index 00000000000..e9b23922bd5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_adhocbackup.go @@ -0,0 +1,75 @@ +package backupinstances + +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 AdhocBackupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationJobExtendedInfo +} + +// AdhocBackup ... +func (c BackupInstancesClient) AdhocBackup(ctx context.Context, id BackupInstanceId, input TriggerBackupRequest) (result AdhocBackupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/backup", 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 +} + +// AdhocBackupThenPoll performs AdhocBackup then polls until it's completed +func (c BackupInstancesClient) AdhocBackupThenPoll(ctx context.Context, id BackupInstanceId, input TriggerBackupRequest) error { + result, err := c.AdhocBackup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AdhocBackup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AdhocBackup: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_createorupdate.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_createorupdate.go new file mode 100644 index 00000000000..7f9162cb178 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_createorupdate.go @@ -0,0 +1,105 @@ +package backupinstances + +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 *BackupInstanceResource +} + +type CreateOrUpdateOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c BackupInstancesClient) CreateOrUpdate(ctx context.Context, id BackupInstanceId, input BackupInstanceResource, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 BackupInstancesClient) CreateOrUpdateThenPoll(ctx context.Context, id BackupInstanceId, input BackupInstanceResource, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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/dataprotection/2025-02-01/backupinstances/method_delete.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_delete.go new file mode 100644 index 00000000000..3de0e319d1f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_delete.go @@ -0,0 +1,100 @@ +package backupinstances + +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 +} + +type DeleteOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c BackupInstancesClient) Delete(ctx context.Context, id BackupInstanceId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + 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 BackupInstancesClient) DeleteThenPoll(ctx context.Context, id BackupInstanceId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + 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/dataprotection/2025-02-01/backupinstances/method_get.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_get.go new file mode 100644 index 00000000000..39aa6d46c90 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_get.go @@ -0,0 +1,53 @@ +package backupinstances + +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 *BackupInstanceResource +} + +// Get ... +func (c BackupInstancesClient) Get(ctx context.Context, id BackupInstanceId) (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 BackupInstanceResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_list.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_list.go new file mode 100644 index 00000000000..e59d6159025 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_list.go @@ -0,0 +1,105 @@ +package backupinstances + +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 *[]BackupInstanceResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackupInstanceResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c BackupInstancesClient) List(ctx context.Context, id BackupVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/backupInstances", 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 *[]BackupInstanceResource `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 BackupInstancesClient) ListComplete(ctx context.Context, id BackupVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BackupInstanceResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupInstancesClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate BackupInstanceResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]BackupInstanceResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_resumebackups.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_resumebackups.go new file mode 100644 index 00000000000..afecf4c1dbc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_resumebackups.go @@ -0,0 +1,70 @@ +package backupinstances + +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 ResumeBackupsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ResumeBackups ... +func (c BackupInstancesClient) ResumeBackups(ctx context.Context, id BackupInstanceId) (result ResumeBackupsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resumeBackups", 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 +} + +// ResumeBackupsThenPoll performs ResumeBackups then polls until it's completed +func (c BackupInstancesClient) ResumeBackupsThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.ResumeBackups(ctx, id) + if err != nil { + return fmt.Errorf("performing ResumeBackups: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ResumeBackups: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_resumeprotection.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_resumeprotection.go new file mode 100644 index 00000000000..5903e05788c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_resumeprotection.go @@ -0,0 +1,70 @@ +package backupinstances + +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 ResumeProtectionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ResumeProtection ... +func (c BackupInstancesClient) ResumeProtection(ctx context.Context, id BackupInstanceId) (result ResumeProtectionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resumeProtection", 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 +} + +// ResumeProtectionThenPoll performs ResumeProtection then polls until it's completed +func (c BackupInstancesClient) ResumeProtectionThenPoll(ctx context.Context, id BackupInstanceId) error { + result, err := c.ResumeProtection(ctx, id) + if err != nil { + return fmt.Errorf("performing ResumeProtection: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ResumeProtection: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_stopprotection.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_stopprotection.go new file mode 100644 index 00000000000..f42acb7c160 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_stopprotection.go @@ -0,0 +1,103 @@ +package backupinstances + +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 StopProtectionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type StopProtectionOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultStopProtectionOperationOptions() StopProtectionOperationOptions { + return StopProtectionOperationOptions{} +} + +func (o StopProtectionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o StopProtectionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o StopProtectionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// StopProtection ... +func (c BackupInstancesClient) StopProtection(ctx context.Context, id BackupInstanceId, input StopProtectionRequest, options StopProtectionOperationOptions) (result StopProtectionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/stopProtection", 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 +} + +// StopProtectionThenPoll performs StopProtection then polls until it's completed +func (c BackupInstancesClient) StopProtectionThenPoll(ctx context.Context, id BackupInstanceId, input StopProtectionRequest, options StopProtectionOperationOptions) error { + result, err := c.StopProtection(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing StopProtection: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after StopProtection: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_suspendbackups.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_suspendbackups.go new file mode 100644 index 00000000000..28443e575a6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_suspendbackups.go @@ -0,0 +1,103 @@ +package backupinstances + +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 SuspendBackupsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type SuspendBackupsOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultSuspendBackupsOperationOptions() SuspendBackupsOperationOptions { + return SuspendBackupsOperationOptions{} +} + +func (o SuspendBackupsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o SuspendBackupsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o SuspendBackupsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// SuspendBackups ... +func (c BackupInstancesClient) SuspendBackups(ctx context.Context, id BackupInstanceId, input SuspendBackupRequest, options SuspendBackupsOperationOptions) (result SuspendBackupsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/suspendBackups", 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 +} + +// SuspendBackupsThenPoll performs SuspendBackups then polls until it's completed +func (c BackupInstancesClient) SuspendBackupsThenPoll(ctx context.Context, id BackupInstanceId, input SuspendBackupRequest, options SuspendBackupsOperationOptions) error { + result, err := c.SuspendBackups(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing SuspendBackups: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SuspendBackups: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_syncbackupinstance.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_syncbackupinstance.go new file mode 100644 index 00000000000..b91587d0462 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_syncbackupinstance.go @@ -0,0 +1,74 @@ +package backupinstances + +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 SyncBackupInstanceOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SyncBackupInstance ... +func (c BackupInstancesClient) SyncBackupInstance(ctx context.Context, id BackupInstanceId, input SyncBackupInstanceRequest) (result SyncBackupInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sync", 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 +} + +// SyncBackupInstanceThenPoll performs SyncBackupInstance then polls until it's completed +func (c BackupInstancesClient) SyncBackupInstanceThenPoll(ctx context.Context, id BackupInstanceId, input SyncBackupInstanceRequest) error { + result, err := c.SyncBackupInstance(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SyncBackupInstance: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SyncBackupInstance: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggercrossregionrestore.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggercrossregionrestore.go new file mode 100644 index 00000000000..081a04a7e83 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggercrossregionrestore.go @@ -0,0 +1,75 @@ +package backupinstances + +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 TriggerCrossRegionRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationJobExtendedInfo +} + +// TriggerCrossRegionRestore ... +func (c BackupInstancesClient) TriggerCrossRegionRestore(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreRequestObject) (result TriggerCrossRegionRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/crossRegionRestore", 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 +} + +// TriggerCrossRegionRestoreThenPoll performs TriggerCrossRegionRestore then polls until it's completed +func (c BackupInstancesClient) TriggerCrossRegionRestoreThenPoll(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreRequestObject) error { + result, err := c.TriggerCrossRegionRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TriggerCrossRegionRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TriggerCrossRegionRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrehydrate.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrehydrate.go new file mode 100644 index 00000000000..0daeeff100f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrehydrate.go @@ -0,0 +1,74 @@ +package backupinstances + +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 TriggerRehydrateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// TriggerRehydrate ... +func (c BackupInstancesClient) TriggerRehydrate(ctx context.Context, id BackupInstanceId, input AzureBackupRehydrationRequest) (result TriggerRehydrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/rehydrate", 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 +} + +// TriggerRehydrateThenPoll performs TriggerRehydrate then polls until it's completed +func (c BackupInstancesClient) TriggerRehydrateThenPoll(ctx context.Context, id BackupInstanceId, input AzureBackupRehydrationRequest) error { + result, err := c.TriggerRehydrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TriggerRehydrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TriggerRehydrate: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrestore.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrestore.go new file mode 100644 index 00000000000..c301fac0f4a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_triggerrestore.go @@ -0,0 +1,104 @@ +package backupinstances + +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 TriggerRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationJobExtendedInfo +} + +type TriggerRestoreOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultTriggerRestoreOperationOptions() TriggerRestoreOperationOptions { + return TriggerRestoreOperationOptions{} +} + +func (o TriggerRestoreOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o TriggerRestoreOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o TriggerRestoreOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// TriggerRestore ... +func (c BackupInstancesClient) TriggerRestore(ctx context.Context, id BackupInstanceId, input AzureBackupRestoreRequest, options TriggerRestoreOperationOptions) (result TriggerRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/restore", 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 +} + +// TriggerRestoreThenPoll performs TriggerRestore then polls until it's completed +func (c BackupInstancesClient) TriggerRestoreThenPoll(ctx context.Context, id BackupInstanceId, input AzureBackupRestoreRequest, options TriggerRestoreOperationOptions) error { + result, err := c.TriggerRestore(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing TriggerRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TriggerRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_validatecrossregionrestore.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validatecrossregionrestore.go new file mode 100644 index 00000000000..f3492da21b7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validatecrossregionrestore.go @@ -0,0 +1,75 @@ +package backupinstances + +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 ValidateCrossRegionRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationJobExtendedInfo +} + +// ValidateCrossRegionRestore ... +func (c BackupInstancesClient) ValidateCrossRegionRestore(ctx context.Context, id ProviderLocationId, input ValidateCrossRegionRestoreRequestObject) (result ValidateCrossRegionRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateCrossRegionRestore", 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 +} + +// ValidateCrossRegionRestoreThenPoll performs ValidateCrossRegionRestore then polls until it's completed +func (c BackupInstancesClient) ValidateCrossRegionRestoreThenPoll(ctx context.Context, id ProviderLocationId, input ValidateCrossRegionRestoreRequestObject) error { + result, err := c.ValidateCrossRegionRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateCrossRegionRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateCrossRegionRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforbackup.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforbackup.go new file mode 100644 index 00000000000..b2f9beb384e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforbackup.go @@ -0,0 +1,75 @@ +package backupinstances + +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 ValidateForBackupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationJobExtendedInfo +} + +// ValidateForBackup ... +func (c BackupInstancesClient) ValidateForBackup(ctx context.Context, id BackupVaultId, input ValidateForBackupRequest) (result ValidateForBackupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateForBackup", 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 +} + +// ValidateForBackupThenPoll performs ValidateForBackup then polls until it's completed +func (c BackupInstancesClient) ValidateForBackupThenPoll(ctx context.Context, id BackupVaultId, input ValidateForBackupRequest) error { + result, err := c.ValidateForBackup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateForBackup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateForBackup: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateformodifybackup.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateformodifybackup.go new file mode 100644 index 00000000000..2b916c7c150 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateformodifybackup.go @@ -0,0 +1,73 @@ +package backupinstances + +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 ValidateForModifyBackupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ValidateForModifyBackup ... +func (c BackupInstancesClient) ValidateForModifyBackup(ctx context.Context, id BackupInstanceId, input ValidateForModifyBackupRequest) (result ValidateForModifyBackupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateForModifyBackup", 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 +} + +// ValidateForModifyBackupThenPoll performs ValidateForModifyBackup then polls until it's completed +func (c BackupInstancesClient) ValidateForModifyBackupThenPoll(ctx context.Context, id BackupInstanceId, input ValidateForModifyBackupRequest) error { + result, err := c.ValidateForModifyBackup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateForModifyBackup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateForModifyBackup: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforrestore.go b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforrestore.go new file mode 100644 index 00000000000..2a4adedbdea --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/method_validateforrestore.go @@ -0,0 +1,75 @@ +package backupinstances + +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 ValidateForRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationJobExtendedInfo +} + +// ValidateForRestore ... +func (c BackupInstancesClient) ValidateForRestore(ctx context.Context, id BackupInstanceId, input ValidateRestoreRequestObject) (result ValidateForRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateRestore", 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 +} + +// ValidateForRestoreThenPoll performs ValidateForRestore then polls until it's completed +func (c BackupInstancesClient) ValidateForRestoreThenPoll(ctx context.Context, id BackupInstanceId, input ValidateRestoreRequestObject) error { + result, err := c.ValidateForRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateForRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateForRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackupruleoptions.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackupruleoptions.go new file mode 100644 index 00000000000..6c6e86388b8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackupruleoptions.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdHocBackupRuleOptions struct { + RuleName string `json:"ruleName"` + TriggerOption AdhocBackupTriggerOption `json:"triggerOption"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackuptriggeroption.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackuptriggeroption.go new file mode 100644 index 00000000000..3ce1a004123 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_adhocbackuptriggeroption.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdhocBackupTriggerOption struct { + RetentionTagOverride *string `json:"retentionTagOverride,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_adlsblobbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_adlsblobbackupdatasourceparameters.go new file mode 100644 index 00000000000..d12678c1796 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_adlsblobbackupdatasourceparameters.go @@ -0,0 +1,50 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = AdlsBlobBackupDatasourceParameters{} + +type AdlsBlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s AdlsBlobBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AdlsBlobBackupDatasourceParameters{} + +func (s AdlsBlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper AdlsBlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "AdlsBlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_authcredentials.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_authcredentials.go new file mode 100644 index 00000000000..a76df9971fd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_authcredentials.go @@ -0,0 +1,75 @@ +package backupinstances + +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 AuthCredentials interface { + AuthCredentials() BaseAuthCredentialsImpl +} + +var _ AuthCredentials = BaseAuthCredentialsImpl{} + +type BaseAuthCredentialsImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseAuthCredentialsImpl) AuthCredentials() BaseAuthCredentialsImpl { + return s +} + +var _ AuthCredentials = RawAuthCredentialsImpl{} + +// RawAuthCredentialsImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAuthCredentialsImpl struct { + authCredentials BaseAuthCredentialsImpl + Type string + Values map[string]interface{} +} + +func (s RawAuthCredentialsImpl) AuthCredentials() BaseAuthCredentialsImpl { + return s.authCredentials +} + +func UnmarshalAuthCredentialsImplementation(input []byte) (AuthCredentials, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AuthCredentials into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "SecretStoreBasedAuthCredentials") { + var out SecretStoreBasedAuthCredentials + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecretStoreBasedAuthCredentials: %+v", err) + } + return out, nil + } + + var parent BaseAuthCredentialsImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseAuthCredentialsImpl: %+v", err) + } + + return RawAuthCredentialsImpl{ + authCredentials: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go new file mode 100644 index 00000000000..137344a6d07 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverypointbasedrestorerequest.go @@ -0,0 +1,98 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRestoreRequest = AzureBackupRecoveryPointBasedRestoreRequest{} + +type AzureBackupRecoveryPointBasedRestoreRequest struct { + RecoveryPointId string `json:"recoveryPointId"` + + // Fields inherited from AzureBackupRestoreRequest + + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +func (s AzureBackupRecoveryPointBasedRestoreRequest) AzureBackupRestoreRequest() BaseAzureBackupRestoreRequestImpl { + return BaseAzureBackupRestoreRequestImpl{ + IdentityDetails: s.IdentityDetails, + ObjectType: s.ObjectType, + ResourceGuardOperationRequests: s.ResourceGuardOperationRequests, + RestoreTargetInfo: s.RestoreTargetInfo, + SourceDataStoreType: s.SourceDataStoreType, + SourceResourceId: s.SourceResourceId, + } +} + +var _ json.Marshaler = AzureBackupRecoveryPointBasedRestoreRequest{} + +func (s AzureBackupRecoveryPointBasedRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRecoveryPointBasedRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + + decoded["objectType"] = "AzureBackupRecoveryPointBasedRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRecoveryPointBasedRestoreRequest{} + +func (s *AzureBackupRecoveryPointBasedRestoreRequest) UnmarshalJSON(bytes []byte) error { + var decoded struct { + RecoveryPointId string `json:"recoveryPointId"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.RecoveryPointId = decoded.RecoveryPointId + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryPointBasedRestoreRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := UnmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'AzureBackupRecoveryPointBasedRestoreRequest': %+v", err) + } + s.RestoreTargetInfo = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go new file mode 100644 index 00000000000..fc6ace67659 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprecoverytimebasedrestorerequest.go @@ -0,0 +1,98 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRestoreRequest = AzureBackupRecoveryTimeBasedRestoreRequest{} + +type AzureBackupRecoveryTimeBasedRestoreRequest struct { + RecoveryPointTime string `json:"recoveryPointTime"` + + // Fields inherited from AzureBackupRestoreRequest + + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +func (s AzureBackupRecoveryTimeBasedRestoreRequest) AzureBackupRestoreRequest() BaseAzureBackupRestoreRequestImpl { + return BaseAzureBackupRestoreRequestImpl{ + IdentityDetails: s.IdentityDetails, + ObjectType: s.ObjectType, + ResourceGuardOperationRequests: s.ResourceGuardOperationRequests, + RestoreTargetInfo: s.RestoreTargetInfo, + SourceDataStoreType: s.SourceDataStoreType, + SourceResourceId: s.SourceResourceId, + } +} + +var _ json.Marshaler = AzureBackupRecoveryTimeBasedRestoreRequest{} + +func (s AzureBackupRecoveryTimeBasedRestoreRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRecoveryTimeBasedRestoreRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + + decoded["objectType"] = "AzureBackupRecoveryTimeBasedRestoreRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRecoveryTimeBasedRestoreRequest{} + +func (s *AzureBackupRecoveryTimeBasedRestoreRequest) UnmarshalJSON(bytes []byte) error { + var decoded struct { + RecoveryPointTime string `json:"recoveryPointTime"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.RecoveryPointTime = decoded.RecoveryPointTime + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryTimeBasedRestoreRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := UnmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'AzureBackupRecoveryTimeBasedRestoreRequest': %+v", err) + } + s.RestoreTargetInfo = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprehydrationrequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprehydrationrequest.go new file mode 100644 index 00000000000..b78ded8adb1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprehydrationrequest.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRehydrationRequest struct { + RecoveryPointId string `json:"recoveryPointId"` + RehydrationPriority *RehydrationPriority `json:"rehydrationPriority,omitempty"` + RehydrationRetentionDuration string `json:"rehydrationRetentionDuration"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorerequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorerequest.go new file mode 100644 index 00000000000..11a759db823 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorerequest.go @@ -0,0 +1,132 @@ +package backupinstances + +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 AzureBackupRestoreRequest interface { + AzureBackupRestoreRequest() BaseAzureBackupRestoreRequestImpl +} + +var _ AzureBackupRestoreRequest = BaseAzureBackupRestoreRequestImpl{} + +type BaseAzureBackupRestoreRequestImpl struct { + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +func (s BaseAzureBackupRestoreRequestImpl) AzureBackupRestoreRequest() BaseAzureBackupRestoreRequestImpl { + return s +} + +var _ AzureBackupRestoreRequest = RawAzureBackupRestoreRequestImpl{} + +// RawAzureBackupRestoreRequestImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAzureBackupRestoreRequestImpl struct { + azureBackupRestoreRequest BaseAzureBackupRestoreRequestImpl + Type string + Values map[string]interface{} +} + +func (s RawAzureBackupRestoreRequestImpl) AzureBackupRestoreRequest() BaseAzureBackupRestoreRequestImpl { + return s.azureBackupRestoreRequest +} + +var _ json.Unmarshaler = &BaseAzureBackupRestoreRequestImpl{} + +func (s *BaseAzureBackupRestoreRequestImpl) UnmarshalJSON(bytes []byte) error { + var decoded struct { + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BaseAzureBackupRestoreRequestImpl into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := UnmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'BaseAzureBackupRestoreRequestImpl': %+v", err) + } + s.RestoreTargetInfo = impl + } + + return nil +} + +func UnmarshalAzureBackupRestoreRequestImplementation(input []byte) (AzureBackupRestoreRequest, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRestoreRequest into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureBackupRecoveryPointBasedRestoreRequest") { + var out AzureBackupRecoveryPointBasedRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRecoveryPointBasedRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureBackupRecoveryTimeBasedRestoreRequest") { + var out AzureBackupRecoveryTimeBasedRestoreRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRecoveryTimeBasedRestoreRequest: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureBackupRestoreWithRehydrationRequest") { + var out AzureBackupRestoreWithRehydrationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + return out, nil + } + + var parent BaseAzureBackupRestoreRequestImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseAzureBackupRestoreRequestImpl: %+v", err) + } + + return RawAzureBackupRestoreRequestImpl{ + azureBackupRestoreRequest: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go new file mode 100644 index 00000000000..0c248836f35 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azurebackuprestorewithrehydrationrequest.go @@ -0,0 +1,104 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRestoreRequest = AzureBackupRestoreWithRehydrationRequest{} + +type AzureBackupRestoreWithRehydrationRequest struct { + RecoveryPointId string `json:"recoveryPointId"` + RehydrationPriority RehydrationPriority `json:"rehydrationPriority"` + RehydrationRetentionDuration string `json:"rehydrationRetentionDuration"` + + // Fields inherited from AzureBackupRestoreRequest + + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + RestoreTargetInfo RestoreTargetInfoBase `json:"restoreTargetInfo"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` +} + +func (s AzureBackupRestoreWithRehydrationRequest) AzureBackupRestoreRequest() BaseAzureBackupRestoreRequestImpl { + return BaseAzureBackupRestoreRequestImpl{ + IdentityDetails: s.IdentityDetails, + ObjectType: s.ObjectType, + ResourceGuardOperationRequests: s.ResourceGuardOperationRequests, + RestoreTargetInfo: s.RestoreTargetInfo, + SourceDataStoreType: s.SourceDataStoreType, + SourceResourceId: s.SourceResourceId, + } +} + +var _ json.Marshaler = AzureBackupRestoreWithRehydrationRequest{} + +func (s AzureBackupRestoreWithRehydrationRequest) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRestoreWithRehydrationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + + decoded["objectType"] = "AzureBackupRestoreWithRehydrationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRestoreWithRehydrationRequest: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRestoreWithRehydrationRequest{} + +func (s *AzureBackupRestoreWithRehydrationRequest) UnmarshalJSON(bytes []byte) error { + var decoded struct { + RecoveryPointId string `json:"recoveryPointId"` + RehydrationPriority RehydrationPriority `json:"rehydrationPriority"` + RehydrationRetentionDuration string `json:"rehydrationRetentionDuration"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SourceDataStoreType SourceDataStoreType `json:"sourceDataStoreType"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.RecoveryPointId = decoded.RecoveryPointId + s.RehydrationPriority = decoded.RehydrationPriority + s.RehydrationRetentionDuration = decoded.RehydrationRetentionDuration + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.SourceDataStoreType = decoded.SourceDataStoreType + s.SourceResourceId = decoded.SourceResourceId + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRestoreWithRehydrationRequest into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreTargetInfo"]; ok { + impl, err := UnmarshalRestoreTargetInfoBaseImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreTargetInfo' for 'AzureBackupRestoreWithRehydrationRequest': %+v", err) + } + s.RestoreTargetInfo = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_azureoperationalstoreparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azureoperationalstoreparameters.go new file mode 100644 index 00000000000..2c2c8c9086a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_azureoperationalstoreparameters.go @@ -0,0 +1,52 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataStoreParameters = AzureOperationalStoreParameters{} + +type AzureOperationalStoreParameters struct { + ResourceGroupId *string `json:"resourceGroupId,omitempty"` + + // Fields inherited from DataStoreParameters + + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} + +func (s AzureOperationalStoreParameters) DataStoreParameters() BaseDataStoreParametersImpl { + return BaseDataStoreParametersImpl{ + DataStoreType: s.DataStoreType, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureOperationalStoreParameters{} + +func (s AzureOperationalStoreParameters) MarshalJSON() ([]byte, error) { + type wrapper AzureOperationalStoreParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureOperationalStoreParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureOperationalStoreParameters: %+v", err) + } + + decoded["objectType"] = "AzureOperationalStoreParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureOperationalStoreParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupdatasourceparameters.go new file mode 100644 index 00000000000..c5515448e33 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupdatasourceparameters.go @@ -0,0 +1,91 @@ +package backupinstances + +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 BackupDatasourceParameters interface { + BackupDatasourceParameters() BaseBackupDatasourceParametersImpl +} + +var _ BackupDatasourceParameters = BaseBackupDatasourceParametersImpl{} + +type BaseBackupDatasourceParametersImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseBackupDatasourceParametersImpl) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return s +} + +var _ BackupDatasourceParameters = RawBackupDatasourceParametersImpl{} + +// RawBackupDatasourceParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupDatasourceParametersImpl struct { + backupDatasourceParameters BaseBackupDatasourceParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawBackupDatasourceParametersImpl) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return s.backupDatasourceParameters +} + +func UnmarshalBackupDatasourceParametersImplementation(input []byte) (BackupDatasourceParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupDatasourceParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AdlsBlobBackupDatasourceParameters") { + var out AdlsBlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AdlsBlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "BlobBackupDatasourceParameters") { + var out BlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterBackupDatasourceParameters") { + var out KubernetesClusterBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + var parent BaseBackupDatasourceParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBackupDatasourceParametersImpl: %+v", err) + } + + return RawBackupDatasourceParametersImpl{ + backupDatasourceParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstance.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstance.go new file mode 100644 index 00000000000..ef05566c527 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstance.go @@ -0,0 +1,75 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstance struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` +} + +var _ json.Unmarshaler = &BackupInstance{} + +func (s *BackupInstance) UnmarshalJSON(bytes []byte) error { + var decoded struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.CurrentProtectionState = decoded.CurrentProtectionState + s.DataSourceInfo = decoded.DataSourceInfo + s.DataSourceSetInfo = decoded.DataSourceSetInfo + s.FriendlyName = decoded.FriendlyName + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.PolicyInfo = decoded.PolicyInfo + s.ProtectionErrorDetails = decoded.ProtectionErrorDetails + s.ProtectionStatus = decoded.ProtectionStatus + s.ProvisioningState = decoded.ProvisioningState + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.ValidationType = decoded.ValidationType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupInstance into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := UnmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'BackupInstance': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstanceresource.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstanceresource.go new file mode 100644 index 00000000000..ca92f651ec6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_backupinstanceresource.go @@ -0,0 +1,17 @@ +package backupinstances + +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 BackupInstanceResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupInstance `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/dataprotection/2025-02-01/backupinstances/model_baseresourceproperties.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_baseresourceproperties.go new file mode 100644 index 00000000000..9ef7d2eef6b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_baseresourceproperties.go @@ -0,0 +1,75 @@ +package backupinstances + +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 BaseResourceProperties interface { + BaseResourceProperties() BaseBaseResourcePropertiesImpl +} + +var _ BaseResourceProperties = BaseBaseResourcePropertiesImpl{} + +type BaseBaseResourcePropertiesImpl struct { + ObjectType ResourcePropertiesObjectType `json:"objectType"` +} + +func (s BaseBaseResourcePropertiesImpl) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return s +} + +var _ BaseResourceProperties = RawBaseResourcePropertiesImpl{} + +// RawBaseResourcePropertiesImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseResourcePropertiesImpl struct { + baseResourceProperties BaseBaseResourcePropertiesImpl + Type string + Values map[string]interface{} +} + +func (s RawBaseResourcePropertiesImpl) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return s.baseResourceProperties +} + +func UnmarshalBaseResourcePropertiesImplementation(input []byte) (BaseResourceProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseResourceProperties into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "DefaultResourceProperties") { + var out DefaultResourceProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DefaultResourceProperties: %+v", err) + } + return out, nil + } + + var parent BaseBaseResourcePropertiesImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBaseResourcePropertiesImpl: %+v", err) + } + + return RawBaseResourcePropertiesImpl{ + baseResourceProperties: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_blobbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_blobbackupdatasourceparameters.go new file mode 100644 index 00000000000..fc701b02154 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_blobbackupdatasourceparameters.go @@ -0,0 +1,50 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = BlobBackupDatasourceParameters{} + +type BlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s BlobBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = BlobBackupDatasourceParameters{} + +func (s BlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper BlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BlobBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "BlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestoredetails.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestoredetails.go new file mode 100644 index 00000000000..edbe7ac454b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestoredetails.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreDetails struct { + SourceBackupInstanceId string `json:"sourceBackupInstanceId"` + SourceRegion string `json:"sourceRegion"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestorerequestobject.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestorerequestobject.go new file mode 100644 index 00000000000..80b4acaaada --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_crossregionrestorerequestobject.go @@ -0,0 +1,42 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreRequestObject struct { + CrossRegionRestoreDetails CrossRegionRestoreDetails `json:"crossRegionRestoreDetails"` + RestoreRequestObject AzureBackupRestoreRequest `json:"restoreRequestObject"` +} + +var _ json.Unmarshaler = &CrossRegionRestoreRequestObject{} + +func (s *CrossRegionRestoreRequestObject) UnmarshalJSON(bytes []byte) error { + var decoded struct { + CrossRegionRestoreDetails CrossRegionRestoreDetails `json:"crossRegionRestoreDetails"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.CrossRegionRestoreDetails = decoded.CrossRegionRestoreDetails + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling CrossRegionRestoreRequestObject into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequestObject"]; ok { + impl, err := UnmarshalAzureBackupRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequestObject' for 'CrossRegionRestoreRequestObject': %+v", err) + } + s.RestoreRequestObject = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_datasource.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_datasource.go new file mode 100644 index 00000000000..f346089941e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_datasource.go @@ -0,0 +1,60 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Datasource struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &Datasource{} + +func (s *Datasource) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Datasource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := UnmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'Datasource': %+v", err) + } + s.ResourceProperties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_datasourceset.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_datasourceset.go new file mode 100644 index 00000000000..0c88066e275 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_datasourceset.go @@ -0,0 +1,60 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatasourceSet struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &DatasourceSet{} + +func (s *DatasourceSet) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DatasourceSet into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := UnmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'DatasourceSet': %+v", err) + } + s.ResourceProperties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_datastoreparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_datastoreparameters.go new file mode 100644 index 00000000000..c1d859acd97 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_datastoreparameters.go @@ -0,0 +1,76 @@ +package backupinstances + +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 DataStoreParameters interface { + DataStoreParameters() BaseDataStoreParametersImpl +} + +var _ DataStoreParameters = BaseDataStoreParametersImpl{} + +type BaseDataStoreParametersImpl struct { + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} + +func (s BaseDataStoreParametersImpl) DataStoreParameters() BaseDataStoreParametersImpl { + return s +} + +var _ DataStoreParameters = RawDataStoreParametersImpl{} + +// RawDataStoreParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDataStoreParametersImpl struct { + dataStoreParameters BaseDataStoreParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawDataStoreParametersImpl) DataStoreParameters() BaseDataStoreParametersImpl { + return s.dataStoreParameters +} + +func UnmarshalDataStoreParametersImplementation(input []byte) (DataStoreParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DataStoreParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureOperationalStoreParameters") { + var out AzureOperationalStoreParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureOperationalStoreParameters: %+v", err) + } + return out, nil + } + + var parent BaseDataStoreParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseDataStoreParametersImpl: %+v", err) + } + + return RawDataStoreParametersImpl{ + dataStoreParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_defaultresourceproperties.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_defaultresourceproperties.go new file mode 100644 index 00000000000..6de216a9daa --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_defaultresourceproperties.go @@ -0,0 +1,49 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseResourceProperties = DefaultResourceProperties{} + +type DefaultResourceProperties struct { + + // Fields inherited from BaseResourceProperties + + ObjectType ResourcePropertiesObjectType `json:"objectType"` +} + +func (s DefaultResourceProperties) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return BaseBaseResourcePropertiesImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = DefaultResourceProperties{} + +func (s DefaultResourceProperties) MarshalJSON() ([]byte, error) { + type wrapper DefaultResourceProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DefaultResourceProperties: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DefaultResourceProperties: %+v", err) + } + + decoded["objectType"] = "DefaultResourceProperties" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DefaultResourceProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_identitydetails.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_identitydetails.go new file mode 100644 index 00000000000..0b2cd743ef3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_identitydetails.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityDetails struct { + UseSystemAssignedIdentity *bool `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentityArmURL *string `json:"userAssignedIdentityArmUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_innererror.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_innererror.go new file mode 100644 index 00000000000..15fc997eebd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_innererror.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestorecriteria.go new file mode 100644 index 00000000000..2431e735e7d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestorecriteria.go @@ -0,0 +1,115 @@ +package backupinstances + +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 ItemLevelRestoreCriteria interface { + ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl +} + +var _ ItemLevelRestoreCriteria = BaseItemLevelRestoreCriteriaImpl{} + +type BaseItemLevelRestoreCriteriaImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseItemLevelRestoreCriteriaImpl) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return s +} + +var _ ItemLevelRestoreCriteria = RawItemLevelRestoreCriteriaImpl{} + +// RawItemLevelRestoreCriteriaImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawItemLevelRestoreCriteriaImpl struct { + itemLevelRestoreCriteria BaseItemLevelRestoreCriteriaImpl + Type string + Values map[string]interface{} +} + +func (s RawItemLevelRestoreCriteriaImpl) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return s.itemLevelRestoreCriteria +} + +func UnmarshalItemLevelRestoreCriteriaImplementation(input []byte) (ItemLevelRestoreCriteria, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling ItemLevelRestoreCriteria into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "ItemPathBasedRestoreCriteria") { + var out ItemPathBasedRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ItemPathBasedRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterRestoreCriteria") { + var out KubernetesClusterRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterVaultTierRestoreCriteria") { + var out KubernetesClusterVaultTierRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesPVRestoreCriteria") { + var out KubernetesPVRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesPVRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesStorageClassRestoreCriteria") { + var out KubernetesStorageClassRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesStorageClassRestoreCriteria: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RangeBasedItemLevelRestoreCriteria") { + var out RangeBasedItemLevelRestoreCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RangeBasedItemLevelRestoreCriteria: %+v", err) + } + return out, nil + } + + var parent BaseItemLevelRestoreCriteriaImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseItemLevelRestoreCriteriaImpl: %+v", err) + } + + return RawItemLevelRestoreCriteriaImpl{ + itemLevelRestoreCriteria: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestoretargetinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestoretargetinfo.go new file mode 100644 index 00000000000..605e75155bb --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_itemlevelrestoretargetinfo.go @@ -0,0 +1,110 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreTargetInfoBase = ItemLevelRestoreTargetInfo{} + +type ItemLevelRestoreTargetInfo struct { + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + DatasourceInfo Datasource `json:"datasourceInfo"` + DatasourceSetInfo *DatasourceSet `json:"datasourceSetInfo,omitempty"` + RestoreCriteria []ItemLevelRestoreCriteria `json:"restoreCriteria"` + + // Fields inherited from RestoreTargetInfoBase + + ObjectType string `json:"objectType"` + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +func (s ItemLevelRestoreTargetInfo) RestoreTargetInfoBase() BaseRestoreTargetInfoBaseImpl { + return BaseRestoreTargetInfoBaseImpl{ + ObjectType: s.ObjectType, + RecoveryOption: s.RecoveryOption, + RestoreLocation: s.RestoreLocation, + } +} + +var _ json.Marshaler = ItemLevelRestoreTargetInfo{} + +func (s ItemLevelRestoreTargetInfo) MarshalJSON() ([]byte, error) { + type wrapper ItemLevelRestoreTargetInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ItemLevelRestoreTargetInfo: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ItemLevelRestoreTargetInfo: %+v", err) + } + + decoded["objectType"] = "ItemLevelRestoreTargetInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ItemLevelRestoreTargetInfo: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &ItemLevelRestoreTargetInfo{} + +func (s *ItemLevelRestoreTargetInfo) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceInfo Datasource `json:"datasourceInfo"` + DatasourceSetInfo *DatasourceSet `json:"datasourceSetInfo,omitempty"` + ObjectType string `json:"objectType"` + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceInfo = decoded.DatasourceInfo + s.DatasourceSetInfo = decoded.DatasourceSetInfo + s.ObjectType = decoded.ObjectType + s.RecoveryOption = decoded.RecoveryOption + s.RestoreLocation = decoded.RestoreLocation + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ItemLevelRestoreTargetInfo into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := UnmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'ItemLevelRestoreTargetInfo': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + + if v, ok := temp["restoreCriteria"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling RestoreCriteria into list []json.RawMessage: %+v", err) + } + + output := make([]ItemLevelRestoreCriteria, 0) + for i, val := range listTemp { + impl, err := UnmarshalItemLevelRestoreCriteriaImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'RestoreCriteria' for 'ItemLevelRestoreTargetInfo': %+v", i, err) + } + output = append(output, impl) + } + s.RestoreCriteria = output + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_itempathbasedrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_itempathbasedrestorecriteria.go new file mode 100644 index 00000000000..293c8227b06 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_itempathbasedrestorecriteria.go @@ -0,0 +1,52 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = ItemPathBasedRestoreCriteria{} + +type ItemPathBasedRestoreCriteria struct { + IsPathRelativeToBackupItem bool `json:"isPathRelativeToBackupItem"` + ItemPath string `json:"itemPath"` + SubItemPathPrefix *[]string `json:"subItemPathPrefix,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria + + ObjectType string `json:"objectType"` +} + +func (s ItemPathBasedRestoreCriteria) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return BaseItemLevelRestoreCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = ItemPathBasedRestoreCriteria{} + +func (s ItemPathBasedRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper ItemPathBasedRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ItemPathBasedRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ItemPathBasedRestoreCriteria: %+v", err) + } + + decoded["objectType"] = "ItemPathBasedRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ItemPathBasedRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go new file mode 100644 index 00000000000..dfefb95f817 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterbackupdatasourceparameters.go @@ -0,0 +1,58 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = KubernetesClusterBackupDatasourceParameters{} + +type KubernetesClusterBackupDatasourceParameters struct { + BackupHookReferences *[]NamespacedNameResource `json:"backupHookReferences,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + IncludedVolumeTypes *[]AKSVolumeTypes `json:"includedVolumeTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + SnapshotVolumes bool `json:"snapshotVolumes"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s KubernetesClusterBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesClusterBackupDatasourceParameters{} + +func (s KubernetesClusterBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "KubernetesClusterBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterrestorecriteria.go new file mode 100644 index 00000000000..c39f21cf7df --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclusterrestorecriteria.go @@ -0,0 +1,60 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesClusterRestoreCriteria{} + +type KubernetesClusterRestoreCriteria struct { + ConflictPolicy *ExistingResourcePolicy `json:"conflictPolicy,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + NamespaceMappings *map[string]string `json:"namespaceMappings,omitempty"` + PersistentVolumeRestoreMode *PersistentVolumeRestoreMode `json:"persistentVolumeRestoreMode,omitempty"` + ResourceModifierReference *NamespacedNameResource `json:"resourceModifierReference,omitempty"` + RestoreHookReferences *[]NamespacedNameResource `json:"restoreHookReferences,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria + + ObjectType string `json:"objectType"` +} + +func (s KubernetesClusterRestoreCriteria) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return BaseItemLevelRestoreCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesClusterRestoreCriteria{} + +func (s KubernetesClusterRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterRestoreCriteria: %+v", err) + } + + decoded["objectType"] = "KubernetesClusterRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go new file mode 100644 index 00000000000..b192cf49ac8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesclustervaulttierrestorecriteria.go @@ -0,0 +1,62 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesClusterVaultTierRestoreCriteria{} + +type KubernetesClusterVaultTierRestoreCriteria struct { + ConflictPolicy *ExistingResourcePolicy `json:"conflictPolicy,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + NamespaceMappings *map[string]string `json:"namespaceMappings,omitempty"` + PersistentVolumeRestoreMode *PersistentVolumeRestoreMode `json:"persistentVolumeRestoreMode,omitempty"` + ResourceModifierReference *NamespacedNameResource `json:"resourceModifierReference,omitempty"` + RestoreHookReferences *[]NamespacedNameResource `json:"restoreHookReferences,omitempty"` + StagingResourceGroupId *string `json:"stagingResourceGroupId,omitempty"` + StagingStorageAccountId *string `json:"stagingStorageAccountId,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria + + ObjectType string `json:"objectType"` +} + +func (s KubernetesClusterVaultTierRestoreCriteria) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return BaseItemLevelRestoreCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesClusterVaultTierRestoreCriteria{} + +func (s KubernetesClusterVaultTierRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterVaultTierRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + + decoded["objectType"] = "KubernetesClusterVaultTierRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterVaultTierRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetespvrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetespvrestorecriteria.go new file mode 100644 index 00000000000..4a0189b1de3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetespvrestorecriteria.go @@ -0,0 +1,51 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesPVRestoreCriteria{} + +type KubernetesPVRestoreCriteria struct { + Name *string `json:"name,omitempty"` + StorageClassName *string `json:"storageClassName,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria + + ObjectType string `json:"objectType"` +} + +func (s KubernetesPVRestoreCriteria) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return BaseItemLevelRestoreCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesPVRestoreCriteria{} + +func (s KubernetesPVRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesPVRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesPVRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesPVRestoreCriteria: %+v", err) + } + + decoded["objectType"] = "KubernetesPVRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesPVRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go new file mode 100644 index 00000000000..a1f6748502f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_kubernetesstorageclassrestorecriteria.go @@ -0,0 +1,51 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = KubernetesStorageClassRestoreCriteria{} + +type KubernetesStorageClassRestoreCriteria struct { + Provisioner *string `json:"provisioner,omitempty"` + SelectedStorageClassName *string `json:"selectedStorageClassName,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria + + ObjectType string `json:"objectType"` +} + +func (s KubernetesStorageClassRestoreCriteria) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return BaseItemLevelRestoreCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesStorageClassRestoreCriteria{} + +func (s KubernetesStorageClassRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper KubernetesStorageClassRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesStorageClassRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesStorageClassRestoreCriteria: %+v", err) + } + + decoded["objectType"] = "KubernetesStorageClassRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesStorageClassRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_namespacednameresource.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_namespacednameresource.go new file mode 100644 index 00000000000..f0c6e7a847c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_namespacednameresource.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespacedNameResource struct { + Name *string `json:"name,omitempty"` + Namespace *string `json:"namespace,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_operationextendedinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_operationextendedinfo.go new file mode 100644 index 00000000000..f32c9b06c65 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_operationextendedinfo.go @@ -0,0 +1,75 @@ +package backupinstances + +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 OperationExtendedInfo interface { + OperationExtendedInfo() BaseOperationExtendedInfoImpl +} + +var _ OperationExtendedInfo = BaseOperationExtendedInfoImpl{} + +type BaseOperationExtendedInfoImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseOperationExtendedInfoImpl) OperationExtendedInfo() BaseOperationExtendedInfoImpl { + return s +} + +var _ OperationExtendedInfo = RawOperationExtendedInfoImpl{} + +// RawOperationExtendedInfoImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawOperationExtendedInfoImpl struct { + operationExtendedInfo BaseOperationExtendedInfoImpl + Type string + Values map[string]interface{} +} + +func (s RawOperationExtendedInfoImpl) OperationExtendedInfo() BaseOperationExtendedInfoImpl { + return s.operationExtendedInfo +} + +func UnmarshalOperationExtendedInfoImplementation(input []byte) (OperationExtendedInfo, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling OperationExtendedInfo into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "OperationJobExtendedInfo") { + var out OperationJobExtendedInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OperationJobExtendedInfo: %+v", err) + } + return out, nil + } + + var parent BaseOperationExtendedInfoImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseOperationExtendedInfoImpl: %+v", err) + } + + return RawOperationExtendedInfoImpl{ + operationExtendedInfo: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_operationjobextendedinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_operationjobextendedinfo.go new file mode 100644 index 00000000000..c0ead370cf2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_operationjobextendedinfo.go @@ -0,0 +1,50 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ OperationExtendedInfo = OperationJobExtendedInfo{} + +type OperationJobExtendedInfo struct { + JobId *string `json:"jobId,omitempty"` + + // Fields inherited from OperationExtendedInfo + + ObjectType string `json:"objectType"` +} + +func (s OperationJobExtendedInfo) OperationExtendedInfo() BaseOperationExtendedInfoImpl { + return BaseOperationExtendedInfoImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = OperationJobExtendedInfo{} + +func (s OperationJobExtendedInfo) MarshalJSON() ([]byte, error) { + type wrapper OperationJobExtendedInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OperationJobExtendedInfo: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OperationJobExtendedInfo: %+v", err) + } + + decoded["objectType"] = "OperationJobExtendedInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OperationJobExtendedInfo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_policyinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_policyinfo.go new file mode 100644 index 00000000000..41646c6341d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_policyinfo.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyInfo struct { + PolicyId string `json:"policyId"` + PolicyParameters *PolicyParameters `json:"policyParameters,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_policyparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_policyparameters.go new file mode 100644 index 00000000000..482f3acf639 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_policyparameters.go @@ -0,0 +1,60 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyParameters struct { + BackupDatasourceParametersList *[]BackupDatasourceParameters `json:"backupDatasourceParametersList,omitempty"` + DataStoreParametersList *[]DataStoreParameters `json:"dataStoreParametersList,omitempty"` +} + +var _ json.Unmarshaler = &PolicyParameters{} + +func (s *PolicyParameters) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PolicyParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupDatasourceParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling BackupDatasourceParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]BackupDatasourceParameters, 0) + for i, val := range listTemp { + impl, err := UnmarshalBackupDatasourceParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'BackupDatasourceParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.BackupDatasourceParametersList = &output + } + + if v, ok := temp["dataStoreParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DataStoreParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]DataStoreParameters, 0) + for i, val := range listTemp { + impl, err := UnmarshalDataStoreParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DataStoreParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.DataStoreParametersList = &output + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_protectionstatusdetails.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_protectionstatusdetails.go new file mode 100644 index 00000000000..47607ca70da --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_protectionstatusdetails.go @@ -0,0 +1,9 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionStatusDetails struct { + ErrorDetails *UserFacingError `json:"errorDetails,omitempty"` + Status *Status `json:"status,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go new file mode 100644 index 00000000000..365518530ec --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_rangebaseditemlevelrestorecriteria.go @@ -0,0 +1,51 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ItemLevelRestoreCriteria = RangeBasedItemLevelRestoreCriteria{} + +type RangeBasedItemLevelRestoreCriteria struct { + MaxMatchingValue *string `json:"maxMatchingValue,omitempty"` + MinMatchingValue *string `json:"minMatchingValue,omitempty"` + + // Fields inherited from ItemLevelRestoreCriteria + + ObjectType string `json:"objectType"` +} + +func (s RangeBasedItemLevelRestoreCriteria) ItemLevelRestoreCriteria() BaseItemLevelRestoreCriteriaImpl { + return BaseItemLevelRestoreCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = RangeBasedItemLevelRestoreCriteria{} + +func (s RangeBasedItemLevelRestoreCriteria) MarshalJSON() ([]byte, error) { + type wrapper RangeBasedItemLevelRestoreCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RangeBasedItemLevelRestoreCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RangeBasedItemLevelRestoreCriteria: %+v", err) + } + + decoded["objectType"] = "RangeBasedItemLevelRestoreCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RangeBasedItemLevelRestoreCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_restorefilestargetinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_restorefilestargetinfo.go new file mode 100644 index 00000000000..b5cf6722012 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_restorefilestargetinfo.go @@ -0,0 +1,54 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreTargetInfoBase = RestoreFilesTargetInfo{} + +type RestoreFilesTargetInfo struct { + TargetDetails TargetDetails `json:"targetDetails"` + + // Fields inherited from RestoreTargetInfoBase + + ObjectType string `json:"objectType"` + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +func (s RestoreFilesTargetInfo) RestoreTargetInfoBase() BaseRestoreTargetInfoBaseImpl { + return BaseRestoreTargetInfoBaseImpl{ + ObjectType: s.ObjectType, + RecoveryOption: s.RecoveryOption, + RestoreLocation: s.RestoreLocation, + } +} + +var _ json.Marshaler = RestoreFilesTargetInfo{} + +func (s RestoreFilesTargetInfo) MarshalJSON() ([]byte, error) { + type wrapper RestoreFilesTargetInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RestoreFilesTargetInfo: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RestoreFilesTargetInfo: %+v", err) + } + + decoded["objectType"] = "RestoreFilesTargetInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RestoreFilesTargetInfo: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfo.go new file mode 100644 index 00000000000..c2c0ef5a915 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfo.go @@ -0,0 +1,92 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ RestoreTargetInfoBase = RestoreTargetInfo{} + +type RestoreTargetInfo struct { + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + DatasourceInfo Datasource `json:"datasourceInfo"` + DatasourceSetInfo *DatasourceSet `json:"datasourceSetInfo,omitempty"` + + // Fields inherited from RestoreTargetInfoBase + + ObjectType string `json:"objectType"` + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +func (s RestoreTargetInfo) RestoreTargetInfoBase() BaseRestoreTargetInfoBaseImpl { + return BaseRestoreTargetInfoBaseImpl{ + ObjectType: s.ObjectType, + RecoveryOption: s.RecoveryOption, + RestoreLocation: s.RestoreLocation, + } +} + +var _ json.Marshaler = RestoreTargetInfo{} + +func (s RestoreTargetInfo) MarshalJSON() ([]byte, error) { + type wrapper RestoreTargetInfo + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RestoreTargetInfo: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RestoreTargetInfo: %+v", err) + } + + decoded["objectType"] = "RestoreTargetInfo" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RestoreTargetInfo: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &RestoreTargetInfo{} + +func (s *RestoreTargetInfo) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceInfo Datasource `json:"datasourceInfo"` + DatasourceSetInfo *DatasourceSet `json:"datasourceSetInfo,omitempty"` + ObjectType string `json:"objectType"` + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceInfo = decoded.DatasourceInfo + s.DatasourceSetInfo = decoded.DatasourceSetInfo + s.ObjectType = decoded.ObjectType + s.RecoveryOption = decoded.RecoveryOption + s.RestoreLocation = decoded.RestoreLocation + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling RestoreTargetInfo into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := UnmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'RestoreTargetInfo': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfobase.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfobase.go new file mode 100644 index 00000000000..0c38bd0a723 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_restoretargetinfobase.go @@ -0,0 +1,93 @@ +package backupinstances + +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 RestoreTargetInfoBase interface { + RestoreTargetInfoBase() BaseRestoreTargetInfoBaseImpl +} + +var _ RestoreTargetInfoBase = BaseRestoreTargetInfoBaseImpl{} + +type BaseRestoreTargetInfoBaseImpl struct { + ObjectType string `json:"objectType"` + RecoveryOption RecoveryOption `json:"recoveryOption"` + RestoreLocation *string `json:"restoreLocation,omitempty"` +} + +func (s BaseRestoreTargetInfoBaseImpl) RestoreTargetInfoBase() BaseRestoreTargetInfoBaseImpl { + return s +} + +var _ RestoreTargetInfoBase = RawRestoreTargetInfoBaseImpl{} + +// RawRestoreTargetInfoBaseImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawRestoreTargetInfoBaseImpl struct { + restoreTargetInfoBase BaseRestoreTargetInfoBaseImpl + Type string + Values map[string]interface{} +} + +func (s RawRestoreTargetInfoBaseImpl) RestoreTargetInfoBase() BaseRestoreTargetInfoBaseImpl { + return s.restoreTargetInfoBase +} + +func UnmarshalRestoreTargetInfoBaseImplementation(input []byte) (RestoreTargetInfoBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling RestoreTargetInfoBase into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "ItemLevelRestoreTargetInfo") { + var out ItemLevelRestoreTargetInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ItemLevelRestoreTargetInfo: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RestoreFilesTargetInfo") { + var out RestoreFilesTargetInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RestoreFilesTargetInfo: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RestoreTargetInfo") { + var out RestoreTargetInfo + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RestoreTargetInfo: %+v", err) + } + return out, nil + } + + var parent BaseRestoreTargetInfoBaseImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseRestoreTargetInfoBaseImpl: %+v", err) + } + + return RawRestoreTargetInfoBaseImpl{ + restoreTargetInfoBase: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstorebasedauthcredentials.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstorebasedauthcredentials.go new file mode 100644 index 00000000000..859bcef3249 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstorebasedauthcredentials.go @@ -0,0 +1,50 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AuthCredentials = SecretStoreBasedAuthCredentials{} + +type SecretStoreBasedAuthCredentials struct { + SecretStoreResource *SecretStoreResource `json:"secretStoreResource,omitempty"` + + // Fields inherited from AuthCredentials + + ObjectType string `json:"objectType"` +} + +func (s SecretStoreBasedAuthCredentials) AuthCredentials() BaseAuthCredentialsImpl { + return BaseAuthCredentialsImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = SecretStoreBasedAuthCredentials{} + +func (s SecretStoreBasedAuthCredentials) MarshalJSON() ([]byte, error) { + type wrapper SecretStoreBasedAuthCredentials + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + decoded["objectType"] = "SecretStoreBasedAuthCredentials" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstoreresource.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstoreresource.go new file mode 100644 index 00000000000..ee1d6fb0bd9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_secretstoreresource.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretStoreResource struct { + SecretStoreType SecretStoreType `json:"secretStoreType"` + Uri *string `json:"uri,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_stopprotectionrequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_stopprotectionrequest.go new file mode 100644 index 00000000000..f435ab8a767 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_stopprotectionrequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StopProtectionRequest struct { + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_suspendbackuprequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_suspendbackuprequest.go new file mode 100644 index 00000000000..c4234efa63b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_suspendbackuprequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SuspendBackupRequest struct { + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_syncbackupinstancerequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_syncbackupinstancerequest.go new file mode 100644 index 00000000000..ce2412fb5e5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_syncbackupinstancerequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncBackupInstanceRequest struct { + SyncType *SyncType `json:"syncType,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_targetdetails.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_targetdetails.go new file mode 100644 index 00000000000..321cf422bff --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_targetdetails.go @@ -0,0 +1,11 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetDetails struct { + FilePrefix string `json:"filePrefix"` + RestoreTargetLocationType RestoreTargetLocationType `json:"restoreTargetLocationType"` + TargetResourceArmId *string `json:"targetResourceArmId,omitempty"` + Url string `json:"url"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_triggerbackuprequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_triggerbackuprequest.go new file mode 100644 index 00000000000..ffe844c6e4a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_triggerbackuprequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TriggerBackupRequest struct { + BackupRuleOptions AdHocBackupRuleOptions `json:"backupRuleOptions"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_userfacingerror.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_userfacingerror.go new file mode 100644 index 00000000000..e3afc757301 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_userfacingerror.go @@ -0,0 +1,16 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_validatecrossregionrestorerequestobject.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validatecrossregionrestorerequestobject.go new file mode 100644 index 00000000000..96030bc1a54 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validatecrossregionrestorerequestobject.go @@ -0,0 +1,42 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateCrossRegionRestoreRequestObject struct { + CrossRegionRestoreDetails CrossRegionRestoreDetails `json:"crossRegionRestoreDetails"` + RestoreRequestObject AzureBackupRestoreRequest `json:"restoreRequestObject"` +} + +var _ json.Unmarshaler = &ValidateCrossRegionRestoreRequestObject{} + +func (s *ValidateCrossRegionRestoreRequestObject) UnmarshalJSON(bytes []byte) error { + var decoded struct { + CrossRegionRestoreDetails CrossRegionRestoreDetails `json:"crossRegionRestoreDetails"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.CrossRegionRestoreDetails = decoded.CrossRegionRestoreDetails + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateCrossRegionRestoreRequestObject into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequestObject"]; ok { + impl, err := UnmarshalAzureBackupRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequestObject' for 'ValidateCrossRegionRestoreRequestObject': %+v", err) + } + s.RestoreRequestObject = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_validateforbackuprequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validateforbackuprequest.go new file mode 100644 index 00000000000..92af8c34ee0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validateforbackuprequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateForBackupRequest struct { + BackupInstance BackupInstance `json:"backupInstance"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_validateformodifybackuprequest.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validateformodifybackuprequest.go new file mode 100644 index 00000000000..97ca658e7a4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validateformodifybackuprequest.go @@ -0,0 +1,8 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateForModifyBackupRequest struct { + BackupInstance BackupInstance `json:"backupInstance"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/model_validaterestorerequestobject.go b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validaterestorerequestobject.go new file mode 100644 index 00000000000..5a475fbdb0d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/model_validaterestorerequestobject.go @@ -0,0 +1,33 @@ +package backupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateRestoreRequestObject struct { + RestoreRequestObject AzureBackupRestoreRequest `json:"restoreRequestObject"` +} + +var _ json.Unmarshaler = &ValidateRestoreRequestObject{} + +func (s *ValidateRestoreRequestObject) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling ValidateRestoreRequestObject into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["restoreRequestObject"]; ok { + impl, err := UnmarshalAzureBackupRestoreRequestImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'RestoreRequestObject' for 'ValidateRestoreRequestObject': %+v", err) + } + s.RestoreRequestObject = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstances/predicates.go b/resource-manager/dataprotection/2025-02-01/backupinstances/predicates.go new file mode 100644 index 00000000000..c734a2fe8ca --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/predicates.go @@ -0,0 +1,27 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstanceResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BackupInstanceResourceOperationPredicate) Matches(input BackupInstanceResource) 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/dataprotection/2025-02-01/backupinstances/version.go b/resource-manager/dataprotection/2025-02-01/backupinstances/version.go new file mode 100644 index 00000000000..a2f7e870dfa --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstances/version.go @@ -0,0 +1,10 @@ +package backupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/backupinstances/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/README.md b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/README.md new file mode 100644 index 00000000000..52e1d250ce0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting` Documentation + +The `backupinstancesextensionrouting` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting" +``` + + +### Client Initialization + +```go +client := backupinstancesextensionrouting.NewBackupInstancesExtensionRoutingClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupInstancesExtensionRoutingClient.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 +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/client.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/client.go new file mode 100644 index 00000000000..fa5061f45f5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/client.go @@ -0,0 +1,26 @@ +package backupinstancesextensionrouting + +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 BackupInstancesExtensionRoutingClient struct { + Client *resourcemanager.Client +} + +func NewBackupInstancesExtensionRoutingClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupInstancesExtensionRoutingClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "backupinstancesextensionrouting", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupInstancesExtensionRoutingClient: %+v", err) + } + + return &BackupInstancesExtensionRoutingClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/constants.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/constants.go new file mode 100644 index 00000000000..0bad79a5d1d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/constants.go @@ -0,0 +1,339 @@ +package backupinstancesextensionrouting + +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 AKSVolumeTypes string + +const ( + AKSVolumeTypesAzureDisk AKSVolumeTypes = "AzureDisk" + AKSVolumeTypesAzureFileShareSMB AKSVolumeTypes = "AzureFileShareSMB" +) + +func PossibleValuesForAKSVolumeTypes() []string { + return []string{ + string(AKSVolumeTypesAzureDisk), + string(AKSVolumeTypesAzureFileShareSMB), + } +} + +func (s *AKSVolumeTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAKSVolumeTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAKSVolumeTypes(input string) (*AKSVolumeTypes, error) { + vals := map[string]AKSVolumeTypes{ + "azuredisk": AKSVolumeTypesAzureDisk, + "azurefilesharesmb": AKSVolumeTypesAzureFileShareSMB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AKSVolumeTypes(input) + return &out, nil +} + +type CurrentProtectionState string + +const ( + CurrentProtectionStateBackupSchedulesSuspended CurrentProtectionState = "BackupSchedulesSuspended" + CurrentProtectionStateConfiguringProtection CurrentProtectionState = "ConfiguringProtection" + CurrentProtectionStateConfiguringProtectionFailed CurrentProtectionState = "ConfiguringProtectionFailed" + CurrentProtectionStateInvalid CurrentProtectionState = "Invalid" + CurrentProtectionStateNotProtected CurrentProtectionState = "NotProtected" + CurrentProtectionStateProtectionConfigured CurrentProtectionState = "ProtectionConfigured" + CurrentProtectionStateProtectionError CurrentProtectionState = "ProtectionError" + CurrentProtectionStateProtectionStopped CurrentProtectionState = "ProtectionStopped" + CurrentProtectionStateRetentionSchedulesSuspended CurrentProtectionState = "RetentionSchedulesSuspended" + CurrentProtectionStateSoftDeleted CurrentProtectionState = "SoftDeleted" + CurrentProtectionStateSoftDeleting CurrentProtectionState = "SoftDeleting" + CurrentProtectionStateUpdatingProtection CurrentProtectionState = "UpdatingProtection" +) + +func PossibleValuesForCurrentProtectionState() []string { + return []string{ + string(CurrentProtectionStateBackupSchedulesSuspended), + string(CurrentProtectionStateConfiguringProtection), + string(CurrentProtectionStateConfiguringProtectionFailed), + string(CurrentProtectionStateInvalid), + string(CurrentProtectionStateNotProtected), + string(CurrentProtectionStateProtectionConfigured), + string(CurrentProtectionStateProtectionError), + string(CurrentProtectionStateProtectionStopped), + string(CurrentProtectionStateRetentionSchedulesSuspended), + string(CurrentProtectionStateSoftDeleted), + string(CurrentProtectionStateSoftDeleting), + string(CurrentProtectionStateUpdatingProtection), + } +} + +func (s *CurrentProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCurrentProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCurrentProtectionState(input string) (*CurrentProtectionState, error) { + vals := map[string]CurrentProtectionState{ + "backupschedulessuspended": CurrentProtectionStateBackupSchedulesSuspended, + "configuringprotection": CurrentProtectionStateConfiguringProtection, + "configuringprotectionfailed": CurrentProtectionStateConfiguringProtectionFailed, + "invalid": CurrentProtectionStateInvalid, + "notprotected": CurrentProtectionStateNotProtected, + "protectionconfigured": CurrentProtectionStateProtectionConfigured, + "protectionerror": CurrentProtectionStateProtectionError, + "protectionstopped": CurrentProtectionStateProtectionStopped, + "retentionschedulessuspended": CurrentProtectionStateRetentionSchedulesSuspended, + "softdeleted": CurrentProtectionStateSoftDeleted, + "softdeleting": CurrentProtectionStateSoftDeleting, + "updatingprotection": CurrentProtectionStateUpdatingProtection, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CurrentProtectionState(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +type ResourcePropertiesObjectType string + +const ( + ResourcePropertiesObjectTypeDefaultResourceProperties ResourcePropertiesObjectType = "DefaultResourceProperties" +) + +func PossibleValuesForResourcePropertiesObjectType() []string { + return []string{ + string(ResourcePropertiesObjectTypeDefaultResourceProperties), + } +} + +func (s *ResourcePropertiesObjectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourcePropertiesObjectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourcePropertiesObjectType(input string) (*ResourcePropertiesObjectType, error) { + vals := map[string]ResourcePropertiesObjectType{ + "defaultresourceproperties": ResourcePropertiesObjectTypeDefaultResourceProperties, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourcePropertiesObjectType(input) + return &out, nil +} + +type SecretStoreType string + +const ( + SecretStoreTypeAzureKeyVault SecretStoreType = "AzureKeyVault" + SecretStoreTypeInvalid SecretStoreType = "Invalid" +) + +func PossibleValuesForSecretStoreType() []string { + return []string{ + string(SecretStoreTypeAzureKeyVault), + string(SecretStoreTypeInvalid), + } +} + +func (s *SecretStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretStoreType(input string) (*SecretStoreType, error) { + vals := map[string]SecretStoreType{ + "azurekeyvault": SecretStoreTypeAzureKeyVault, + "invalid": SecretStoreTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretStoreType(input) + return &out, nil +} + +type Status string + +const ( + StatusConfiguringProtection Status = "ConfiguringProtection" + StatusConfiguringProtectionFailed Status = "ConfiguringProtectionFailed" + StatusProtectionConfigured Status = "ProtectionConfigured" + StatusProtectionStopped Status = "ProtectionStopped" + StatusSoftDeleted Status = "SoftDeleted" + StatusSoftDeleting Status = "SoftDeleting" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConfiguringProtection), + string(StatusConfiguringProtectionFailed), + string(StatusProtectionConfigured), + string(StatusProtectionStopped), + string(StatusSoftDeleted), + string(StatusSoftDeleting), + } +} + +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{ + "configuringprotection": StatusConfiguringProtection, + "configuringprotectionfailed": StatusConfiguringProtectionFailed, + "protectionconfigured": StatusProtectionConfigured, + "protectionstopped": StatusProtectionStopped, + "softdeleted": StatusSoftDeleted, + "softdeleting": StatusSoftDeleting, + } + 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 ValidationType string + +const ( + ValidationTypeDeepValidation ValidationType = "DeepValidation" + ValidationTypeShallowValidation ValidationType = "ShallowValidation" +) + +func PossibleValuesForValidationType() []string { + return []string{ + string(ValidationTypeDeepValidation), + string(ValidationTypeShallowValidation), + } +} + +func (s *ValidationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseValidationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseValidationType(input string) (*ValidationType, error) { + vals := map[string]ValidationType{ + "deepvalidation": ValidationTypeDeepValidation, + "shallowvalidation": ValidationTypeShallowValidation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/method_list.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/method_list.go new file mode 100644 index 00000000000..09b417b5ae5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/method_list.go @@ -0,0 +1,106 @@ +package backupinstancesextensionrouting + +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 *[]BackupInstanceResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackupInstanceResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c BackupInstancesExtensionRoutingClient) 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, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/backupInstances", 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 *[]BackupInstanceResource `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 BackupInstancesExtensionRoutingClient) ListComplete(ctx context.Context, id commonids.ScopeId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BackupInstanceResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupInstancesExtensionRoutingClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate BackupInstanceResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]BackupInstanceResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_adlsblobbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_adlsblobbackupdatasourceparameters.go new file mode 100644 index 00000000000..e472fd00ed6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_adlsblobbackupdatasourceparameters.go @@ -0,0 +1,50 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = AdlsBlobBackupDatasourceParameters{} + +type AdlsBlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s AdlsBlobBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AdlsBlobBackupDatasourceParameters{} + +func (s AdlsBlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper AdlsBlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "AdlsBlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_authcredentials.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_authcredentials.go new file mode 100644 index 00000000000..9a3d0459a8f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_authcredentials.go @@ -0,0 +1,75 @@ +package backupinstancesextensionrouting + +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 AuthCredentials interface { + AuthCredentials() BaseAuthCredentialsImpl +} + +var _ AuthCredentials = BaseAuthCredentialsImpl{} + +type BaseAuthCredentialsImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseAuthCredentialsImpl) AuthCredentials() BaseAuthCredentialsImpl { + return s +} + +var _ AuthCredentials = RawAuthCredentialsImpl{} + +// RawAuthCredentialsImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAuthCredentialsImpl struct { + authCredentials BaseAuthCredentialsImpl + Type string + Values map[string]interface{} +} + +func (s RawAuthCredentialsImpl) AuthCredentials() BaseAuthCredentialsImpl { + return s.authCredentials +} + +func UnmarshalAuthCredentialsImplementation(input []byte) (AuthCredentials, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AuthCredentials into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "SecretStoreBasedAuthCredentials") { + var out SecretStoreBasedAuthCredentials + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecretStoreBasedAuthCredentials: %+v", err) + } + return out, nil + } + + var parent BaseAuthCredentialsImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseAuthCredentialsImpl: %+v", err) + } + + return RawAuthCredentialsImpl{ + authCredentials: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_azureoperationalstoreparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_azureoperationalstoreparameters.go new file mode 100644 index 00000000000..7d380b73623 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_azureoperationalstoreparameters.go @@ -0,0 +1,52 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataStoreParameters = AzureOperationalStoreParameters{} + +type AzureOperationalStoreParameters struct { + ResourceGroupId *string `json:"resourceGroupId,omitempty"` + + // Fields inherited from DataStoreParameters + + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} + +func (s AzureOperationalStoreParameters) DataStoreParameters() BaseDataStoreParametersImpl { + return BaseDataStoreParametersImpl{ + DataStoreType: s.DataStoreType, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureOperationalStoreParameters{} + +func (s AzureOperationalStoreParameters) MarshalJSON() ([]byte, error) { + type wrapper AzureOperationalStoreParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureOperationalStoreParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureOperationalStoreParameters: %+v", err) + } + + decoded["objectType"] = "AzureOperationalStoreParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureOperationalStoreParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupdatasourceparameters.go new file mode 100644 index 00000000000..f3459d096da --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupdatasourceparameters.go @@ -0,0 +1,91 @@ +package backupinstancesextensionrouting + +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 BackupDatasourceParameters interface { + BackupDatasourceParameters() BaseBackupDatasourceParametersImpl +} + +var _ BackupDatasourceParameters = BaseBackupDatasourceParametersImpl{} + +type BaseBackupDatasourceParametersImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseBackupDatasourceParametersImpl) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return s +} + +var _ BackupDatasourceParameters = RawBackupDatasourceParametersImpl{} + +// RawBackupDatasourceParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupDatasourceParametersImpl struct { + backupDatasourceParameters BaseBackupDatasourceParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawBackupDatasourceParametersImpl) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return s.backupDatasourceParameters +} + +func UnmarshalBackupDatasourceParametersImplementation(input []byte) (BackupDatasourceParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupDatasourceParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AdlsBlobBackupDatasourceParameters") { + var out AdlsBlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AdlsBlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "BlobBackupDatasourceParameters") { + var out BlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterBackupDatasourceParameters") { + var out KubernetesClusterBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + var parent BaseBackupDatasourceParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBackupDatasourceParametersImpl: %+v", err) + } + + return RawBackupDatasourceParametersImpl{ + backupDatasourceParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstance.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstance.go new file mode 100644 index 00000000000..8c52ab5bae1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstance.go @@ -0,0 +1,75 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstance struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` +} + +var _ json.Unmarshaler = &BackupInstance{} + +func (s *BackupInstance) UnmarshalJSON(bytes []byte) error { + var decoded struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.CurrentProtectionState = decoded.CurrentProtectionState + s.DataSourceInfo = decoded.DataSourceInfo + s.DataSourceSetInfo = decoded.DataSourceSetInfo + s.FriendlyName = decoded.FriendlyName + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.PolicyInfo = decoded.PolicyInfo + s.ProtectionErrorDetails = decoded.ProtectionErrorDetails + s.ProtectionStatus = decoded.ProtectionStatus + s.ProvisioningState = decoded.ProvisioningState + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.ValidationType = decoded.ValidationType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupInstance into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := UnmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'BackupInstance': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstanceresource.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstanceresource.go new file mode 100644 index 00000000000..2475f000f75 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_backupinstanceresource.go @@ -0,0 +1,17 @@ +package backupinstancesextensionrouting + +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 BackupInstanceResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupInstance `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/dataprotection/2025-02-01/backupinstancesextensionrouting/model_baseresourceproperties.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_baseresourceproperties.go new file mode 100644 index 00000000000..01f0b55de17 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_baseresourceproperties.go @@ -0,0 +1,75 @@ +package backupinstancesextensionrouting + +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 BaseResourceProperties interface { + BaseResourceProperties() BaseBaseResourcePropertiesImpl +} + +var _ BaseResourceProperties = BaseBaseResourcePropertiesImpl{} + +type BaseBaseResourcePropertiesImpl struct { + ObjectType ResourcePropertiesObjectType `json:"objectType"` +} + +func (s BaseBaseResourcePropertiesImpl) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return s +} + +var _ BaseResourceProperties = RawBaseResourcePropertiesImpl{} + +// RawBaseResourcePropertiesImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseResourcePropertiesImpl struct { + baseResourceProperties BaseBaseResourcePropertiesImpl + Type string + Values map[string]interface{} +} + +func (s RawBaseResourcePropertiesImpl) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return s.baseResourceProperties +} + +func UnmarshalBaseResourcePropertiesImplementation(input []byte) (BaseResourceProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseResourceProperties into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "DefaultResourceProperties") { + var out DefaultResourceProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DefaultResourceProperties: %+v", err) + } + return out, nil + } + + var parent BaseBaseResourcePropertiesImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBaseResourcePropertiesImpl: %+v", err) + } + + return RawBaseResourcePropertiesImpl{ + baseResourceProperties: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_blobbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_blobbackupdatasourceparameters.go new file mode 100644 index 00000000000..84bada559e2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_blobbackupdatasourceparameters.go @@ -0,0 +1,50 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = BlobBackupDatasourceParameters{} + +type BlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s BlobBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = BlobBackupDatasourceParameters{} + +func (s BlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper BlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BlobBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "BlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasource.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasource.go new file mode 100644 index 00000000000..69a48baf9b9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasource.go @@ -0,0 +1,60 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Datasource struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &Datasource{} + +func (s *Datasource) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Datasource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := UnmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'Datasource': %+v", err) + } + s.ResourceProperties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasourceset.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasourceset.go new file mode 100644 index 00000000000..3ef00bfda19 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datasourceset.go @@ -0,0 +1,60 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatasourceSet struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &DatasourceSet{} + +func (s *DatasourceSet) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DatasourceSet into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := UnmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'DatasourceSet': %+v", err) + } + s.ResourceProperties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datastoreparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datastoreparameters.go new file mode 100644 index 00000000000..9ff16fc767a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_datastoreparameters.go @@ -0,0 +1,76 @@ +package backupinstancesextensionrouting + +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 DataStoreParameters interface { + DataStoreParameters() BaseDataStoreParametersImpl +} + +var _ DataStoreParameters = BaseDataStoreParametersImpl{} + +type BaseDataStoreParametersImpl struct { + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} + +func (s BaseDataStoreParametersImpl) DataStoreParameters() BaseDataStoreParametersImpl { + return s +} + +var _ DataStoreParameters = RawDataStoreParametersImpl{} + +// RawDataStoreParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDataStoreParametersImpl struct { + dataStoreParameters BaseDataStoreParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawDataStoreParametersImpl) DataStoreParameters() BaseDataStoreParametersImpl { + return s.dataStoreParameters +} + +func UnmarshalDataStoreParametersImplementation(input []byte) (DataStoreParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DataStoreParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureOperationalStoreParameters") { + var out AzureOperationalStoreParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureOperationalStoreParameters: %+v", err) + } + return out, nil + } + + var parent BaseDataStoreParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseDataStoreParametersImpl: %+v", err) + } + + return RawDataStoreParametersImpl{ + dataStoreParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_defaultresourceproperties.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_defaultresourceproperties.go new file mode 100644 index 00000000000..545969d7cdf --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_defaultresourceproperties.go @@ -0,0 +1,49 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseResourceProperties = DefaultResourceProperties{} + +type DefaultResourceProperties struct { + + // Fields inherited from BaseResourceProperties + + ObjectType ResourcePropertiesObjectType `json:"objectType"` +} + +func (s DefaultResourceProperties) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return BaseBaseResourcePropertiesImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = DefaultResourceProperties{} + +func (s DefaultResourceProperties) MarshalJSON() ([]byte, error) { + type wrapper DefaultResourceProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DefaultResourceProperties: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DefaultResourceProperties: %+v", err) + } + + decoded["objectType"] = "DefaultResourceProperties" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DefaultResourceProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_identitydetails.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_identitydetails.go new file mode 100644 index 00000000000..5933b86797c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_identitydetails.go @@ -0,0 +1,9 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityDetails struct { + UseSystemAssignedIdentity *bool `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentityArmURL *string `json:"userAssignedIdentityArmUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_innererror.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_innererror.go new file mode 100644 index 00000000000..cbb4bed7fc2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_innererror.go @@ -0,0 +1,10 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_kubernetesclusterbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_kubernetesclusterbackupdatasourceparameters.go new file mode 100644 index 00000000000..9edb440295b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_kubernetesclusterbackupdatasourceparameters.go @@ -0,0 +1,58 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = KubernetesClusterBackupDatasourceParameters{} + +type KubernetesClusterBackupDatasourceParameters struct { + BackupHookReferences *[]NamespacedNameResource `json:"backupHookReferences,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + IncludedVolumeTypes *[]AKSVolumeTypes `json:"includedVolumeTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + SnapshotVolumes bool `json:"snapshotVolumes"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s KubernetesClusterBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesClusterBackupDatasourceParameters{} + +func (s KubernetesClusterBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "KubernetesClusterBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_namespacednameresource.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_namespacednameresource.go new file mode 100644 index 00000000000..f5eebec8f11 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_namespacednameresource.go @@ -0,0 +1,9 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespacedNameResource struct { + Name *string `json:"name,omitempty"` + Namespace *string `json:"namespace,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyinfo.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyinfo.go new file mode 100644 index 00000000000..3bf2c011486 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyinfo.go @@ -0,0 +1,10 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyInfo struct { + PolicyId string `json:"policyId"` + PolicyParameters *PolicyParameters `json:"policyParameters,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyparameters.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyparameters.go new file mode 100644 index 00000000000..507c99142ef --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_policyparameters.go @@ -0,0 +1,60 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyParameters struct { + BackupDatasourceParametersList *[]BackupDatasourceParameters `json:"backupDatasourceParametersList,omitempty"` + DataStoreParametersList *[]DataStoreParameters `json:"dataStoreParametersList,omitempty"` +} + +var _ json.Unmarshaler = &PolicyParameters{} + +func (s *PolicyParameters) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PolicyParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupDatasourceParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling BackupDatasourceParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]BackupDatasourceParameters, 0) + for i, val := range listTemp { + impl, err := UnmarshalBackupDatasourceParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'BackupDatasourceParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.BackupDatasourceParametersList = &output + } + + if v, ok := temp["dataStoreParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DataStoreParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]DataStoreParameters, 0) + for i, val := range listTemp { + impl, err := UnmarshalDataStoreParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DataStoreParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.DataStoreParametersList = &output + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_protectionstatusdetails.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_protectionstatusdetails.go new file mode 100644 index 00000000000..021103e85bc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_protectionstatusdetails.go @@ -0,0 +1,9 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionStatusDetails struct { + ErrorDetails *UserFacingError `json:"errorDetails,omitempty"` + Status *Status `json:"status,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstorebasedauthcredentials.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstorebasedauthcredentials.go new file mode 100644 index 00000000000..c2f65da6553 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstorebasedauthcredentials.go @@ -0,0 +1,50 @@ +package backupinstancesextensionrouting + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AuthCredentials = SecretStoreBasedAuthCredentials{} + +type SecretStoreBasedAuthCredentials struct { + SecretStoreResource *SecretStoreResource `json:"secretStoreResource,omitempty"` + + // Fields inherited from AuthCredentials + + ObjectType string `json:"objectType"` +} + +func (s SecretStoreBasedAuthCredentials) AuthCredentials() BaseAuthCredentialsImpl { + return BaseAuthCredentialsImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = SecretStoreBasedAuthCredentials{} + +func (s SecretStoreBasedAuthCredentials) MarshalJSON() ([]byte, error) { + type wrapper SecretStoreBasedAuthCredentials + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + decoded["objectType"] = "SecretStoreBasedAuthCredentials" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstoreresource.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstoreresource.go new file mode 100644 index 00000000000..46c758dc426 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_secretstoreresource.go @@ -0,0 +1,10 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretStoreResource struct { + SecretStoreType SecretStoreType `json:"secretStoreType"` + Uri *string `json:"uri,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_userfacingerror.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_userfacingerror.go new file mode 100644 index 00000000000..20efdbfdb58 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/model_userfacingerror.go @@ -0,0 +1,16 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/predicates.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/predicates.go new file mode 100644 index 00000000000..a524820a860 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/predicates.go @@ -0,0 +1,27 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupInstanceResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BackupInstanceResourceOperationPredicate) Matches(input BackupInstanceResource) 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/dataprotection/2025-02-01/backupinstancesextensionrouting/version.go b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/version.go new file mode 100644 index 00000000000..e828edb493f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting/version.go @@ -0,0 +1,10 @@ +package backupinstancesextensionrouting + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/backupinstancesextensionrouting/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/README.md b/resource-manager/dataprotection/2025-02-01/backuppolicies/README.md new file mode 100644 index 00000000000..bf223a93d4e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backuppolicies` Documentation + +The `backuppolicies` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backuppolicies" +``` + + +### Client Initialization + +```go +client := backuppolicies.NewBackupPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupPolicyName") + +payload := backuppolicies.BaseBackupPolicyResource{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupPolicyName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupPoliciesClient.Get` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupPolicyName") + +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: `BackupPoliciesClient.List` + +```go +ctx := context.TODO() +id := backuppolicies.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/client.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/client.go new file mode 100644 index 00000000000..a888bef7263 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/client.go @@ -0,0 +1,26 @@ +package backuppolicies + +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 BackupPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewBackupPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "backuppolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupPoliciesClient: %+v", err) + } + + return &BackupPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/constants.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/constants.go new file mode 100644 index 00000000000..0a08f75af9b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/constants.go @@ -0,0 +1,281 @@ +package backuppolicies + +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 AbsoluteMarker string + +const ( + AbsoluteMarkerAllBackup AbsoluteMarker = "AllBackup" + AbsoluteMarkerFirstOfDay AbsoluteMarker = "FirstOfDay" + AbsoluteMarkerFirstOfMonth AbsoluteMarker = "FirstOfMonth" + AbsoluteMarkerFirstOfWeek AbsoluteMarker = "FirstOfWeek" + AbsoluteMarkerFirstOfYear AbsoluteMarker = "FirstOfYear" +) + +func PossibleValuesForAbsoluteMarker() []string { + return []string{ + string(AbsoluteMarkerAllBackup), + string(AbsoluteMarkerFirstOfDay), + string(AbsoluteMarkerFirstOfMonth), + string(AbsoluteMarkerFirstOfWeek), + string(AbsoluteMarkerFirstOfYear), + } +} + +func (s *AbsoluteMarker) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAbsoluteMarker(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAbsoluteMarker(input string) (*AbsoluteMarker, error) { + vals := map[string]AbsoluteMarker{ + "allbackup": AbsoluteMarkerAllBackup, + "firstofday": AbsoluteMarkerFirstOfDay, + "firstofmonth": AbsoluteMarkerFirstOfMonth, + "firstofweek": AbsoluteMarkerFirstOfWeek, + "firstofyear": AbsoluteMarkerFirstOfYear, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AbsoluteMarker(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +type DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} + +type Month string + +const ( + MonthApril Month = "April" + MonthAugust Month = "August" + MonthDecember Month = "December" + MonthFebruary Month = "February" + MonthJanuary Month = "January" + MonthJuly Month = "July" + MonthJune Month = "June" + MonthMarch Month = "March" + MonthMay Month = "May" + MonthNovember Month = "November" + MonthOctober Month = "October" + MonthSeptember Month = "September" +) + +func PossibleValuesForMonth() []string { + return []string{ + string(MonthApril), + string(MonthAugust), + string(MonthDecember), + string(MonthFebruary), + string(MonthJanuary), + string(MonthJuly), + string(MonthJune), + string(MonthMarch), + string(MonthMay), + string(MonthNovember), + string(MonthOctober), + string(MonthSeptember), + } +} + +func (s *Month) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMonth(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMonth(input string) (*Month, error) { + vals := map[string]Month{ + "april": MonthApril, + "august": MonthAugust, + "december": MonthDecember, + "february": MonthFebruary, + "january": MonthJanuary, + "july": MonthJuly, + "june": MonthJune, + "march": MonthMarch, + "may": MonthMay, + "november": MonthNovember, + "october": MonthOctober, + "september": MonthSeptember, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Month(input) + return &out, nil +} + +type WeekNumber string + +const ( + WeekNumberFirst WeekNumber = "First" + WeekNumberFourth WeekNumber = "Fourth" + WeekNumberLast WeekNumber = "Last" + WeekNumberSecond WeekNumber = "Second" + WeekNumberThird WeekNumber = "Third" +) + +func PossibleValuesForWeekNumber() []string { + return []string{ + string(WeekNumberFirst), + string(WeekNumberFourth), + string(WeekNumberLast), + string(WeekNumberSecond), + string(WeekNumberThird), + } +} + +func (s *WeekNumber) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWeekNumber(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWeekNumber(input string) (*WeekNumber, error) { + vals := map[string]WeekNumber{ + "first": WeekNumberFirst, + "fourth": WeekNumberFourth, + "last": WeekNumberLast, + "second": WeekNumberSecond, + "third": WeekNumberThird, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WeekNumber(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy.go new file mode 100644 index 00000000000..b53eed252bf --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy.go @@ -0,0 +1,139 @@ +package backuppolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupPolicyId{}) +} + +var _ resourceids.ResourceId = &BackupPolicyId{} + +// BackupPolicyId is a struct representing the Resource ID for a Backup Policy +type BackupPolicyId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupPolicyName string +} + +// NewBackupPolicyID returns a new BackupPolicyId struct +func NewBackupPolicyID(subscriptionId string, resourceGroupName string, backupVaultName string, backupPolicyName string) BackupPolicyId { + return BackupPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupPolicyName: backupPolicyName, + } +} + +// ParseBackupPolicyID parses 'input' into a BackupPolicyId +func ParseBackupPolicyID(input string) (*BackupPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupPolicyIDInsensitively parses 'input' case-insensitively into a BackupPolicyId +// note: this method should only be used for API response data and not user input +func ParseBackupPolicyIDInsensitively(input string) (*BackupPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupPolicyId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupPolicyName, ok = input.Parsed["backupPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupPolicyName", input) + } + + return nil +} + +// ValidateBackupPolicyID checks that 'input' can be parsed as a Backup Policy ID +func ValidateBackupPolicyID(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 := ParseBackupPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Policy ID +func (id BackupPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Policy ID +func (id BackupPolicyId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupPolicies", "backupPolicies", "backupPolicies"), + resourceids.UserSpecifiedSegment("backupPolicyName", "backupPolicyName"), + } +} + +// String returns a human-readable description of this Backup Policy ID +func (id BackupPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Policy Name: %q", id.BackupPolicyName), + } + return fmt.Sprintf("Backup Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy_test.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy_test.go new file mode 100644 index 00000000000..7db596ffd5c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backuppolicy_test.go @@ -0,0 +1,327 @@ +package backuppolicies + +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 = &BackupPolicyId{} + +func TestNewBackupPolicyID(t *testing.T) { + id := NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupPolicyName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.BackupPolicyName != "backupPolicyName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupPolicyName'", id.BackupPolicyName, "backupPolicyName") + } +} + +func TestFormatBackupPolicyID(t *testing.T) { + actual := NewBackupPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupPolicyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies/backupPolicyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupPolicyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies/backupPolicyName", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupPolicyName: "backupPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies/backupPolicyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupPolicyID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupPolicyName != v.Expected.BackupPolicyName { + t.Fatalf("Expected %q but got %q for BackupPolicyName", v.Expected.BackupPolicyName, actual.BackupPolicyName) + } + + } +} + +func TestParseBackupPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupPolicyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies/backupPolicyName", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupPolicyName: "backupPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupPolicies/backupPolicyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPpOlIcIeS/bAcKuPpOlIcYnAmE", + Expected: &BackupPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + BackupPolicyName: "bAcKuPpOlIcYnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPpOlIcIeS/bAcKuPpOlIcYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupPolicyIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupPolicyName != v.Expected.BackupPolicyName { + t.Fatalf("Expected %q but got %q for BackupPolicyName", v.Expected.BackupPolicyName, actual.BackupPolicyName) + } + + } +} + +func TestSegmentsForBackupPolicyId(t *testing.T) { + segments := BackupPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupPolicyId 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/dataprotection/2025-02-01/backuppolicies/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault.go new file mode 100644 index 00000000000..2e13f9aeb84 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault.go @@ -0,0 +1,130 @@ +package backuppolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault_test.go new file mode 100644 index 00000000000..5844e8c8de1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/id_backupvault_test.go @@ -0,0 +1,282 @@ +package backuppolicies + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/backuppolicies/method_createorupdate.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_createorupdate.go new file mode 100644 index 00000000000..04342e7a5d0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_createorupdate.go @@ -0,0 +1,57 @@ +package backuppolicies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BaseBackupPolicyResource +} + +// CreateOrUpdate ... +func (c BackupPoliciesClient) CreateOrUpdate(ctx context.Context, id BackupPolicyId, input BaseBackupPolicyResource) (result CreateOrUpdateOperationResponse, 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 BaseBackupPolicyResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/method_delete.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_delete.go new file mode 100644 index 00000000000..8b9659f79fa --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_delete.go @@ -0,0 +1,47 @@ +package backuppolicies + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c BackupPoliciesClient) Delete(ctx context.Context, id BackupPolicyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/method_get.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_get.go new file mode 100644 index 00000000000..1dbecf80051 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_get.go @@ -0,0 +1,53 @@ +package backuppolicies + +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 *BaseBackupPolicyResource +} + +// Get ... +func (c BackupPoliciesClient) Get(ctx context.Context, id BackupPolicyId) (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 BaseBackupPolicyResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/method_list.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_list.go new file mode 100644 index 00000000000..1090bb36395 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/method_list.go @@ -0,0 +1,105 @@ +package backuppolicies + +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 *[]BaseBackupPolicyResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []BaseBackupPolicyResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c BackupPoliciesClient) List(ctx context.Context, id BackupVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/backupPolicies", 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 *[]BaseBackupPolicyResource `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 BackupPoliciesClient) ListComplete(ctx context.Context, id BackupVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BaseBackupPolicyResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate BaseBackupPolicyResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]BaseBackupPolicyResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_absolutedeleteoption.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_absolutedeleteoption.go new file mode 100644 index 00000000000..fe6ce6d3432 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_absolutedeleteoption.go @@ -0,0 +1,51 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DeleteOption = AbsoluteDeleteOption{} + +type AbsoluteDeleteOption struct { + + // Fields inherited from DeleteOption + + Duration string `json:"duration"` + ObjectType string `json:"objectType"` +} + +func (s AbsoluteDeleteOption) DeleteOption() BaseDeleteOptionImpl { + return BaseDeleteOptionImpl{ + Duration: s.Duration, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AbsoluteDeleteOption{} + +func (s AbsoluteDeleteOption) MarshalJSON() ([]byte, error) { + type wrapper AbsoluteDeleteOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AbsoluteDeleteOption: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AbsoluteDeleteOption: %+v", err) + } + + decoded["objectType"] = "AbsoluteDeleteOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AbsoluteDeleteOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtaggingcriteria.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtaggingcriteria.go new file mode 100644 index 00000000000..e74b150de31 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtaggingcriteria.go @@ -0,0 +1,8 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdhocBasedTaggingCriteria struct { + TagInfo *RetentionTag `json:"tagInfo,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtriggercontext.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtriggercontext.go new file mode 100644 index 00000000000..30cb106ddf1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_adhocbasedtriggercontext.go @@ -0,0 +1,50 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ TriggerContext = AdhocBasedTriggerContext{} + +type AdhocBasedTriggerContext struct { + TaggingCriteria AdhocBasedTaggingCriteria `json:"taggingCriteria"` + + // Fields inherited from TriggerContext + + ObjectType string `json:"objectType"` +} + +func (s AdhocBasedTriggerContext) TriggerContext() BaseTriggerContextImpl { + return BaseTriggerContextImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AdhocBasedTriggerContext{} + +func (s AdhocBasedTriggerContext) MarshalJSON() ([]byte, error) { + type wrapper AdhocBasedTriggerContext + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AdhocBasedTriggerContext: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AdhocBasedTriggerContext: %+v", err) + } + + decoded["objectType"] = "AdhocBasedTriggerContext" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AdhocBasedTriggerContext: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackupparams.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackupparams.go new file mode 100644 index 00000000000..6b98b1df1f3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackupparams.go @@ -0,0 +1,50 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupParameters = AzureBackupParams{} + +type AzureBackupParams struct { + BackupType string `json:"backupType"` + + // Fields inherited from BackupParameters + + ObjectType string `json:"objectType"` +} + +func (s AzureBackupParams) BackupParameters() BaseBackupParametersImpl { + return BaseBackupParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureBackupParams{} + +func (s AzureBackupParams) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupParams + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupParams: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupParams: %+v", err) + } + + decoded["objectType"] = "AzureBackupParams" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupParams: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackuprule.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackuprule.go new file mode 100644 index 00000000000..f0b3fbd2940 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azurebackuprule.go @@ -0,0 +1,94 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BasePolicyRule = AzureBackupRule{} + +type AzureBackupRule struct { + BackupParameters BackupParameters `json:"backupParameters"` + DataStore DataStoreInfoBase `json:"dataStore"` + Trigger TriggerContext `json:"trigger"` + + // Fields inherited from BasePolicyRule + + Name string `json:"name"` + ObjectType string `json:"objectType"` +} + +func (s AzureBackupRule) BasePolicyRule() BaseBasePolicyRuleImpl { + return BaseBasePolicyRuleImpl{ + Name: s.Name, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureBackupRule{} + +func (s AzureBackupRule) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupRule: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRule: %+v", err) + } + + decoded["objectType"] = "AzureBackupRule" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupRule: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &AzureBackupRule{} + +func (s *AzureBackupRule) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DataStore DataStoreInfoBase `json:"dataStore"` + Name string `json:"name"` + ObjectType string `json:"objectType"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DataStore = decoded.DataStore + s.Name = decoded.Name + s.ObjectType = decoded.ObjectType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRule into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupParameters"]; ok { + impl, err := UnmarshalBackupParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'BackupParameters' for 'AzureBackupRule': %+v", err) + } + s.BackupParameters = impl + } + + if v, ok := temp["trigger"]; ok { + impl, err := UnmarshalTriggerContextImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Trigger' for 'AzureBackupRule': %+v", err) + } + s.Trigger = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azureretentionrule.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azureretentionrule.go new file mode 100644 index 00000000000..f6c4c671bcc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_azureretentionrule.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BasePolicyRule = AzureRetentionRule{} + +type AzureRetentionRule struct { + IsDefault *bool `json:"isDefault,omitempty"` + Lifecycles []SourceLifeCycle `json:"lifecycles"` + + // Fields inherited from BasePolicyRule + + Name string `json:"name"` + ObjectType string `json:"objectType"` +} + +func (s AzureRetentionRule) BasePolicyRule() BaseBasePolicyRuleImpl { + return BaseBasePolicyRuleImpl{ + Name: s.Name, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureRetentionRule{} + +func (s AzureRetentionRule) MarshalJSON() ([]byte, error) { + type wrapper AzureRetentionRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureRetentionRule: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureRetentionRule: %+v", err) + } + + decoded["objectType"] = "AzureRetentionRule" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureRetentionRule: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupcriteria.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupcriteria.go new file mode 100644 index 00000000000..1a965263159 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupcriteria.go @@ -0,0 +1,75 @@ +package backuppolicies + +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 BackupCriteria interface { + BackupCriteria() BaseBackupCriteriaImpl +} + +var _ BackupCriteria = BaseBackupCriteriaImpl{} + +type BaseBackupCriteriaImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseBackupCriteriaImpl) BackupCriteria() BaseBackupCriteriaImpl { + return s +} + +var _ BackupCriteria = RawBackupCriteriaImpl{} + +// RawBackupCriteriaImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupCriteriaImpl struct { + backupCriteria BaseBackupCriteriaImpl + Type string + Values map[string]interface{} +} + +func (s RawBackupCriteriaImpl) BackupCriteria() BaseBackupCriteriaImpl { + return s.backupCriteria +} + +func UnmarshalBackupCriteriaImplementation(input []byte) (BackupCriteria, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupCriteria into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "ScheduleBasedBackupCriteria") { + var out ScheduleBasedBackupCriteria + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScheduleBasedBackupCriteria: %+v", err) + } + return out, nil + } + + var parent BaseBackupCriteriaImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBackupCriteriaImpl: %+v", err) + } + + return RawBackupCriteriaImpl{ + backupCriteria: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupparameters.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupparameters.go new file mode 100644 index 00000000000..5df2e7f42c2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupparameters.go @@ -0,0 +1,75 @@ +package backuppolicies + +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 BackupParameters interface { + BackupParameters() BaseBackupParametersImpl +} + +var _ BackupParameters = BaseBackupParametersImpl{} + +type BaseBackupParametersImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseBackupParametersImpl) BackupParameters() BaseBackupParametersImpl { + return s +} + +var _ BackupParameters = RawBackupParametersImpl{} + +// RawBackupParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupParametersImpl struct { + backupParameters BaseBackupParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawBackupParametersImpl) BackupParameters() BaseBackupParametersImpl { + return s.backupParameters +} + +func UnmarshalBackupParametersImplementation(input []byte) (BackupParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureBackupParams") { + var out AzureBackupParams + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupParams: %+v", err) + } + return out, nil + } + + var parent BaseBackupParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBackupParametersImpl: %+v", err) + } + + return RawBackupParametersImpl{ + backupParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backuppolicy.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backuppolicy.go new file mode 100644 index 00000000000..ef0baa7b6ec --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backuppolicy.go @@ -0,0 +1,91 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseBackupPolicy = BackupPolicy{} + +type BackupPolicy struct { + PolicyRules []BasePolicyRule `json:"policyRules"` + + // Fields inherited from BaseBackupPolicy + + DatasourceTypes []string `json:"datasourceTypes"` + ObjectType string `json:"objectType"` +} + +func (s BackupPolicy) BaseBackupPolicy() BaseBaseBackupPolicyImpl { + return BaseBaseBackupPolicyImpl{ + DatasourceTypes: s.DatasourceTypes, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = BackupPolicy{} + +func (s BackupPolicy) MarshalJSON() ([]byte, error) { + type wrapper BackupPolicy + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BackupPolicy: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BackupPolicy: %+v", err) + } + + decoded["objectType"] = "BackupPolicy" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BackupPolicy: %+v", err) + } + + return encoded, nil +} + +var _ json.Unmarshaler = &BackupPolicy{} + +func (s *BackupPolicy) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceTypes []string `json:"datasourceTypes"` + ObjectType string `json:"objectType"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceTypes = decoded.DatasourceTypes + s.ObjectType = decoded.ObjectType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BackupPolicy into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["policyRules"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling PolicyRules into list []json.RawMessage: %+v", err) + } + + output := make([]BasePolicyRule, 0) + for i, val := range listTemp { + impl, err := UnmarshalBasePolicyRuleImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'PolicyRules' for 'BackupPolicy': %+v", i, err) + } + output = append(output, impl) + } + s.PolicyRules = output + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupschedule.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupschedule.go new file mode 100644 index 00000000000..47d41f51d4c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_backupschedule.go @@ -0,0 +1,9 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupSchedule struct { + RepeatingTimeIntervals []string `json:"repeatingTimeIntervals"` + TimeZone *string `json:"timeZone,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicy.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicy.go new file mode 100644 index 00000000000..a2e6ff5b9d5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicy.go @@ -0,0 +1,76 @@ +package backuppolicies + +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 BaseBackupPolicy interface { + BaseBackupPolicy() BaseBaseBackupPolicyImpl +} + +var _ BaseBackupPolicy = BaseBaseBackupPolicyImpl{} + +type BaseBaseBackupPolicyImpl struct { + DatasourceTypes []string `json:"datasourceTypes"` + ObjectType string `json:"objectType"` +} + +func (s BaseBaseBackupPolicyImpl) BaseBackupPolicy() BaseBaseBackupPolicyImpl { + return s +} + +var _ BaseBackupPolicy = RawBaseBackupPolicyImpl{} + +// RawBaseBackupPolicyImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseBackupPolicyImpl struct { + baseBackupPolicy BaseBaseBackupPolicyImpl + Type string + Values map[string]interface{} +} + +func (s RawBaseBackupPolicyImpl) BaseBackupPolicy() BaseBaseBackupPolicyImpl { + return s.baseBackupPolicy +} + +func UnmarshalBaseBackupPolicyImplementation(input []byte) (BaseBackupPolicy, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseBackupPolicy into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "BackupPolicy") { + var out BackupPolicy + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BackupPolicy: %+v", err) + } + return out, nil + } + + var parent BaseBaseBackupPolicyImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBaseBackupPolicyImpl: %+v", err) + } + + return RawBaseBackupPolicyImpl{ + baseBackupPolicy: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicyresource.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicyresource.go new file mode 100644 index 00000000000..670d8300045 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basebackuppolicyresource.go @@ -0,0 +1,53 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" + + "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 BaseBackupPolicyResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties BaseBackupPolicy `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &BaseBackupPolicyResource{} + +func (s *BaseBackupPolicyResource) UnmarshalJSON(bytes []byte) error { + var decoded struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BaseBackupPolicyResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := UnmarshalBaseBackupPolicyImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'BaseBackupPolicyResource': %+v", err) + } + s.Properties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basepolicyrule.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basepolicyrule.go new file mode 100644 index 00000000000..c448a13228e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_basepolicyrule.go @@ -0,0 +1,84 @@ +package backuppolicies + +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 BasePolicyRule interface { + BasePolicyRule() BaseBasePolicyRuleImpl +} + +var _ BasePolicyRule = BaseBasePolicyRuleImpl{} + +type BaseBasePolicyRuleImpl struct { + Name string `json:"name"` + ObjectType string `json:"objectType"` +} + +func (s BaseBasePolicyRuleImpl) BasePolicyRule() BaseBasePolicyRuleImpl { + return s +} + +var _ BasePolicyRule = RawBasePolicyRuleImpl{} + +// RawBasePolicyRuleImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBasePolicyRuleImpl struct { + basePolicyRule BaseBasePolicyRuleImpl + Type string + Values map[string]interface{} +} + +func (s RawBasePolicyRuleImpl) BasePolicyRule() BaseBasePolicyRuleImpl { + return s.basePolicyRule +} + +func UnmarshalBasePolicyRuleImplementation(input []byte) (BasePolicyRule, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BasePolicyRule into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureBackupRule") { + var out AzureBackupRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupRule: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureRetentionRule") { + var out AzureRetentionRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureRetentionRule: %+v", err) + } + return out, nil + } + + var parent BaseBasePolicyRuleImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBasePolicyRuleImpl: %+v", err) + } + + return RawBasePolicyRuleImpl{ + basePolicyRule: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyonexpiryoption.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyonexpiryoption.go new file mode 100644 index 00000000000..de3ff29737c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyonexpiryoption.go @@ -0,0 +1,49 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CopyOption = CopyOnExpiryOption{} + +type CopyOnExpiryOption struct { + + // Fields inherited from CopyOption + + ObjectType string `json:"objectType"` +} + +func (s CopyOnExpiryOption) CopyOption() BaseCopyOptionImpl { + return BaseCopyOptionImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = CopyOnExpiryOption{} + +func (s CopyOnExpiryOption) MarshalJSON() ([]byte, error) { + type wrapper CopyOnExpiryOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CopyOnExpiryOption: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CopyOnExpiryOption: %+v", err) + } + + decoded["objectType"] = "CopyOnExpiryOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CopyOnExpiryOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyoption.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyoption.go new file mode 100644 index 00000000000..b8e76972b85 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_copyoption.go @@ -0,0 +1,91 @@ +package backuppolicies + +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 CopyOption interface { + CopyOption() BaseCopyOptionImpl +} + +var _ CopyOption = BaseCopyOptionImpl{} + +type BaseCopyOptionImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseCopyOptionImpl) CopyOption() BaseCopyOptionImpl { + return s +} + +var _ CopyOption = RawCopyOptionImpl{} + +// RawCopyOptionImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawCopyOptionImpl struct { + copyOption BaseCopyOptionImpl + Type string + Values map[string]interface{} +} + +func (s RawCopyOptionImpl) CopyOption() BaseCopyOptionImpl { + return s.copyOption +} + +func UnmarshalCopyOptionImplementation(input []byte) (CopyOption, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling CopyOption into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "CopyOnExpiryOption") { + var out CopyOnExpiryOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CopyOnExpiryOption: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "CustomCopyOption") { + var out CustomCopyOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CustomCopyOption: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ImmediateCopyOption") { + var out ImmediateCopyOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ImmediateCopyOption: %+v", err) + } + return out, nil + } + + var parent BaseCopyOptionImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseCopyOptionImpl: %+v", err) + } + + return RawCopyOptionImpl{ + copyOption: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_customcopyoption.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_customcopyoption.go new file mode 100644 index 00000000000..e23a6200cb3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_customcopyoption.go @@ -0,0 +1,50 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CopyOption = CustomCopyOption{} + +type CustomCopyOption struct { + Duration *string `json:"duration,omitempty"` + + // Fields inherited from CopyOption + + ObjectType string `json:"objectType"` +} + +func (s CustomCopyOption) CopyOption() BaseCopyOptionImpl { + return BaseCopyOptionImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = CustomCopyOption{} + +func (s CustomCopyOption) MarshalJSON() ([]byte, error) { + type wrapper CustomCopyOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CustomCopyOption: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CustomCopyOption: %+v", err) + } + + decoded["objectType"] = "CustomCopyOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CustomCopyOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_datastoreinfobase.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_datastoreinfobase.go new file mode 100644 index 00000000000..d462ed4c6f6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_datastoreinfobase.go @@ -0,0 +1,9 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataStoreInfoBase struct { + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_day.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_day.go new file mode 100644 index 00000000000..c46c7f57129 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_day.go @@ -0,0 +1,9 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Day struct { + Date *int64 `json:"date,omitempty"` + IsLast *bool `json:"isLast,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_deleteoption.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_deleteoption.go new file mode 100644 index 00000000000..26625d33900 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_deleteoption.go @@ -0,0 +1,76 @@ +package backuppolicies + +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 DeleteOption interface { + DeleteOption() BaseDeleteOptionImpl +} + +var _ DeleteOption = BaseDeleteOptionImpl{} + +type BaseDeleteOptionImpl struct { + Duration string `json:"duration"` + ObjectType string `json:"objectType"` +} + +func (s BaseDeleteOptionImpl) DeleteOption() BaseDeleteOptionImpl { + return s +} + +var _ DeleteOption = RawDeleteOptionImpl{} + +// RawDeleteOptionImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDeleteOptionImpl struct { + deleteOption BaseDeleteOptionImpl + Type string + Values map[string]interface{} +} + +func (s RawDeleteOptionImpl) DeleteOption() BaseDeleteOptionImpl { + return s.deleteOption +} + +func UnmarshalDeleteOptionImplementation(input []byte) (DeleteOption, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DeleteOption into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AbsoluteDeleteOption") { + var out AbsoluteDeleteOption + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AbsoluteDeleteOption: %+v", err) + } + return out, nil + } + + var parent BaseDeleteOptionImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseDeleteOptionImpl: %+v", err) + } + + return RawDeleteOptionImpl{ + deleteOption: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_immediatecopyoption.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_immediatecopyoption.go new file mode 100644 index 00000000000..8be58faec52 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_immediatecopyoption.go @@ -0,0 +1,49 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ CopyOption = ImmediateCopyOption{} + +type ImmediateCopyOption struct { + + // Fields inherited from CopyOption + + ObjectType string `json:"objectType"` +} + +func (s ImmediateCopyOption) CopyOption() BaseCopyOptionImpl { + return BaseCopyOptionImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = ImmediateCopyOption{} + +func (s ImmediateCopyOption) MarshalJSON() ([]byte, error) { + type wrapper ImmediateCopyOption + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ImmediateCopyOption: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ImmediateCopyOption: %+v", err) + } + + decoded["objectType"] = "ImmediateCopyOption" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ImmediateCopyOption: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_retentiontag.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_retentiontag.go new file mode 100644 index 00000000000..f9a6dff3e17 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_retentiontag.go @@ -0,0 +1,10 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetentionTag struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + TagName string `json:"tagName"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedbackupcriteria.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedbackupcriteria.go new file mode 100644 index 00000000000..69188ba4962 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedbackupcriteria.go @@ -0,0 +1,55 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupCriteria = ScheduleBasedBackupCriteria{} + +type ScheduleBasedBackupCriteria struct { + AbsoluteCriteria *[]AbsoluteMarker `json:"absoluteCriteria,omitempty"` + DaysOfMonth *[]Day `json:"daysOfMonth,omitempty"` + DaysOfTheWeek *[]DayOfWeek `json:"daysOfTheWeek,omitempty"` + MonthsOfYear *[]Month `json:"monthsOfYear,omitempty"` + ScheduleTimes *[]string `json:"scheduleTimes,omitempty"` + WeeksOfTheMonth *[]WeekNumber `json:"weeksOfTheMonth,omitempty"` + + // Fields inherited from BackupCriteria + + ObjectType string `json:"objectType"` +} + +func (s ScheduleBasedBackupCriteria) BackupCriteria() BaseBackupCriteriaImpl { + return BaseBackupCriteriaImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = ScheduleBasedBackupCriteria{} + +func (s ScheduleBasedBackupCriteria) MarshalJSON() ([]byte, error) { + type wrapper ScheduleBasedBackupCriteria + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScheduleBasedBackupCriteria: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScheduleBasedBackupCriteria: %+v", err) + } + + decoded["objectType"] = "ScheduleBasedBackupCriteria" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScheduleBasedBackupCriteria: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedtriggercontext.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedtriggercontext.go new file mode 100644 index 00000000000..aee5719cd5c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_schedulebasedtriggercontext.go @@ -0,0 +1,51 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ TriggerContext = ScheduleBasedTriggerContext{} + +type ScheduleBasedTriggerContext struct { + Schedule BackupSchedule `json:"schedule"` + TaggingCriteria []TaggingCriteria `json:"taggingCriteria"` + + // Fields inherited from TriggerContext + + ObjectType string `json:"objectType"` +} + +func (s ScheduleBasedTriggerContext) TriggerContext() BaseTriggerContextImpl { + return BaseTriggerContextImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = ScheduleBasedTriggerContext{} + +func (s ScheduleBasedTriggerContext) MarshalJSON() ([]byte, error) { + type wrapper ScheduleBasedTriggerContext + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScheduleBasedTriggerContext: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScheduleBasedTriggerContext: %+v", err) + } + + decoded["objectType"] = "ScheduleBasedTriggerContext" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScheduleBasedTriggerContext: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_sourcelifecycle.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_sourcelifecycle.go new file mode 100644 index 00000000000..ca6ba42dcc6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_sourcelifecycle.go @@ -0,0 +1,45 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceLifeCycle struct { + DeleteAfter DeleteOption `json:"deleteAfter"` + SourceDataStore DataStoreInfoBase `json:"sourceDataStore"` + TargetDataStoreCopySettings *[]TargetCopySetting `json:"targetDataStoreCopySettings,omitempty"` +} + +var _ json.Unmarshaler = &SourceLifeCycle{} + +func (s *SourceLifeCycle) UnmarshalJSON(bytes []byte) error { + var decoded struct { + SourceDataStore DataStoreInfoBase `json:"sourceDataStore"` + TargetDataStoreCopySettings *[]TargetCopySetting `json:"targetDataStoreCopySettings,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.SourceDataStore = decoded.SourceDataStore + s.TargetDataStoreCopySettings = decoded.TargetDataStoreCopySettings + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SourceLifeCycle into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["deleteAfter"]; ok { + impl, err := UnmarshalDeleteOptionImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DeleteAfter' for 'SourceLifeCycle': %+v", err) + } + s.DeleteAfter = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_taggingcriteria.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_taggingcriteria.go new file mode 100644 index 00000000000..443406895ee --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_taggingcriteria.go @@ -0,0 +1,57 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TaggingCriteria struct { + Criteria *[]BackupCriteria `json:"criteria,omitempty"` + IsDefault bool `json:"isDefault"` + TagInfo RetentionTag `json:"tagInfo"` + TaggingPriority int64 `json:"taggingPriority"` +} + +var _ json.Unmarshaler = &TaggingCriteria{} + +func (s *TaggingCriteria) UnmarshalJSON(bytes []byte) error { + var decoded struct { + IsDefault bool `json:"isDefault"` + TagInfo RetentionTag `json:"tagInfo"` + TaggingPriority int64 `json:"taggingPriority"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.IsDefault = decoded.IsDefault + s.TagInfo = decoded.TagInfo + s.TaggingPriority = decoded.TaggingPriority + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TaggingCriteria into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["criteria"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Criteria into list []json.RawMessage: %+v", err) + } + + output := make([]BackupCriteria, 0) + for i, val := range listTemp { + impl, err := UnmarshalBackupCriteriaImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Criteria' for 'TaggingCriteria': %+v", i, err) + } + output = append(output, impl) + } + s.Criteria = &output + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_targetcopysetting.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_targetcopysetting.go new file mode 100644 index 00000000000..4cdf638ee09 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_targetcopysetting.go @@ -0,0 +1,42 @@ +package backuppolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetCopySetting struct { + CopyAfter CopyOption `json:"copyAfter"` + DataStore DataStoreInfoBase `json:"dataStore"` +} + +var _ json.Unmarshaler = &TargetCopySetting{} + +func (s *TargetCopySetting) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DataStore DataStoreInfoBase `json:"dataStore"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DataStore = decoded.DataStore + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TargetCopySetting into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["copyAfter"]; ok { + impl, err := UnmarshalCopyOptionImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'CopyAfter' for 'TargetCopySetting': %+v", err) + } + s.CopyAfter = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/model_triggercontext.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_triggercontext.go new file mode 100644 index 00000000000..b3ed53a6440 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/model_triggercontext.go @@ -0,0 +1,83 @@ +package backuppolicies + +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 TriggerContext interface { + TriggerContext() BaseTriggerContextImpl +} + +var _ TriggerContext = BaseTriggerContextImpl{} + +type BaseTriggerContextImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseTriggerContextImpl) TriggerContext() BaseTriggerContextImpl { + return s +} + +var _ TriggerContext = RawTriggerContextImpl{} + +// RawTriggerContextImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawTriggerContextImpl struct { + triggerContext BaseTriggerContextImpl + Type string + Values map[string]interface{} +} + +func (s RawTriggerContextImpl) TriggerContext() BaseTriggerContextImpl { + return s.triggerContext +} + +func UnmarshalTriggerContextImplementation(input []byte) (TriggerContext, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling TriggerContext into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AdhocBasedTriggerContext") { + var out AdhocBasedTriggerContext + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AdhocBasedTriggerContext: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ScheduleBasedTriggerContext") { + var out ScheduleBasedTriggerContext + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScheduleBasedTriggerContext: %+v", err) + } + return out, nil + } + + var parent BaseTriggerContextImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseTriggerContextImpl: %+v", err) + } + + return RawTriggerContextImpl{ + triggerContext: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/backuppolicies/predicates.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/predicates.go new file mode 100644 index 00000000000..e53bb0c1ed4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/predicates.go @@ -0,0 +1,27 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseBackupPolicyResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BaseBackupPolicyResourceOperationPredicate) Matches(input BaseBackupPolicyResource) 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/dataprotection/2025-02-01/backuppolicies/version.go b/resource-manager/dataprotection/2025-02-01/backuppolicies/version.go new file mode 100644 index 00000000000..8e6cfed1546 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backuppolicies/version.go @@ -0,0 +1,10 @@ +package backuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/backuppolicies/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/README.md b/resource-manager/dataprotection/2025-02-01/backupvaults/README.md new file mode 100644 index 00000000000..188030da1e7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/README.md @@ -0,0 +1,138 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupvaults` Documentation + +The `backupvaults` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupvaults" +``` + + +### Client Initialization + +```go +client := backupvaults.NewBackupVaultsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupVaultsClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := backupvaults.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +payload := backupvaults.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BackupVaultsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +payload := backupvaults.BackupVaultResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, backupvaults.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupVaultsClient.Delete` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupVaultsClient.Get` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +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: `BackupVaultsClient.GetInResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.GetInResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.GetInResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackupVaultsClient.GetInSubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.GetInSubscription(ctx, id)` can be used to do batched pagination +items, err := client.GetInSubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackupVaultsClient.Update` + +```go +ctx := context.TODO() +id := backupvaults.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +payload := backupvaults.PatchResourceRequestInput{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload, backupvaults.DefaultUpdateOperationOptions()); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/client.go b/resource-manager/dataprotection/2025-02-01/backupvaults/client.go new file mode 100644 index 00000000000..57d96b431b5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/client.go @@ -0,0 +1,26 @@ +package backupvaults + +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 BackupVaultsClient struct { + Client *resourcemanager.Client +} + +func NewBackupVaultsClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupVaultsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "backupvaults", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupVaultsClient: %+v", err) + } + + return &BackupVaultsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/constants.go b/resource-manager/dataprotection/2025-02-01/backupvaults/constants.go new file mode 100644 index 00000000000..731af792200 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/constants.go @@ -0,0 +1,653 @@ +package backupvaults + +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 AlertsState string + +const ( + AlertsStateDisabled AlertsState = "Disabled" + AlertsStateEnabled AlertsState = "Enabled" +) + +func PossibleValuesForAlertsState() []string { + return []string{ + string(AlertsStateDisabled), + string(AlertsStateEnabled), + } +} + +func (s *AlertsState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertsState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertsState(input string) (*AlertsState, error) { + vals := map[string]AlertsState{ + "disabled": AlertsStateDisabled, + "enabled": AlertsStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertsState(input) + return &out, nil +} + +type BCDRSecurityLevel string + +const ( + BCDRSecurityLevelExcellent BCDRSecurityLevel = "Excellent" + BCDRSecurityLevelFair BCDRSecurityLevel = "Fair" + BCDRSecurityLevelGood BCDRSecurityLevel = "Good" + BCDRSecurityLevelNotSupported BCDRSecurityLevel = "NotSupported" + BCDRSecurityLevelPoor BCDRSecurityLevel = "Poor" +) + +func PossibleValuesForBCDRSecurityLevel() []string { + return []string{ + string(BCDRSecurityLevelExcellent), + string(BCDRSecurityLevelFair), + string(BCDRSecurityLevelGood), + string(BCDRSecurityLevelNotSupported), + string(BCDRSecurityLevelPoor), + } +} + +func (s *BCDRSecurityLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBCDRSecurityLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBCDRSecurityLevel(input string) (*BCDRSecurityLevel, error) { + vals := map[string]BCDRSecurityLevel{ + "excellent": BCDRSecurityLevelExcellent, + "fair": BCDRSecurityLevelFair, + "good": BCDRSecurityLevelGood, + "notsupported": BCDRSecurityLevelNotSupported, + "poor": BCDRSecurityLevelPoor, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BCDRSecurityLevel(input) + return &out, nil +} + +type CrossRegionRestoreState string + +const ( + CrossRegionRestoreStateDisabled CrossRegionRestoreState = "Disabled" + CrossRegionRestoreStateEnabled CrossRegionRestoreState = "Enabled" +) + +func PossibleValuesForCrossRegionRestoreState() []string { + return []string{ + string(CrossRegionRestoreStateDisabled), + string(CrossRegionRestoreStateEnabled), + } +} + +func (s *CrossRegionRestoreState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCrossRegionRestoreState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCrossRegionRestoreState(input string) (*CrossRegionRestoreState, error) { + vals := map[string]CrossRegionRestoreState{ + "disabled": CrossRegionRestoreStateDisabled, + "enabled": CrossRegionRestoreStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CrossRegionRestoreState(input) + return &out, nil +} + +type CrossSubscriptionRestoreState string + +const ( + CrossSubscriptionRestoreStateDisabled CrossSubscriptionRestoreState = "Disabled" + CrossSubscriptionRestoreStateEnabled CrossSubscriptionRestoreState = "Enabled" + CrossSubscriptionRestoreStatePermanentlyDisabled CrossSubscriptionRestoreState = "PermanentlyDisabled" +) + +func PossibleValuesForCrossSubscriptionRestoreState() []string { + return []string{ + string(CrossSubscriptionRestoreStateDisabled), + string(CrossSubscriptionRestoreStateEnabled), + string(CrossSubscriptionRestoreStatePermanentlyDisabled), + } +} + +func (s *CrossSubscriptionRestoreState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCrossSubscriptionRestoreState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCrossSubscriptionRestoreState(input string) (*CrossSubscriptionRestoreState, error) { + vals := map[string]CrossSubscriptionRestoreState{ + "disabled": CrossSubscriptionRestoreStateDisabled, + "enabled": CrossSubscriptionRestoreStateEnabled, + "permanentlydisabled": CrossSubscriptionRestoreStatePermanentlyDisabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CrossSubscriptionRestoreState(input) + return &out, nil +} + +type EncryptionState string + +const ( + EncryptionStateDisabled EncryptionState = "Disabled" + EncryptionStateEnabled EncryptionState = "Enabled" + EncryptionStateInconsistent EncryptionState = "Inconsistent" +) + +func PossibleValuesForEncryptionState() []string { + return []string{ + string(EncryptionStateDisabled), + string(EncryptionStateEnabled), + string(EncryptionStateInconsistent), + } +} + +func (s *EncryptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncryptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEncryptionState(input string) (*EncryptionState, error) { + vals := map[string]EncryptionState{ + "disabled": EncryptionStateDisabled, + "enabled": EncryptionStateEnabled, + "inconsistent": EncryptionStateInconsistent, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncryptionState(input) + return &out, nil +} + +type IdentityType string + +const ( + IdentityTypeSystemAssigned IdentityType = "SystemAssigned" + IdentityTypeUserAssigned IdentityType = "UserAssigned" +) + +func PossibleValuesForIdentityType() []string { + return []string{ + string(IdentityTypeSystemAssigned), + string(IdentityTypeUserAssigned), + } +} + +func (s *IdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentityType(input string) (*IdentityType, error) { + vals := map[string]IdentityType{ + "systemassigned": IdentityTypeSystemAssigned, + "userassigned": IdentityTypeUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityType(input) + return &out, nil +} + +type ImmutabilityState string + +const ( + ImmutabilityStateDisabled ImmutabilityState = "Disabled" + ImmutabilityStateLocked ImmutabilityState = "Locked" + ImmutabilityStateUnlocked ImmutabilityState = "Unlocked" +) + +func PossibleValuesForImmutabilityState() []string { + return []string{ + string(ImmutabilityStateDisabled), + string(ImmutabilityStateLocked), + string(ImmutabilityStateUnlocked), + } +} + +func (s *ImmutabilityState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImmutabilityState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImmutabilityState(input string) (*ImmutabilityState, error) { + vals := map[string]ImmutabilityState{ + "disabled": ImmutabilityStateDisabled, + "locked": ImmutabilityStateLocked, + "unlocked": ImmutabilityStateUnlocked, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImmutabilityState(input) + return &out, nil +} + +type InfrastructureEncryptionState string + +const ( + InfrastructureEncryptionStateDisabled InfrastructureEncryptionState = "Disabled" + InfrastructureEncryptionStateEnabled InfrastructureEncryptionState = "Enabled" +) + +func PossibleValuesForInfrastructureEncryptionState() []string { + return []string{ + string(InfrastructureEncryptionStateDisabled), + string(InfrastructureEncryptionStateEnabled), + } +} + +func (s *InfrastructureEncryptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInfrastructureEncryptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInfrastructureEncryptionState(input string) (*InfrastructureEncryptionState, error) { + vals := map[string]InfrastructureEncryptionState{ + "disabled": InfrastructureEncryptionStateDisabled, + "enabled": InfrastructureEncryptionStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InfrastructureEncryptionState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnknown ProvisioningState = "Unknown" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnknown), + 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{ + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "unknown": ProvisioningStateUnknown, + "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 ResourceMoveState string + +const ( + ResourceMoveStateCommitFailed ResourceMoveState = "CommitFailed" + ResourceMoveStateCommitTimedout ResourceMoveState = "CommitTimedout" + ResourceMoveStateCriticalFailure ResourceMoveState = "CriticalFailure" + ResourceMoveStateFailed ResourceMoveState = "Failed" + ResourceMoveStateInProgress ResourceMoveState = "InProgress" + ResourceMoveStateMoveSucceeded ResourceMoveState = "MoveSucceeded" + ResourceMoveStatePartialSuccess ResourceMoveState = "PartialSuccess" + ResourceMoveStatePrepareFailed ResourceMoveState = "PrepareFailed" + ResourceMoveStatePrepareTimedout ResourceMoveState = "PrepareTimedout" + ResourceMoveStateUnknown ResourceMoveState = "Unknown" +) + +func PossibleValuesForResourceMoveState() []string { + return []string{ + string(ResourceMoveStateCommitFailed), + string(ResourceMoveStateCommitTimedout), + string(ResourceMoveStateCriticalFailure), + string(ResourceMoveStateFailed), + string(ResourceMoveStateInProgress), + string(ResourceMoveStateMoveSucceeded), + string(ResourceMoveStatePartialSuccess), + string(ResourceMoveStatePrepareFailed), + string(ResourceMoveStatePrepareTimedout), + string(ResourceMoveStateUnknown), + } +} + +func (s *ResourceMoveState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceMoveState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceMoveState(input string) (*ResourceMoveState, error) { + vals := map[string]ResourceMoveState{ + "commitfailed": ResourceMoveStateCommitFailed, + "committimedout": ResourceMoveStateCommitTimedout, + "criticalfailure": ResourceMoveStateCriticalFailure, + "failed": ResourceMoveStateFailed, + "inprogress": ResourceMoveStateInProgress, + "movesucceeded": ResourceMoveStateMoveSucceeded, + "partialsuccess": ResourceMoveStatePartialSuccess, + "preparefailed": ResourceMoveStatePrepareFailed, + "preparetimedout": ResourceMoveStatePrepareTimedout, + "unknown": ResourceMoveStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceMoveState(input) + return &out, nil +} + +type SecureScoreLevel string + +const ( + SecureScoreLevelAdequate SecureScoreLevel = "Adequate" + SecureScoreLevelMaximum SecureScoreLevel = "Maximum" + SecureScoreLevelMinimum SecureScoreLevel = "Minimum" + SecureScoreLevelNone SecureScoreLevel = "None" + SecureScoreLevelNotSupported SecureScoreLevel = "NotSupported" +) + +func PossibleValuesForSecureScoreLevel() []string { + return []string{ + string(SecureScoreLevelAdequate), + string(SecureScoreLevelMaximum), + string(SecureScoreLevelMinimum), + string(SecureScoreLevelNone), + string(SecureScoreLevelNotSupported), + } +} + +func (s *SecureScoreLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecureScoreLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecureScoreLevel(input string) (*SecureScoreLevel, error) { + vals := map[string]SecureScoreLevel{ + "adequate": SecureScoreLevelAdequate, + "maximum": SecureScoreLevelMaximum, + "minimum": SecureScoreLevelMinimum, + "none": SecureScoreLevelNone, + "notsupported": SecureScoreLevelNotSupported, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecureScoreLevel(input) + return &out, nil +} + +type SoftDeleteState string + +const ( + SoftDeleteStateAlwaysOn SoftDeleteState = "AlwaysOn" + SoftDeleteStateOff SoftDeleteState = "Off" + SoftDeleteStateOn SoftDeleteState = "On" +) + +func PossibleValuesForSoftDeleteState() []string { + return []string{ + string(SoftDeleteStateAlwaysOn), + string(SoftDeleteStateOff), + string(SoftDeleteStateOn), + } +} + +func (s *SoftDeleteState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSoftDeleteState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSoftDeleteState(input string) (*SoftDeleteState, error) { + vals := map[string]SoftDeleteState{ + "alwayson": SoftDeleteStateAlwaysOn, + "off": SoftDeleteStateOff, + "on": SoftDeleteStateOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SoftDeleteState(input) + return &out, nil +} + +type StorageSettingStoreTypes string + +const ( + StorageSettingStoreTypesArchiveStore StorageSettingStoreTypes = "ArchiveStore" + StorageSettingStoreTypesOperationalStore StorageSettingStoreTypes = "OperationalStore" + StorageSettingStoreTypesVaultStore StorageSettingStoreTypes = "VaultStore" +) + +func PossibleValuesForStorageSettingStoreTypes() []string { + return []string{ + string(StorageSettingStoreTypesArchiveStore), + string(StorageSettingStoreTypesOperationalStore), + string(StorageSettingStoreTypesVaultStore), + } +} + +func (s *StorageSettingStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageSettingStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageSettingStoreTypes(input string) (*StorageSettingStoreTypes, error) { + vals := map[string]StorageSettingStoreTypes{ + "archivestore": StorageSettingStoreTypesArchiveStore, + "operationalstore": StorageSettingStoreTypesOperationalStore, + "vaultstore": StorageSettingStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageSettingStoreTypes(input) + return &out, nil +} + +type StorageSettingTypes string + +const ( + StorageSettingTypesGeoRedundant StorageSettingTypes = "GeoRedundant" + StorageSettingTypesLocallyRedundant StorageSettingTypes = "LocallyRedundant" + StorageSettingTypesZoneRedundant StorageSettingTypes = "ZoneRedundant" +) + +func PossibleValuesForStorageSettingTypes() []string { + return []string{ + string(StorageSettingTypesGeoRedundant), + string(StorageSettingTypesLocallyRedundant), + string(StorageSettingTypesZoneRedundant), + } +} + +func (s *StorageSettingTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageSettingTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageSettingTypes(input string) (*StorageSettingTypes, error) { + vals := map[string]StorageSettingTypes{ + "georedundant": StorageSettingTypesGeoRedundant, + "locallyredundant": StorageSettingTypesLocallyRedundant, + "zoneredundant": StorageSettingTypesZoneRedundant, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageSettingTypes(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault.go new file mode 100644 index 00000000000..4a410f65278 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault.go @@ -0,0 +1,130 @@ +package backupvaults + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault_test.go new file mode 100644 index 00000000000..c9950a006d0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/id_backupvault_test.go @@ -0,0 +1,282 @@ +package backupvaults + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/backupvaults/id_providerlocation.go b/resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation.go new file mode 100644 index 00000000000..2d81f0401de --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation.go @@ -0,0 +1,130 @@ +package backupvaults + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation_test.go b/resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation_test.go new file mode 100644 index 00000000000..00af9361aba --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package backupvaults + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2025-02-01/backupvaults/method_checknameavailability.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_checknameavailability.go new file mode 100644 index 00000000000..de967ac422d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_checknameavailability.go @@ -0,0 +1,58 @@ +package backupvaults + +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 CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResult +} + +// CheckNameAvailability ... +func (c BackupVaultsClient) CheckNameAvailability(ctx context.Context, id ProviderLocationId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/method_createorupdate.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_createorupdate.go new file mode 100644 index 00000000000..9ac0e63d1c8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_createorupdate.go @@ -0,0 +1,104 @@ +package backupvaults + +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 *BackupVaultResource +} + +type CreateOrUpdateOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c BackupVaultsClient) CreateOrUpdate(ctx context.Context, id BackupVaultId, input BackupVaultResource, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 BackupVaultsClient) CreateOrUpdateThenPoll(ctx context.Context, id BackupVaultId, input BackupVaultResource, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + 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/dataprotection/2025-02-01/backupvaults/method_delete.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_delete.go new file mode 100644 index 00000000000..6899d5db814 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_delete.go @@ -0,0 +1,71 @@ +package backupvaults + +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 BackupVaultsClient) Delete(ctx context.Context, id BackupVaultId) (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 BackupVaultsClient) DeleteThenPoll(ctx context.Context, id BackupVaultId) 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/dataprotection/2025-02-01/backupvaults/method_get.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_get.go new file mode 100644 index 00000000000..638bcc8f8ce --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_get.go @@ -0,0 +1,53 @@ +package backupvaults + +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 *BackupVaultResource +} + +// Get ... +func (c BackupVaultsClient) Get(ctx context.Context, id BackupVaultId) (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 BackupVaultResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/method_getinresourcegroup.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_getinresourcegroup.go new file mode 100644 index 00000000000..e6956a1b944 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_getinresourcegroup.go @@ -0,0 +1,106 @@ +package backupvaults + +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 GetInResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackupVaultResource +} + +type GetInResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackupVaultResource +} + +type GetInResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetInResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetInResourceGroup ... +func (c BackupVaultsClient) GetInResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result GetInResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetInResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/backupVaults", 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 *[]BackupVaultResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetInResourceGroupComplete retrieves all the results into a single object +func (c BackupVaultsClient) GetInResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (GetInResourceGroupCompleteResult, error) { + return c.GetInResourceGroupCompleteMatchingPredicate(ctx, id, BackupVaultResourceOperationPredicate{}) +} + +// GetInResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupVaultsClient) GetInResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate BackupVaultResourceOperationPredicate) (result GetInResourceGroupCompleteResult, err error) { + items := make([]BackupVaultResource, 0) + + resp, err := c.GetInResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetInResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/method_getinsubscription.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_getinsubscription.go new file mode 100644 index 00000000000..51f30e81a07 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_getinsubscription.go @@ -0,0 +1,106 @@ +package backupvaults + +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 GetInSubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackupVaultResource +} + +type GetInSubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackupVaultResource +} + +type GetInSubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetInSubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetInSubscription ... +func (c BackupVaultsClient) GetInSubscription(ctx context.Context, id commonids.SubscriptionId) (result GetInSubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetInSubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/backupVaults", 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 *[]BackupVaultResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetInSubscriptionComplete retrieves all the results into a single object +func (c BackupVaultsClient) GetInSubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (GetInSubscriptionCompleteResult, error) { + return c.GetInSubscriptionCompleteMatchingPredicate(ctx, id, BackupVaultResourceOperationPredicate{}) +} + +// GetInSubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupVaultsClient) GetInSubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate BackupVaultResourceOperationPredicate) (result GetInSubscriptionCompleteResult, err error) { + items := make([]BackupVaultResource, 0) + + resp, err := c.GetInSubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetInSubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/method_update.go b/resource-manager/dataprotection/2025-02-01/backupvaults/method_update.go new file mode 100644 index 00000000000..1153481cbae --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/method_update.go @@ -0,0 +1,104 @@ +package backupvaults + +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 *BackupVaultResource +} + +type UpdateOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c BackupVaultsClient) Update(ctx context.Context, id BackupVaultId, input PatchResourceRequestInput, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + OptionsObject: options, + 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 BackupVaultsClient) UpdateThenPoll(ctx context.Context, id BackupVaultId, input PatchResourceRequestInput, options UpdateOperationOptions) error { + result, err := c.Update(ctx, id, input, options) + 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/dataprotection/2025-02-01/backupvaults/model_azuremonitoralertsettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_azuremonitoralertsettings.go new file mode 100644 index 00000000000..8abdec3ec1b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_azuremonitoralertsettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureMonitorAlertSettings struct { + AlertsForAllJobFailures *AlertsState `json:"alertsForAllJobFailures,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvault.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvault.go new file mode 100644 index 00000000000..e4b439669fc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvault.go @@ -0,0 +1,19 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupVault struct { + BcdrSecurityLevel *BCDRSecurityLevel `json:"bcdrSecurityLevel,omitempty"` + FeatureSettings *FeatureSettings `json:"featureSettings,omitempty"` + IsVaultProtectedByResourceGuard *bool `json:"isVaultProtectedByResourceGuard,omitempty"` + MonitoringSettings *MonitoringSettings `json:"monitoringSettings,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ReplicatedRegions *[]string `json:"replicatedRegions,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ResourceMoveDetails *ResourceMoveDetails `json:"resourceMoveDetails,omitempty"` + ResourceMoveState *ResourceMoveState `json:"resourceMoveState,omitempty"` + SecureScore *SecureScoreLevel `json:"secureScore,omitempty"` + SecuritySettings *SecuritySettings `json:"securitySettings,omitempty"` + StorageSettings []StorageSetting `json:"storageSettings"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvaultresource.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvaultresource.go new file mode 100644 index 00000000000..29a98bad3b8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_backupvaultresource.go @@ -0,0 +1,20 @@ +package backupvaults + +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 BackupVaultResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *DppIdentityDetails `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties BackupVault `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityrequest.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..bb78afc83b2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityresult.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityresult.go new file mode 100644 index 00000000000..86c51891313 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_checknameavailabilityresult.go @@ -0,0 +1,10 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResult struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkekidentity.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkekidentity.go new file mode 100644 index 00000000000..5d5fa1569f4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkekidentity.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CmkKekIdentity struct { + IdentityId *string `json:"identityId,omitempty"` + IdentityType *IdentityType `json:"identityType,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkeyvaultproperties.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkeyvaultproperties.go new file mode 100644 index 00000000000..b17ed0aea42 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_cmkkeyvaultproperties.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CmkKeyVaultProperties struct { + KeyUri *string `json:"keyUri,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_crossregionrestoresettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_crossregionrestoresettings.go new file mode 100644 index 00000000000..71637991bdd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_crossregionrestoresettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreSettings struct { + State *CrossRegionRestoreState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_crosssubscriptionrestoresettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_crosssubscriptionrestoresettings.go new file mode 100644 index 00000000000..0e8ba93d082 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_crosssubscriptionrestoresettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossSubscriptionRestoreSettings struct { + State *CrossSubscriptionRestoreState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_dppidentitydetails.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_dppidentitydetails.go new file mode 100644 index 00000000000..88294a548cd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_dppidentitydetails.go @@ -0,0 +1,11 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppIdentityDetails struct { + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Type *string `json:"type,omitempty"` + UserAssignedIdentities *map[string]UserAssignedIdentity `json:"userAssignedIdentities,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_encryptionsettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_encryptionsettings.go new file mode 100644 index 00000000000..89ddfc7332b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_encryptionsettings.go @@ -0,0 +1,11 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionSettings struct { + InfrastructureEncryption *InfrastructureEncryptionState `json:"infrastructureEncryption,omitempty"` + KekIdentity *CmkKekIdentity `json:"kekIdentity,omitempty"` + KeyVaultProperties *CmkKeyVaultProperties `json:"keyVaultProperties,omitempty"` + State *EncryptionState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_featuresettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_featuresettings.go new file mode 100644 index 00000000000..c8981f793c3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_featuresettings.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FeatureSettings struct { + CrossRegionRestoreSettings *CrossRegionRestoreSettings `json:"crossRegionRestoreSettings,omitempty"` + CrossSubscriptionRestoreSettings *CrossSubscriptionRestoreSettings `json:"crossSubscriptionRestoreSettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_immutabilitysettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_immutabilitysettings.go new file mode 100644 index 00000000000..1e8bb471362 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_immutabilitysettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImmutabilitySettings struct { + State *ImmutabilityState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_monitoringsettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_monitoringsettings.go new file mode 100644 index 00000000000..de0fa26a601 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_monitoringsettings.go @@ -0,0 +1,8 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringSettings struct { + AzureMonitorAlertSettings *AzureMonitorAlertSettings `json:"azureMonitorAlertSettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_patchbackupvaultinput.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_patchbackupvaultinput.go new file mode 100644 index 00000000000..19f63cb6049 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_patchbackupvaultinput.go @@ -0,0 +1,11 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchBackupVaultInput struct { + FeatureSettings *FeatureSettings `json:"featureSettings,omitempty"` + MonitoringSettings *MonitoringSettings `json:"monitoringSettings,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + SecuritySettings *SecuritySettings `json:"securitySettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_patchresourcerequestinput.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_patchresourcerequestinput.go new file mode 100644 index 00000000000..09683e7a1d0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_patchresourcerequestinput.go @@ -0,0 +1,10 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchResourceRequestInput struct { + Identity *DppIdentityDetails `json:"identity,omitempty"` + Properties *PatchBackupVaultInput `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_resourcemovedetails.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_resourcemovedetails.go new file mode 100644 index 00000000000..dc459fff005 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_resourcemovedetails.go @@ -0,0 +1,12 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceMoveDetails struct { + CompletionTimeUtc *string `json:"completionTimeUtc,omitempty"` + OperationId *string `json:"operationId,omitempty"` + SourceResourcePath *string `json:"sourceResourcePath,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + TargetResourcePath *string `json:"targetResourcePath,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_securitysettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_securitysettings.go new file mode 100644 index 00000000000..599a66600d9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_securitysettings.go @@ -0,0 +1,10 @@ +package backupvaults + +// 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 { + EncryptionSettings *EncryptionSettings `json:"encryptionSettings,omitempty"` + ImmutabilitySettings *ImmutabilitySettings `json:"immutabilitySettings,omitempty"` + SoftDeleteSettings *SoftDeleteSettings `json:"softDeleteSettings,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_softdeletesettings.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_softdeletesettings.go new file mode 100644 index 00000000000..903e8180d14 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_softdeletesettings.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoftDeleteSettings struct { + RetentionDurationInDays *float64 `json:"retentionDurationInDays,omitempty"` + State *SoftDeleteState `json:"state,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_storagesetting.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_storagesetting.go new file mode 100644 index 00000000000..6112268872b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_storagesetting.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageSetting struct { + DatastoreType *StorageSettingStoreTypes `json:"datastoreType,omitempty"` + Type *StorageSettingTypes `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/model_userassignedidentity.go b/resource-manager/dataprotection/2025-02-01/backupvaults/model_userassignedidentity.go new file mode 100644 index 00000000000..25716effc20 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/model_userassignedidentity.go @@ -0,0 +1,9 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedIdentity struct { + ClientId *string `json:"clientId,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/predicates.go b/resource-manager/dataprotection/2025-02-01/backupvaults/predicates.go new file mode 100644 index 00000000000..04141be33e7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/predicates.go @@ -0,0 +1,37 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupVaultResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p BackupVaultResourceOperationPredicate) Matches(input BackupVaultResource) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dataprotection/2025-02-01/backupvaults/version.go b/resource-manager/dataprotection/2025-02-01/backupvaults/version.go new file mode 100644 index 00000000000..09789a76522 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/backupvaults/version.go @@ -0,0 +1,10 @@ +package backupvaults + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/backupvaults/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/client.go b/resource-manager/dataprotection/2025-02-01/client.go new file mode 100644 index 00000000000..3cbaecf239a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/client.go @@ -0,0 +1,145 @@ +package v2025_02_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/azurebackupjob" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/azurebackupjobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupinstancesextensionrouting" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backuppolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/backupvaults" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/deletedbackupinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppfeaturesupport" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppjob" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/recoverypoint" + "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/resourceguards" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AzureBackupJob *azurebackupjob.AzureBackupJobClient + AzureBackupJobs *azurebackupjobs.AzureBackupJobsClient + BackupInstances *backupinstances.BackupInstancesClient + BackupInstancesExtensionRouting *backupinstancesextensionrouting.BackupInstancesExtensionRoutingClient + BackupPolicies *backuppolicies.BackupPoliciesClient + BackupVaults *backupvaults.BackupVaultsClient + DeletedBackupInstances *deletedbackupinstances.DeletedBackupInstancesClient + DppFeatureSupport *dppfeaturesupport.DppFeatureSupportClient + DppJob *dppjob.DppJobClient + DppResourceGuardProxies *dppresourceguardproxies.DppResourceGuardProxiesClient + FetchSecondaryRecoveryPoints *fetchsecondaryrecoverypoints.FetchSecondaryRecoveryPointsClient + FindRestorableTimeRanges *findrestorabletimeranges.FindRestorableTimeRangesClient + RecoveryPoint *recoverypoint.RecoveryPointClient + ResourceGuards *resourceguards.ResourceGuardsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + azureBackupJobClient, err := azurebackupjob.NewAzureBackupJobClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AzureBackupJob client: %+v", err) + } + configureFunc(azureBackupJobClient.Client) + + azureBackupJobsClient, err := azurebackupjobs.NewAzureBackupJobsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AzureBackupJobs client: %+v", err) + } + configureFunc(azureBackupJobsClient.Client) + + backupInstancesClient, err := backupinstances.NewBackupInstancesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupInstances client: %+v", err) + } + configureFunc(backupInstancesClient.Client) + + backupInstancesExtensionRoutingClient, err := backupinstancesextensionrouting.NewBackupInstancesExtensionRoutingClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupInstancesExtensionRouting client: %+v", err) + } + configureFunc(backupInstancesExtensionRoutingClient.Client) + + backupPoliciesClient, err := backuppolicies.NewBackupPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupPolicies client: %+v", err) + } + configureFunc(backupPoliciesClient.Client) + + backupVaultsClient, err := backupvaults.NewBackupVaultsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupVaults client: %+v", err) + } + configureFunc(backupVaultsClient.Client) + + deletedBackupInstancesClient, err := deletedbackupinstances.NewDeletedBackupInstancesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeletedBackupInstances client: %+v", err) + } + configureFunc(deletedBackupInstancesClient.Client) + + dppFeatureSupportClient, err := dppfeaturesupport.NewDppFeatureSupportClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DppFeatureSupport client: %+v", err) + } + configureFunc(dppFeatureSupportClient.Client) + + dppJobClient, err := dppjob.NewDppJobClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DppJob client: %+v", err) + } + configureFunc(dppJobClient.Client) + + dppResourceGuardProxiesClient, err := dppresourceguardproxies.NewDppResourceGuardProxiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DppResourceGuardProxies client: %+v", err) + } + configureFunc(dppResourceGuardProxiesClient.Client) + + fetchSecondaryRecoveryPointsClient, err := fetchsecondaryrecoverypoints.NewFetchSecondaryRecoveryPointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FetchSecondaryRecoveryPoints client: %+v", err) + } + configureFunc(fetchSecondaryRecoveryPointsClient.Client) + + findRestorableTimeRangesClient, err := findrestorabletimeranges.NewFindRestorableTimeRangesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FindRestorableTimeRanges client: %+v", err) + } + configureFunc(findRestorableTimeRangesClient.Client) + + recoveryPointClient, err := recoverypoint.NewRecoveryPointClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RecoveryPoint client: %+v", err) + } + configureFunc(recoveryPointClient.Client) + + resourceGuardsClient, err := resourceguards.NewResourceGuardsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ResourceGuards client: %+v", err) + } + configureFunc(resourceGuardsClient.Client) + + return &Client{ + AzureBackupJob: azureBackupJobClient, + AzureBackupJobs: azureBackupJobsClient, + BackupInstances: backupInstancesClient, + BackupInstancesExtensionRouting: backupInstancesExtensionRoutingClient, + BackupPolicies: backupPoliciesClient, + BackupVaults: backupVaultsClient, + DeletedBackupInstances: deletedBackupInstancesClient, + DppFeatureSupport: dppFeatureSupportClient, + DppJob: dppJobClient, + DppResourceGuardProxies: dppResourceGuardProxiesClient, + FetchSecondaryRecoveryPoints: fetchSecondaryRecoveryPointsClient, + FindRestorableTimeRanges: findRestorableTimeRangesClient, + RecoveryPoint: recoveryPointClient, + ResourceGuards: resourceGuardsClient, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/README.md b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/README.md new file mode 100644 index 00000000000..6d37cf906fa --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/README.md @@ -0,0 +1,65 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/deletedbackupinstances` Documentation + +The `deletedbackupinstances` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/deletedbackupinstances" +``` + + +### Client Initialization + +```go +client := deletedbackupinstances.NewDeletedBackupInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeletedBackupInstancesClient.Get` + +```go +ctx := context.TODO() +id := deletedbackupinstances.NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "deletedBackupInstanceName") + +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: `DeletedBackupInstancesClient.List` + +```go +ctx := context.TODO() +id := deletedbackupinstances.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +// 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: `DeletedBackupInstancesClient.Undelete` + +```go +ctx := context.TODO() +id := deletedbackupinstances.NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "deletedBackupInstanceName") + +if err := client.UndeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/client.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/client.go new file mode 100644 index 00000000000..65c723446b5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/client.go @@ -0,0 +1,26 @@ +package deletedbackupinstances + +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 DeletedBackupInstancesClient struct { + Client *resourcemanager.Client +} + +func NewDeletedBackupInstancesClientWithBaseURI(sdkApi sdkEnv.Api) (*DeletedBackupInstancesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "deletedbackupinstances", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeletedBackupInstancesClient: %+v", err) + } + + return &DeletedBackupInstancesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/constants.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/constants.go new file mode 100644 index 00000000000..ab825b8b890 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/constants.go @@ -0,0 +1,339 @@ +package deletedbackupinstances + +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 AKSVolumeTypes string + +const ( + AKSVolumeTypesAzureDisk AKSVolumeTypes = "AzureDisk" + AKSVolumeTypesAzureFileShareSMB AKSVolumeTypes = "AzureFileShareSMB" +) + +func PossibleValuesForAKSVolumeTypes() []string { + return []string{ + string(AKSVolumeTypesAzureDisk), + string(AKSVolumeTypesAzureFileShareSMB), + } +} + +func (s *AKSVolumeTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAKSVolumeTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAKSVolumeTypes(input string) (*AKSVolumeTypes, error) { + vals := map[string]AKSVolumeTypes{ + "azuredisk": AKSVolumeTypesAzureDisk, + "azurefilesharesmb": AKSVolumeTypesAzureFileShareSMB, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AKSVolumeTypes(input) + return &out, nil +} + +type CurrentProtectionState string + +const ( + CurrentProtectionStateBackupSchedulesSuspended CurrentProtectionState = "BackupSchedulesSuspended" + CurrentProtectionStateConfiguringProtection CurrentProtectionState = "ConfiguringProtection" + CurrentProtectionStateConfiguringProtectionFailed CurrentProtectionState = "ConfiguringProtectionFailed" + CurrentProtectionStateInvalid CurrentProtectionState = "Invalid" + CurrentProtectionStateNotProtected CurrentProtectionState = "NotProtected" + CurrentProtectionStateProtectionConfigured CurrentProtectionState = "ProtectionConfigured" + CurrentProtectionStateProtectionError CurrentProtectionState = "ProtectionError" + CurrentProtectionStateProtectionStopped CurrentProtectionState = "ProtectionStopped" + CurrentProtectionStateRetentionSchedulesSuspended CurrentProtectionState = "RetentionSchedulesSuspended" + CurrentProtectionStateSoftDeleted CurrentProtectionState = "SoftDeleted" + CurrentProtectionStateSoftDeleting CurrentProtectionState = "SoftDeleting" + CurrentProtectionStateUpdatingProtection CurrentProtectionState = "UpdatingProtection" +) + +func PossibleValuesForCurrentProtectionState() []string { + return []string{ + string(CurrentProtectionStateBackupSchedulesSuspended), + string(CurrentProtectionStateConfiguringProtection), + string(CurrentProtectionStateConfiguringProtectionFailed), + string(CurrentProtectionStateInvalid), + string(CurrentProtectionStateNotProtected), + string(CurrentProtectionStateProtectionConfigured), + string(CurrentProtectionStateProtectionError), + string(CurrentProtectionStateProtectionStopped), + string(CurrentProtectionStateRetentionSchedulesSuspended), + string(CurrentProtectionStateSoftDeleted), + string(CurrentProtectionStateSoftDeleting), + string(CurrentProtectionStateUpdatingProtection), + } +} + +func (s *CurrentProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCurrentProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCurrentProtectionState(input string) (*CurrentProtectionState, error) { + vals := map[string]CurrentProtectionState{ + "backupschedulessuspended": CurrentProtectionStateBackupSchedulesSuspended, + "configuringprotection": CurrentProtectionStateConfiguringProtection, + "configuringprotectionfailed": CurrentProtectionStateConfiguringProtectionFailed, + "invalid": CurrentProtectionStateInvalid, + "notprotected": CurrentProtectionStateNotProtected, + "protectionconfigured": CurrentProtectionStateProtectionConfigured, + "protectionerror": CurrentProtectionStateProtectionError, + "protectionstopped": CurrentProtectionStateProtectionStopped, + "retentionschedulessuspended": CurrentProtectionStateRetentionSchedulesSuspended, + "softdeleted": CurrentProtectionStateSoftDeleted, + "softdeleting": CurrentProtectionStateSoftDeleting, + "updatingprotection": CurrentProtectionStateUpdatingProtection, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CurrentProtectionState(input) + return &out, nil +} + +type DataStoreTypes string + +const ( + DataStoreTypesArchiveStore DataStoreTypes = "ArchiveStore" + DataStoreTypesOperationalStore DataStoreTypes = "OperationalStore" + DataStoreTypesVaultStore DataStoreTypes = "VaultStore" +) + +func PossibleValuesForDataStoreTypes() []string { + return []string{ + string(DataStoreTypesArchiveStore), + string(DataStoreTypesOperationalStore), + string(DataStoreTypesVaultStore), + } +} + +func (s *DataStoreTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataStoreTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataStoreTypes(input string) (*DataStoreTypes, error) { + vals := map[string]DataStoreTypes{ + "archivestore": DataStoreTypesArchiveStore, + "operationalstore": DataStoreTypesOperationalStore, + "vaultstore": DataStoreTypesVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataStoreTypes(input) + return &out, nil +} + +type ResourcePropertiesObjectType string + +const ( + ResourcePropertiesObjectTypeDefaultResourceProperties ResourcePropertiesObjectType = "DefaultResourceProperties" +) + +func PossibleValuesForResourcePropertiesObjectType() []string { + return []string{ + string(ResourcePropertiesObjectTypeDefaultResourceProperties), + } +} + +func (s *ResourcePropertiesObjectType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourcePropertiesObjectType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourcePropertiesObjectType(input string) (*ResourcePropertiesObjectType, error) { + vals := map[string]ResourcePropertiesObjectType{ + "defaultresourceproperties": ResourcePropertiesObjectTypeDefaultResourceProperties, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourcePropertiesObjectType(input) + return &out, nil +} + +type SecretStoreType string + +const ( + SecretStoreTypeAzureKeyVault SecretStoreType = "AzureKeyVault" + SecretStoreTypeInvalid SecretStoreType = "Invalid" +) + +func PossibleValuesForSecretStoreType() []string { + return []string{ + string(SecretStoreTypeAzureKeyVault), + string(SecretStoreTypeInvalid), + } +} + +func (s *SecretStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecretStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecretStoreType(input string) (*SecretStoreType, error) { + vals := map[string]SecretStoreType{ + "azurekeyvault": SecretStoreTypeAzureKeyVault, + "invalid": SecretStoreTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecretStoreType(input) + return &out, nil +} + +type Status string + +const ( + StatusConfiguringProtection Status = "ConfiguringProtection" + StatusConfiguringProtectionFailed Status = "ConfiguringProtectionFailed" + StatusProtectionConfigured Status = "ProtectionConfigured" + StatusProtectionStopped Status = "ProtectionStopped" + StatusSoftDeleted Status = "SoftDeleted" + StatusSoftDeleting Status = "SoftDeleting" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusConfiguringProtection), + string(StatusConfiguringProtectionFailed), + string(StatusProtectionConfigured), + string(StatusProtectionStopped), + string(StatusSoftDeleted), + string(StatusSoftDeleting), + } +} + +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{ + "configuringprotection": StatusConfiguringProtection, + "configuringprotectionfailed": StatusConfiguringProtectionFailed, + "protectionconfigured": StatusProtectionConfigured, + "protectionstopped": StatusProtectionStopped, + "softdeleted": StatusSoftDeleted, + "softdeleting": StatusSoftDeleting, + } + 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 ValidationType string + +const ( + ValidationTypeDeepValidation ValidationType = "DeepValidation" + ValidationTypeShallowValidation ValidationType = "ShallowValidation" +) + +func PossibleValuesForValidationType() []string { + return []string{ + string(ValidationTypeDeepValidation), + string(ValidationTypeShallowValidation), + } +} + +func (s *ValidationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseValidationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseValidationType(input string) (*ValidationType, error) { + vals := map[string]ValidationType{ + "deepvalidation": ValidationTypeDeepValidation, + "shallowvalidation": ValidationTypeShallowValidation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault.go new file mode 100644 index 00000000000..e31a02e04e6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault.go @@ -0,0 +1,130 @@ +package deletedbackupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault_test.go new file mode 100644 index 00000000000..cad24bffff5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_backupvault_test.go @@ -0,0 +1,282 @@ +package deletedbackupinstances + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance.go new file mode 100644 index 00000000000..ebf0ba1b2ed --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance.go @@ -0,0 +1,139 @@ +package deletedbackupinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeletedBackupInstanceId{}) +} + +var _ resourceids.ResourceId = &DeletedBackupInstanceId{} + +// DeletedBackupInstanceId is a struct representing the Resource ID for a Deleted Backup Instance +type DeletedBackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + DeletedBackupInstanceName string +} + +// NewDeletedBackupInstanceID returns a new DeletedBackupInstanceId struct +func NewDeletedBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, deletedBackupInstanceName string) DeletedBackupInstanceId { + return DeletedBackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + DeletedBackupInstanceName: deletedBackupInstanceName, + } +} + +// ParseDeletedBackupInstanceID parses 'input' into a DeletedBackupInstanceId +func ParseDeletedBackupInstanceID(input string) (*DeletedBackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedBackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedBackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedBackupInstanceIDInsensitively parses 'input' case-insensitively into a DeletedBackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseDeletedBackupInstanceIDInsensitively(input string) (*DeletedBackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedBackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedBackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedBackupInstanceId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.DeletedBackupInstanceName, ok = input.Parsed["deletedBackupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedBackupInstanceName", input) + } + + return nil +} + +// ValidateDeletedBackupInstanceID checks that 'input' can be parsed as a Deleted Backup Instance ID +func ValidateDeletedBackupInstanceID(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 := ParseDeletedBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Backup Instance ID +func (id DeletedBackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/deletedBackupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.DeletedBackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Backup Instance ID +func (id DeletedBackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticDeletedBackupInstances", "deletedBackupInstances", "deletedBackupInstances"), + resourceids.UserSpecifiedSegment("deletedBackupInstanceName", "deletedBackupInstanceName"), + } +} + +// String returns a human-readable description of this Deleted Backup Instance ID +func (id DeletedBackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Deleted Backup Instance Name: %q", id.DeletedBackupInstanceName), + } + return fmt.Sprintf("Deleted Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance_test.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance_test.go new file mode 100644 index 00000000000..6c9c0af46dd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/id_deletedbackupinstance_test.go @@ -0,0 +1,327 @@ +package deletedbackupinstances + +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 = &DeletedBackupInstanceId{} + +func TestNewDeletedBackupInstanceID(t *testing.T) { + id := NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "deletedBackupInstanceName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.DeletedBackupInstanceName != "deletedBackupInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedBackupInstanceName'", id.DeletedBackupInstanceName, "deletedBackupInstanceName") + } +} + +func TestFormatDeletedBackupInstanceID(t *testing.T) { + actual := NewDeletedBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "deletedBackupInstanceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances/deletedBackupInstanceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedBackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances/deletedBackupInstanceName", + Expected: &DeletedBackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + DeletedBackupInstanceName: "deletedBackupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances/deletedBackupInstanceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.DeletedBackupInstanceName != v.Expected.DeletedBackupInstanceName { + t.Fatalf("Expected %q but got %q for DeletedBackupInstanceName", v.Expected.DeletedBackupInstanceName, actual.DeletedBackupInstanceName) + } + + } +} + +func TestParseDeletedBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedBackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/dElEtEdBaCkUpInStAnCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances/deletedBackupInstanceName", + Expected: &DeletedBackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + DeletedBackupInstanceName: "deletedBackupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/deletedBackupInstances/deletedBackupInstanceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/dElEtEdBaCkUpInStAnCeS/dElEtEdBaCkUpInStAnCeNaMe", + Expected: &DeletedBackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + DeletedBackupInstanceName: "dElEtEdBaCkUpInStAnCeNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/dElEtEdBaCkUpInStAnCeS/dElEtEdBaCkUpInStAnCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.DeletedBackupInstanceName != v.Expected.DeletedBackupInstanceName { + t.Fatalf("Expected %q but got %q for DeletedBackupInstanceName", v.Expected.DeletedBackupInstanceName, actual.DeletedBackupInstanceName) + } + + } +} + +func TestSegmentsForDeletedBackupInstanceId(t *testing.T) { + segments := DeletedBackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedBackupInstanceId 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/dataprotection/2025-02-01/deletedbackupinstances/method_get.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_get.go new file mode 100644 index 00000000000..d884717c36e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_get.go @@ -0,0 +1,53 @@ +package deletedbackupinstances + +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 *DeletedBackupInstanceResource +} + +// Get ... +func (c DeletedBackupInstancesClient) Get(ctx context.Context, id DeletedBackupInstanceId) (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 DeletedBackupInstanceResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_list.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_list.go new file mode 100644 index 00000000000..8db5448a811 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_list.go @@ -0,0 +1,105 @@ +package deletedbackupinstances + +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 *[]DeletedBackupInstanceResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeletedBackupInstanceResource +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c DeletedBackupInstancesClient) List(ctx context.Context, id BackupVaultId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/deletedBackupInstances", 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 *[]DeletedBackupInstanceResource `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 DeletedBackupInstancesClient) ListComplete(ctx context.Context, id BackupVaultId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DeletedBackupInstanceResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeletedBackupInstancesClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate DeletedBackupInstanceResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DeletedBackupInstanceResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_undelete.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_undelete.go new file mode 100644 index 00000000000..1ab188478a5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/method_undelete.go @@ -0,0 +1,70 @@ +package deletedbackupinstances + +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 UndeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Undelete ... +func (c DeletedBackupInstancesClient) Undelete(ctx context.Context, id DeletedBackupInstanceId) (result UndeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/undelete", 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 +} + +// UndeleteThenPoll performs Undelete then polls until it's completed +func (c DeletedBackupInstancesClient) UndeleteThenPoll(ctx context.Context, id DeletedBackupInstanceId) error { + result, err := c.Undelete(ctx, id) + if err != nil { + return fmt.Errorf("performing Undelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Undelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_adlsblobbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_adlsblobbackupdatasourceparameters.go new file mode 100644 index 00000000000..67c7ccb8113 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_adlsblobbackupdatasourceparameters.go @@ -0,0 +1,50 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = AdlsBlobBackupDatasourceParameters{} + +type AdlsBlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s AdlsBlobBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AdlsBlobBackupDatasourceParameters{} + +func (s AdlsBlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper AdlsBlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "AdlsBlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AdlsBlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_authcredentials.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_authcredentials.go new file mode 100644 index 00000000000..d6ed58bfef7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_authcredentials.go @@ -0,0 +1,75 @@ +package deletedbackupinstances + +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 AuthCredentials interface { + AuthCredentials() BaseAuthCredentialsImpl +} + +var _ AuthCredentials = BaseAuthCredentialsImpl{} + +type BaseAuthCredentialsImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseAuthCredentialsImpl) AuthCredentials() BaseAuthCredentialsImpl { + return s +} + +var _ AuthCredentials = RawAuthCredentialsImpl{} + +// RawAuthCredentialsImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAuthCredentialsImpl struct { + authCredentials BaseAuthCredentialsImpl + Type string + Values map[string]interface{} +} + +func (s RawAuthCredentialsImpl) AuthCredentials() BaseAuthCredentialsImpl { + return s.authCredentials +} + +func UnmarshalAuthCredentialsImplementation(input []byte) (AuthCredentials, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AuthCredentials into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "SecretStoreBasedAuthCredentials") { + var out SecretStoreBasedAuthCredentials + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecretStoreBasedAuthCredentials: %+v", err) + } + return out, nil + } + + var parent BaseAuthCredentialsImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseAuthCredentialsImpl: %+v", err) + } + + return RawAuthCredentialsImpl{ + authCredentials: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_azureoperationalstoreparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_azureoperationalstoreparameters.go new file mode 100644 index 00000000000..34ee2168445 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_azureoperationalstoreparameters.go @@ -0,0 +1,52 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataStoreParameters = AzureOperationalStoreParameters{} + +type AzureOperationalStoreParameters struct { + ResourceGroupId *string `json:"resourceGroupId,omitempty"` + + // Fields inherited from DataStoreParameters + + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} + +func (s AzureOperationalStoreParameters) DataStoreParameters() BaseDataStoreParametersImpl { + return BaseDataStoreParametersImpl{ + DataStoreType: s.DataStoreType, + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureOperationalStoreParameters{} + +func (s AzureOperationalStoreParameters) MarshalJSON() ([]byte, error) { + type wrapper AzureOperationalStoreParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureOperationalStoreParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureOperationalStoreParameters: %+v", err) + } + + decoded["objectType"] = "AzureOperationalStoreParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureOperationalStoreParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_backupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_backupdatasourceparameters.go new file mode 100644 index 00000000000..54d2df9d18d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_backupdatasourceparameters.go @@ -0,0 +1,91 @@ +package deletedbackupinstances + +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 BackupDatasourceParameters interface { + BackupDatasourceParameters() BaseBackupDatasourceParametersImpl +} + +var _ BackupDatasourceParameters = BaseBackupDatasourceParametersImpl{} + +type BaseBackupDatasourceParametersImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseBackupDatasourceParametersImpl) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return s +} + +var _ BackupDatasourceParameters = RawBackupDatasourceParametersImpl{} + +// RawBackupDatasourceParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBackupDatasourceParametersImpl struct { + backupDatasourceParameters BaseBackupDatasourceParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawBackupDatasourceParametersImpl) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return s.backupDatasourceParameters +} + +func UnmarshalBackupDatasourceParametersImplementation(input []byte) (BackupDatasourceParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BackupDatasourceParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AdlsBlobBackupDatasourceParameters") { + var out AdlsBlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AdlsBlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "BlobBackupDatasourceParameters") { + var out BlobBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BlobBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "KubernetesClusterBackupDatasourceParameters") { + var out KubernetesClusterBackupDatasourceParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into KubernetesClusterBackupDatasourceParameters: %+v", err) + } + return out, nil + } + + var parent BaseBackupDatasourceParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBackupDatasourceParametersImpl: %+v", err) + } + + return RawBackupDatasourceParametersImpl{ + backupDatasourceParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_baseresourceproperties.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_baseresourceproperties.go new file mode 100644 index 00000000000..e54dda4681e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_baseresourceproperties.go @@ -0,0 +1,75 @@ +package deletedbackupinstances + +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 BaseResourceProperties interface { + BaseResourceProperties() BaseBaseResourcePropertiesImpl +} + +var _ BaseResourceProperties = BaseBaseResourcePropertiesImpl{} + +type BaseBaseResourcePropertiesImpl struct { + ObjectType ResourcePropertiesObjectType `json:"objectType"` +} + +func (s BaseBaseResourcePropertiesImpl) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return s +} + +var _ BaseResourceProperties = RawBaseResourcePropertiesImpl{} + +// RawBaseResourcePropertiesImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBaseResourcePropertiesImpl struct { + baseResourceProperties BaseBaseResourcePropertiesImpl + Type string + Values map[string]interface{} +} + +func (s RawBaseResourcePropertiesImpl) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return s.baseResourceProperties +} + +func UnmarshalBaseResourcePropertiesImplementation(input []byte) (BaseResourceProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BaseResourceProperties into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "DefaultResourceProperties") { + var out DefaultResourceProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DefaultResourceProperties: %+v", err) + } + return out, nil + } + + var parent BaseBaseResourcePropertiesImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBaseResourcePropertiesImpl: %+v", err) + } + + return RawBaseResourcePropertiesImpl{ + baseResourceProperties: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go new file mode 100644 index 00000000000..8531c83eb0f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_blobbackupdatasourceparameters.go @@ -0,0 +1,50 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = BlobBackupDatasourceParameters{} + +type BlobBackupDatasourceParameters struct { + ContainersList []string `json:"containersList"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s BlobBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = BlobBackupDatasourceParameters{} + +func (s BlobBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper BlobBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BlobBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BlobBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "BlobBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BlobBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasource.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasource.go new file mode 100644 index 00000000000..96f2f21d804 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasource.go @@ -0,0 +1,60 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Datasource struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &Datasource{} + +func (s *Datasource) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling Datasource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := UnmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'Datasource': %+v", err) + } + s.ResourceProperties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasourceset.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasourceset.go new file mode 100644 index 00000000000..eb17c652670 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datasourceset.go @@ -0,0 +1,60 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatasourceSet struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceProperties BaseResourceProperties `json:"resourceProperties"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` +} + +var _ json.Unmarshaler = &DatasourceSet{} + +func (s *DatasourceSet) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DatasourceType *string `json:"datasourceType,omitempty"` + ObjectType *string `json:"objectType,omitempty"` + ResourceID string `json:"resourceID"` + ResourceLocation *string `json:"resourceLocation,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ResourceUri *string `json:"resourceUri,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DatasourceType = decoded.DatasourceType + s.ObjectType = decoded.ObjectType + s.ResourceID = decoded.ResourceID + s.ResourceLocation = decoded.ResourceLocation + s.ResourceName = decoded.ResourceName + s.ResourceType = decoded.ResourceType + s.ResourceUri = decoded.ResourceUri + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DatasourceSet into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["resourceProperties"]; ok { + impl, err := UnmarshalBaseResourcePropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'ResourceProperties' for 'DatasourceSet': %+v", err) + } + s.ResourceProperties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datastoreparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datastoreparameters.go new file mode 100644 index 00000000000..9a1bd25fd85 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_datastoreparameters.go @@ -0,0 +1,76 @@ +package deletedbackupinstances + +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 DataStoreParameters interface { + DataStoreParameters() BaseDataStoreParametersImpl +} + +var _ DataStoreParameters = BaseDataStoreParametersImpl{} + +type BaseDataStoreParametersImpl struct { + DataStoreType DataStoreTypes `json:"dataStoreType"` + ObjectType string `json:"objectType"` +} + +func (s BaseDataStoreParametersImpl) DataStoreParameters() BaseDataStoreParametersImpl { + return s +} + +var _ DataStoreParameters = RawDataStoreParametersImpl{} + +// RawDataStoreParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawDataStoreParametersImpl struct { + dataStoreParameters BaseDataStoreParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawDataStoreParametersImpl) DataStoreParameters() BaseDataStoreParametersImpl { + return s.dataStoreParameters +} + +func UnmarshalDataStoreParametersImplementation(input []byte) (DataStoreParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling DataStoreParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureOperationalStoreParameters") { + var out AzureOperationalStoreParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureOperationalStoreParameters: %+v", err) + } + return out, nil + } + + var parent BaseDataStoreParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseDataStoreParametersImpl: %+v", err) + } + + return RawDataStoreParametersImpl{ + dataStoreParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_defaultresourceproperties.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_defaultresourceproperties.go new file mode 100644 index 00000000000..9ac69e0ad5f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_defaultresourceproperties.go @@ -0,0 +1,49 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BaseResourceProperties = DefaultResourceProperties{} + +type DefaultResourceProperties struct { + + // Fields inherited from BaseResourceProperties + + ObjectType ResourcePropertiesObjectType `json:"objectType"` +} + +func (s DefaultResourceProperties) BaseResourceProperties() BaseBaseResourcePropertiesImpl { + return BaseBaseResourcePropertiesImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = DefaultResourceProperties{} + +func (s DefaultResourceProperties) MarshalJSON() ([]byte, error) { + type wrapper DefaultResourceProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DefaultResourceProperties: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DefaultResourceProperties: %+v", err) + } + + decoded["objectType"] = "DefaultResourceProperties" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DefaultResourceProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstance.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstance.go new file mode 100644 index 00000000000..db69d204f62 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstance.go @@ -0,0 +1,78 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedBackupInstance struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + DatasourceAuthCredentials AuthCredentials `json:"datasourceAuthCredentials"` + DeletionInfo *DeletionInfo `json:"deletionInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` +} + +var _ json.Unmarshaler = &DeletedBackupInstance{} + +func (s *DeletedBackupInstance) UnmarshalJSON(bytes []byte) error { + var decoded struct { + CurrentProtectionState *CurrentProtectionState `json:"currentProtectionState,omitempty"` + DataSourceInfo Datasource `json:"dataSourceInfo"` + DataSourceSetInfo *DatasourceSet `json:"dataSourceSetInfo,omitempty"` + DeletionInfo *DeletionInfo `json:"deletionInfo,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IdentityDetails *IdentityDetails `json:"identityDetails,omitempty"` + ObjectType string `json:"objectType"` + PolicyInfo PolicyInfo `json:"policyInfo"` + ProtectionErrorDetails *UserFacingError `json:"protectionErrorDetails,omitempty"` + ProtectionStatus *ProtectionStatusDetails `json:"protectionStatus,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ValidationType *ValidationType `json:"validationType,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.CurrentProtectionState = decoded.CurrentProtectionState + s.DataSourceInfo = decoded.DataSourceInfo + s.DataSourceSetInfo = decoded.DataSourceSetInfo + s.DeletionInfo = decoded.DeletionInfo + s.FriendlyName = decoded.FriendlyName + s.IdentityDetails = decoded.IdentityDetails + s.ObjectType = decoded.ObjectType + s.PolicyInfo = decoded.PolicyInfo + s.ProtectionErrorDetails = decoded.ProtectionErrorDetails + s.ProtectionStatus = decoded.ProtectionStatus + s.ProvisioningState = decoded.ProvisioningState + s.ResourceGuardOperationRequests = decoded.ResourceGuardOperationRequests + s.ValidationType = decoded.ValidationType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling DeletedBackupInstance into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["datasourceAuthCredentials"]; ok { + impl, err := UnmarshalAuthCredentialsImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'DatasourceAuthCredentials' for 'DeletedBackupInstance': %+v", err) + } + s.DatasourceAuthCredentials = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstanceresource.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstanceresource.go new file mode 100644 index 00000000000..9d4b9f116ec --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletedbackupinstanceresource.go @@ -0,0 +1,16 @@ +package deletedbackupinstances + +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 DeletedBackupInstanceResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeletedBackupInstance `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletioninfo.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletioninfo.go new file mode 100644 index 00000000000..e01dc7d9b15 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_deletioninfo.go @@ -0,0 +1,11 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletionInfo struct { + BillingEndDate *string `json:"billingEndDate,omitempty"` + DeleteActivityID *string `json:"deleteActivityID,omitempty"` + DeletionTime *string `json:"deletionTime,omitempty"` + ScheduledPurgeTime *string `json:"scheduledPurgeTime,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_identitydetails.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_identitydetails.go new file mode 100644 index 00000000000..630b05d040e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_identitydetails.go @@ -0,0 +1,9 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityDetails struct { + UseSystemAssignedIdentity *bool `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentityArmURL *string `json:"userAssignedIdentityArmUrl,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_innererror.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_innererror.go new file mode 100644 index 00000000000..e59cb1caa0f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_innererror.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go new file mode 100644 index 00000000000..ac9b02475a7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_kubernetesclusterbackupdatasourceparameters.go @@ -0,0 +1,58 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BackupDatasourceParameters = KubernetesClusterBackupDatasourceParameters{} + +type KubernetesClusterBackupDatasourceParameters struct { + BackupHookReferences *[]NamespacedNameResource `json:"backupHookReferences,omitempty"` + ExcludedNamespaces *[]string `json:"excludedNamespaces,omitempty"` + ExcludedResourceTypes *[]string `json:"excludedResourceTypes,omitempty"` + IncludeClusterScopeResources bool `json:"includeClusterScopeResources"` + IncludedNamespaces *[]string `json:"includedNamespaces,omitempty"` + IncludedResourceTypes *[]string `json:"includedResourceTypes,omitempty"` + IncludedVolumeTypes *[]AKSVolumeTypes `json:"includedVolumeTypes,omitempty"` + LabelSelectors *[]string `json:"labelSelectors,omitempty"` + SnapshotVolumes bool `json:"snapshotVolumes"` + + // Fields inherited from BackupDatasourceParameters + + ObjectType string `json:"objectType"` +} + +func (s KubernetesClusterBackupDatasourceParameters) BackupDatasourceParameters() BaseBackupDatasourceParametersImpl { + return BaseBackupDatasourceParametersImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = KubernetesClusterBackupDatasourceParameters{} + +func (s KubernetesClusterBackupDatasourceParameters) MarshalJSON() ([]byte, error) { + type wrapper KubernetesClusterBackupDatasourceParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + decoded["objectType"] = "KubernetesClusterBackupDatasourceParameters" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling KubernetesClusterBackupDatasourceParameters: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_namespacednameresource.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_namespacednameresource.go new file mode 100644 index 00000000000..70d84cc64c6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_namespacednameresource.go @@ -0,0 +1,9 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NamespacedNameResource struct { + Name *string `json:"name,omitempty"` + Namespace *string `json:"namespace,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyinfo.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyinfo.go new file mode 100644 index 00000000000..0ab008c3307 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyinfo.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyInfo struct { + PolicyId string `json:"policyId"` + PolicyParameters *PolicyParameters `json:"policyParameters,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyparameters.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyparameters.go new file mode 100644 index 00000000000..9e6a8feeabe --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_policyparameters.go @@ -0,0 +1,60 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyParameters struct { + BackupDatasourceParametersList *[]BackupDatasourceParameters `json:"backupDatasourceParametersList,omitempty"` + DataStoreParametersList *[]DataStoreParameters `json:"dataStoreParametersList,omitempty"` +} + +var _ json.Unmarshaler = &PolicyParameters{} + +func (s *PolicyParameters) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling PolicyParameters into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["backupDatasourceParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling BackupDatasourceParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]BackupDatasourceParameters, 0) + for i, val := range listTemp { + impl, err := UnmarshalBackupDatasourceParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'BackupDatasourceParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.BackupDatasourceParametersList = &output + } + + if v, ok := temp["dataStoreParametersList"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling DataStoreParametersList into list []json.RawMessage: %+v", err) + } + + output := make([]DataStoreParameters, 0) + for i, val := range listTemp { + impl, err := UnmarshalDataStoreParametersImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'DataStoreParametersList' for 'PolicyParameters': %+v", i, err) + } + output = append(output, impl) + } + s.DataStoreParametersList = &output + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_protectionstatusdetails.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_protectionstatusdetails.go new file mode 100644 index 00000000000..27e9741b405 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_protectionstatusdetails.go @@ -0,0 +1,9 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProtectionStatusDetails struct { + ErrorDetails *UserFacingError `json:"errorDetails,omitempty"` + Status *Status `json:"status,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go new file mode 100644 index 00000000000..baef7fd69ef --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstorebasedauthcredentials.go @@ -0,0 +1,50 @@ +package deletedbackupinstances + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AuthCredentials = SecretStoreBasedAuthCredentials{} + +type SecretStoreBasedAuthCredentials struct { + SecretStoreResource *SecretStoreResource `json:"secretStoreResource,omitempty"` + + // Fields inherited from AuthCredentials + + ObjectType string `json:"objectType"` +} + +func (s SecretStoreBasedAuthCredentials) AuthCredentials() BaseAuthCredentialsImpl { + return BaseAuthCredentialsImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = SecretStoreBasedAuthCredentials{} + +func (s SecretStoreBasedAuthCredentials) MarshalJSON() ([]byte, error) { + type wrapper SecretStoreBasedAuthCredentials + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + decoded["objectType"] = "SecretStoreBasedAuthCredentials" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecretStoreBasedAuthCredentials: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstoreresource.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstoreresource.go new file mode 100644 index 00000000000..940322a2821 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_secretstoreresource.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretStoreResource struct { + SecretStoreType SecretStoreType `json:"secretStoreType"` + Uri *string `json:"uri,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_userfacingerror.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_userfacingerror.go new file mode 100644 index 00000000000..db9ffc175f6 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/model_userfacingerror.go @@ -0,0 +1,16 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/predicates.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/predicates.go new file mode 100644 index 00000000000..d7c6585786d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/predicates.go @@ -0,0 +1,27 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedBackupInstanceResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DeletedBackupInstanceResourceOperationPredicate) Matches(input DeletedBackupInstanceResource) 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/dataprotection/2025-02-01/deletedbackupinstances/version.go b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/version.go new file mode 100644 index 00000000000..ed5101e6f4e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/deletedbackupinstances/version.go @@ -0,0 +1,10 @@ +package deletedbackupinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/deletedbackupinstances/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/README.md b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/README.md new file mode 100644 index 00000000000..f0c0793e1b7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppfeaturesupport` Documentation + +The `dppfeaturesupport` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppfeaturesupport" +``` + + +### Client Initialization + +```go +client := dppfeaturesupport.NewDppFeatureSupportClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DppFeatureSupportClient.DataProtectionCheckFeatureSupport` + +```go +ctx := context.TODO() +id := dppfeaturesupport.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +payload := dppfeaturesupport.FeatureValidationRequestBase{ + // ... +} + + +read, err := client.DataProtectionCheckFeatureSupport(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/dataprotection/2025-02-01/dppfeaturesupport/client.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/client.go new file mode 100644 index 00000000000..01ef8c69f05 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/client.go @@ -0,0 +1,26 @@ +package dppfeaturesupport + +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 DppFeatureSupportClient struct { + Client *resourcemanager.Client +} + +func NewDppFeatureSupportClientWithBaseURI(sdkApi sdkEnv.Api) (*DppFeatureSupportClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "dppfeaturesupport", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DppFeatureSupportClient: %+v", err) + } + + return &DppFeatureSupportClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/constants.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/constants.go new file mode 100644 index 00000000000..91dae34ba66 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/constants.go @@ -0,0 +1,104 @@ +package dppfeaturesupport + +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 FeatureSupportStatus string + +const ( + FeatureSupportStatusAlphaPreview FeatureSupportStatus = "AlphaPreview" + FeatureSupportStatusGenerallyAvailable FeatureSupportStatus = "GenerallyAvailable" + FeatureSupportStatusInvalid FeatureSupportStatus = "Invalid" + FeatureSupportStatusNotSupported FeatureSupportStatus = "NotSupported" + FeatureSupportStatusPrivatePreview FeatureSupportStatus = "PrivatePreview" + FeatureSupportStatusPublicPreview FeatureSupportStatus = "PublicPreview" +) + +func PossibleValuesForFeatureSupportStatus() []string { + return []string{ + string(FeatureSupportStatusAlphaPreview), + string(FeatureSupportStatusGenerallyAvailable), + string(FeatureSupportStatusInvalid), + string(FeatureSupportStatusNotSupported), + string(FeatureSupportStatusPrivatePreview), + string(FeatureSupportStatusPublicPreview), + } +} + +func (s *FeatureSupportStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFeatureSupportStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFeatureSupportStatus(input string) (*FeatureSupportStatus, error) { + vals := map[string]FeatureSupportStatus{ + "alphapreview": FeatureSupportStatusAlphaPreview, + "generallyavailable": FeatureSupportStatusGenerallyAvailable, + "invalid": FeatureSupportStatusInvalid, + "notsupported": FeatureSupportStatusNotSupported, + "privatepreview": FeatureSupportStatusPrivatePreview, + "publicpreview": FeatureSupportStatusPublicPreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FeatureSupportStatus(input) + return &out, nil +} + +type FeatureType string + +const ( + FeatureTypeDataSourceType FeatureType = "DataSourceType" + FeatureTypeInvalid FeatureType = "Invalid" +) + +func PossibleValuesForFeatureType() []string { + return []string{ + string(FeatureTypeDataSourceType), + string(FeatureTypeInvalid), + } +} + +func (s *FeatureType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFeatureType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFeatureType(input string) (*FeatureType, error) { + vals := map[string]FeatureType{ + "datasourcetype": FeatureTypeDataSourceType, + "invalid": FeatureTypeInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FeatureType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location.go new file mode 100644 index 00000000000..5d4454ffdcc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location.go @@ -0,0 +1,121 @@ +package dppfeaturesupport + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location_test.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location_test.go new file mode 100644 index 00000000000..3f55e63451d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/id_location_test.go @@ -0,0 +1,237 @@ +package dppfeaturesupport + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/dataprotection/2025-02-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go new file mode 100644 index 00000000000..eae58cdc096 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/method_dataprotectioncheckfeaturesupport.go @@ -0,0 +1,63 @@ +package dppfeaturesupport + +import ( + "context" + "encoding/json" + "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 DataProtectionCheckFeatureSupportOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model FeatureValidationResponseBase +} + +// DataProtectionCheckFeatureSupport ... +func (c DppFeatureSupportClient) DataProtectionCheckFeatureSupport(ctx context.Context, id LocationId, input FeatureValidationRequestBase) (result DataProtectionCheckFeatureSupportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkFeatureSupport", 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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := UnmarshalFeatureValidationResponseBaseImplementation(respObj) + if err != nil { + return + } + result.Model = model + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequest.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequest.go new file mode 100644 index 00000000000..1c4657b517a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequest.go @@ -0,0 +1,51 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ FeatureValidationRequestBase = FeatureValidationRequest{} + +type FeatureValidationRequest struct { + FeatureName *string `json:"featureName,omitempty"` + FeatureType *FeatureType `json:"featureType,omitempty"` + + // Fields inherited from FeatureValidationRequestBase + + ObjectType string `json:"objectType"` +} + +func (s FeatureValidationRequest) FeatureValidationRequestBase() BaseFeatureValidationRequestBaseImpl { + return BaseFeatureValidationRequestBaseImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = FeatureValidationRequest{} + +func (s FeatureValidationRequest) MarshalJSON() ([]byte, error) { + type wrapper FeatureValidationRequest + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FeatureValidationRequest: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationRequest: %+v", err) + } + + decoded["objectType"] = "FeatureValidationRequest" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FeatureValidationRequest: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequestbase.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequestbase.go new file mode 100644 index 00000000000..21d79f26bf4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationrequestbase.go @@ -0,0 +1,75 @@ +package dppfeaturesupport + +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 FeatureValidationRequestBase interface { + FeatureValidationRequestBase() BaseFeatureValidationRequestBaseImpl +} + +var _ FeatureValidationRequestBase = BaseFeatureValidationRequestBaseImpl{} + +type BaseFeatureValidationRequestBaseImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseFeatureValidationRequestBaseImpl) FeatureValidationRequestBase() BaseFeatureValidationRequestBaseImpl { + return s +} + +var _ FeatureValidationRequestBase = RawFeatureValidationRequestBaseImpl{} + +// RawFeatureValidationRequestBaseImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawFeatureValidationRequestBaseImpl struct { + featureValidationRequestBase BaseFeatureValidationRequestBaseImpl + Type string + Values map[string]interface{} +} + +func (s RawFeatureValidationRequestBaseImpl) FeatureValidationRequestBase() BaseFeatureValidationRequestBaseImpl { + return s.featureValidationRequestBase +} + +func UnmarshalFeatureValidationRequestBaseImplementation(input []byte) (FeatureValidationRequestBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationRequestBase into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "FeatureValidationRequest") { + var out FeatureValidationRequest + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FeatureValidationRequest: %+v", err) + } + return out, nil + } + + var parent BaseFeatureValidationRequestBaseImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseFeatureValidationRequestBaseImpl: %+v", err) + } + + return RawFeatureValidationRequestBaseImpl{ + featureValidationRequestBase: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponse.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponse.go new file mode 100644 index 00000000000..05506b82ee9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponse.go @@ -0,0 +1,51 @@ +package dppfeaturesupport + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ FeatureValidationResponseBase = FeatureValidationResponse{} + +type FeatureValidationResponse struct { + FeatureType *FeatureType `json:"featureType,omitempty"` + Features *[]SupportedFeature `json:"features,omitempty"` + + // Fields inherited from FeatureValidationResponseBase + + ObjectType string `json:"objectType"` +} + +func (s FeatureValidationResponse) FeatureValidationResponseBase() BaseFeatureValidationResponseBaseImpl { + return BaseFeatureValidationResponseBaseImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = FeatureValidationResponse{} + +func (s FeatureValidationResponse) MarshalJSON() ([]byte, error) { + type wrapper FeatureValidationResponse + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FeatureValidationResponse: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationResponse: %+v", err) + } + + decoded["objectType"] = "FeatureValidationResponse" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FeatureValidationResponse: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponsebase.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponsebase.go new file mode 100644 index 00000000000..bc5d4d26cd0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_featurevalidationresponsebase.go @@ -0,0 +1,75 @@ +package dppfeaturesupport + +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 FeatureValidationResponseBase interface { + FeatureValidationResponseBase() BaseFeatureValidationResponseBaseImpl +} + +var _ FeatureValidationResponseBase = BaseFeatureValidationResponseBaseImpl{} + +type BaseFeatureValidationResponseBaseImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseFeatureValidationResponseBaseImpl) FeatureValidationResponseBase() BaseFeatureValidationResponseBaseImpl { + return s +} + +var _ FeatureValidationResponseBase = RawFeatureValidationResponseBaseImpl{} + +// RawFeatureValidationResponseBaseImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawFeatureValidationResponseBaseImpl struct { + featureValidationResponseBase BaseFeatureValidationResponseBaseImpl + Type string + Values map[string]interface{} +} + +func (s RawFeatureValidationResponseBaseImpl) FeatureValidationResponseBase() BaseFeatureValidationResponseBaseImpl { + return s.featureValidationResponseBase +} + +func UnmarshalFeatureValidationResponseBaseImplementation(input []byte) (FeatureValidationResponseBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling FeatureValidationResponseBase into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "FeatureValidationResponse") { + var out FeatureValidationResponse + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FeatureValidationResponse: %+v", err) + } + return out, nil + } + + var parent BaseFeatureValidationResponseBaseImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseFeatureValidationResponseBaseImpl: %+v", err) + } + + return RawFeatureValidationResponseBaseImpl{ + featureValidationResponseBase: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_supportedfeature.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_supportedfeature.go new file mode 100644 index 00000000000..f32f28b1b2c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/model_supportedfeature.go @@ -0,0 +1,10 @@ +package dppfeaturesupport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedFeature struct { + ExposureControlledFeatures *[]string `json:"exposureControlledFeatures,omitempty"` + FeatureName *string `json:"featureName,omitempty"` + SupportStatus *FeatureSupportStatus `json:"supportStatus,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/version.go b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/version.go new file mode 100644 index 00000000000..3ad2ef14af3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppfeaturesupport/version.go @@ -0,0 +1,10 @@ +package dppfeaturesupport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/dppfeaturesupport/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/README.md b/resource-manager/dataprotection/2025-02-01/dppjob/README.md new file mode 100644 index 00000000000..9b6f9870ed2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/README.md @@ -0,0 +1,63 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppjob` Documentation + +The `dppjob` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppjob" +``` + + +### Client Initialization + +```go +client := dppjob.NewDppJobClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DppJobClient.FetchCrossRegionRestoreJobGet` + +```go +ctx := context.TODO() +id := dppjob.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +payload := dppjob.CrossRegionRestoreJobRequest{ + // ... +} + + +read, err := client.FetchCrossRegionRestoreJobGet(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppJobClient.FetchCrossRegionRestoreJobsList` + +```go +ctx := context.TODO() +id := dppjob.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +payload := dppjob.CrossRegionRestoreJobsRequest{ + // ... +} + + +// alternatively `client.FetchCrossRegionRestoreJobsList(ctx, id, payload, dppjob.DefaultFetchCrossRegionRestoreJobsListOperationOptions())` can be used to do batched pagination +items, err := client.FetchCrossRegionRestoreJobsListComplete(ctx, id, payload, dppjob.DefaultFetchCrossRegionRestoreJobsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/client.go b/resource-manager/dataprotection/2025-02-01/dppjob/client.go new file mode 100644 index 00000000000..d492231a2c4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/client.go @@ -0,0 +1,26 @@ +package dppjob + +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 DppJobClient struct { + Client *resourcemanager.Client +} + +func NewDppJobClientWithBaseURI(sdkApi sdkEnv.Api) (*DppJobClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "dppjob", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DppJobClient: %+v", err) + } + + return &DppJobClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation.go b/resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation.go new file mode 100644 index 00000000000..bd5fbb2e23c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation.go @@ -0,0 +1,130 @@ +package dppjob + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation_test.go b/resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation_test.go new file mode 100644 index 00000000000..72d16fa5fe3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package dppjob + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobget.go b/resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobget.go new file mode 100644 index 00000000000..2e95534048b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobget.go @@ -0,0 +1,58 @@ +package dppjob + +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 FetchCrossRegionRestoreJobGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupJobResource +} + +// FetchCrossRegionRestoreJobGet ... +func (c DppJobClient) FetchCrossRegionRestoreJobGet(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobRequest) (result FetchCrossRegionRestoreJobGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/fetchCrossRegionRestoreJob", 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 AzureBackupJobResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobslist.go b/resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobslist.go new file mode 100644 index 00000000000..46b0baf9b3a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/method_fetchcrossregionrestorejobslist.go @@ -0,0 +1,134 @@ +package dppjob + +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 FetchCrossRegionRestoreJobsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureBackupJobResource +} + +type FetchCrossRegionRestoreJobsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureBackupJobResource +} + +type FetchCrossRegionRestoreJobsListOperationOptions struct { + Filter *string +} + +func DefaultFetchCrossRegionRestoreJobsListOperationOptions() FetchCrossRegionRestoreJobsListOperationOptions { + return FetchCrossRegionRestoreJobsListOperationOptions{} +} + +func (o FetchCrossRegionRestoreJobsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o FetchCrossRegionRestoreJobsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o FetchCrossRegionRestoreJobsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type FetchCrossRegionRestoreJobsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *FetchCrossRegionRestoreJobsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// FetchCrossRegionRestoreJobsList ... +func (c DppJobClient) FetchCrossRegionRestoreJobsList(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobsRequest, options FetchCrossRegionRestoreJobsListOperationOptions) (result FetchCrossRegionRestoreJobsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &FetchCrossRegionRestoreJobsListCustomPager{}, + Path: fmt.Sprintf("%s/fetchCrossRegionRestoreJobs", 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 *[]AzureBackupJobResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// FetchCrossRegionRestoreJobsListComplete retrieves all the results into a single object +func (c DppJobClient) FetchCrossRegionRestoreJobsListComplete(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobsRequest, options FetchCrossRegionRestoreJobsListOperationOptions) (FetchCrossRegionRestoreJobsListCompleteResult, error) { + return c.FetchCrossRegionRestoreJobsListCompleteMatchingPredicate(ctx, id, input, options, AzureBackupJobResourceOperationPredicate{}) +} + +// FetchCrossRegionRestoreJobsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DppJobClient) FetchCrossRegionRestoreJobsListCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, input CrossRegionRestoreJobsRequest, options FetchCrossRegionRestoreJobsListOperationOptions, predicate AzureBackupJobResourceOperationPredicate) (result FetchCrossRegionRestoreJobsListCompleteResult, err error) { + items := make([]AzureBackupJobResource, 0) + + resp, err := c.FetchCrossRegionRestoreJobsList(ctx, id, input, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = FetchCrossRegionRestoreJobsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjob.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjob.go new file mode 100644 index 00000000000..32eeb40d251 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjob.go @@ -0,0 +1,65 @@ +package dppjob + +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 AzureBackupJob struct { + ActivityID string `json:"activityID"` + BackupInstanceFriendlyName string `json:"backupInstanceFriendlyName"` + BackupInstanceId *string `json:"backupInstanceId,omitempty"` + DataSourceId string `json:"dataSourceId"` + DataSourceLocation string `json:"dataSourceLocation"` + DataSourceName string `json:"dataSourceName"` + DataSourceSetName *string `json:"dataSourceSetName,omitempty"` + DataSourceType string `json:"dataSourceType"` + DestinationDataStoreName *string `json:"destinationDataStoreName,omitempty"` + Duration *string `json:"duration,omitempty"` + EndTime *string `json:"endTime,omitempty"` + ErrorDetails *[]UserFacingError `json:"errorDetails,omitempty"` + Etag *string `json:"etag,omitempty"` + ExtendedInfo *JobExtendedInfo `json:"extendedInfo,omitempty"` + IsUserTriggered bool `json:"isUserTriggered"` + Operation string `json:"operation"` + OperationCategory string `json:"operationCategory"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + ProgressEnabled bool `json:"progressEnabled"` + ProgressURL *string `json:"progressUrl,omitempty"` + RehydrationPriority *string `json:"rehydrationPriority,omitempty"` + RestoreType *string `json:"restoreType,omitempty"` + SourceDataStoreName *string `json:"sourceDataStoreName,omitempty"` + SourceResourceGroup string `json:"sourceResourceGroup"` + SourceSubscriptionID string `json:"sourceSubscriptionID"` + StartTime string `json:"startTime"` + Status string `json:"status"` + SubscriptionId string `json:"subscriptionId"` + SupportedActions []string `json:"supportedActions"` + VaultName string `json:"vaultName"` +} + +func (o *AzureBackupJob) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *AzureBackupJob) GetStartTimeAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureBackupJob) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjobresource.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjobresource.go new file mode 100644 index 00000000000..51c24fa7f16 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_azurebackupjobresource.go @@ -0,0 +1,16 @@ +package dppjob + +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 AzureBackupJobResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupJob `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobrequest.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobrequest.go new file mode 100644 index 00000000000..a1c23f023e2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobrequest.go @@ -0,0 +1,10 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreJobRequest struct { + JobId string `json:"jobId"` + SourceBackupVaultId string `json:"sourceBackupVaultId"` + SourceRegion string `json:"sourceRegion"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobsrequest.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobsrequest.go new file mode 100644 index 00000000000..a75015188e1 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_crossregionrestorejobsrequest.go @@ -0,0 +1,9 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CrossRegionRestoreJobsRequest struct { + SourceBackupVaultId string `json:"sourceBackupVaultId"` + SourceRegion string `json:"sourceRegion"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_innererror.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_innererror.go new file mode 100644 index 00000000000..cc4341695b4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_innererror.go @@ -0,0 +1,10 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + AdditionalInfo *map[string]string `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + EmbeddedInnerError *InnerError `json:"embeddedInnerError,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_jobextendedinfo.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_jobextendedinfo.go new file mode 100644 index 00000000000..92a9c42ff56 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_jobextendedinfo.go @@ -0,0 +1,15 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExtendedInfo struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + BackupInstanceState *string `json:"backupInstanceState,omitempty"` + DataTransferredInBytes *float64 `json:"dataTransferredInBytes,omitempty"` + RecoveryDestination *string `json:"recoveryDestination,omitempty"` + SourceRecoverPoint *RestoreJobRecoveryPointDetails `json:"sourceRecoverPoint,omitempty"` + SubTasks *[]JobSubTask `json:"subTasks,omitempty"` + TargetRecoverPoint *RestoreJobRecoveryPointDetails `json:"targetRecoverPoint,omitempty"` + WarningDetails *[]UserFacingWarningDetail `json:"warningDetails,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_jobsubtask.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_jobsubtask.go new file mode 100644 index 00000000000..e329c0eadda --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_jobsubtask.go @@ -0,0 +1,12 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobSubTask struct { + AdditionalDetails *map[string]string `json:"additionalDetails,omitempty"` + TaskId int64 `json:"taskId"` + TaskName string `json:"taskName"` + TaskProgress *string `json:"taskProgress,omitempty"` + TaskStatus string `json:"taskStatus"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_restorejobrecoverypointdetails.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_restorejobrecoverypointdetails.go new file mode 100644 index 00000000000..10f708f3acd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_restorejobrecoverypointdetails.go @@ -0,0 +1,27 @@ +package dppjob + +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 RestoreJobRecoveryPointDetails struct { + RecoveryPointID *string `json:"recoveryPointID,omitempty"` + RecoveryPointTime *string `json:"recoveryPointTime,omitempty"` +} + +func (o *RestoreJobRecoveryPointDetails) GetRecoveryPointTimeAsTime() (*time.Time, error) { + if o.RecoveryPointTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RecoveryPointTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoreJobRecoveryPointDetails) SetRecoveryPointTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RecoveryPointTime = &formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingerror.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingerror.go new file mode 100644 index 00000000000..d2f0c3f3043 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingerror.go @@ -0,0 +1,16 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingError struct { + Code *string `json:"code,omitempty"` + Details *[]UserFacingError `json:"details,omitempty"` + InnerError *InnerError `json:"innerError,omitempty"` + IsRetryable *bool `json:"isRetryable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Message *string `json:"message,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + RecommendedAction *[]string `json:"recommendedAction,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingwarningdetail.go b/resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingwarningdetail.go new file mode 100644 index 00000000000..f398426c80d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/model_userfacingwarningdetail.go @@ -0,0 +1,9 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserFacingWarningDetail struct { + ResourceName *string `json:"resourceName,omitempty"` + Warning UserFacingError `json:"warning"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppjob/predicates.go b/resource-manager/dataprotection/2025-02-01/dppjob/predicates.go new file mode 100644 index 00000000000..3a5fc03f205 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/predicates.go @@ -0,0 +1,27 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupJobResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupJobResourceOperationPredicate) Matches(input AzureBackupJobResource) 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/dataprotection/2025-02-01/dppjob/version.go b/resource-manager/dataprotection/2025-02-01/dppjob/version.go new file mode 100644 index 00000000000..f51e75055fc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppjob/version.go @@ -0,0 +1,10 @@ +package dppjob + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/dppjob/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/README.md b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/README.md new file mode 100644 index 00000000000..70cdd9f96af --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies` Documentation + +The `dppresourceguardproxies` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies" +``` + + +### Client Initialization + +```go +client := dppresourceguardproxies.NewDppResourceGuardProxiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyCreateOrUpdate` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupResourceGuardProxyName") + +payload := dppresourceguardproxies.ResourceGuardProxyBaseResource{ + // ... +} + + +read, err := client.DppResourceGuardProxyCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyDelete` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupResourceGuardProxyName") + +read, err := client.DppResourceGuardProxyDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyGet` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupResourceGuardProxyName") + +read, err := client.DppResourceGuardProxyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyList` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + +// alternatively `client.DppResourceGuardProxyList(ctx, id)` can be used to do batched pagination +items, err := client.DppResourceGuardProxyListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DppResourceGuardProxiesClient.DppResourceGuardProxyUnlockDelete` + +```go +ctx := context.TODO() +id := dppresourceguardproxies.NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupResourceGuardProxyName") + +payload := dppresourceguardproxies.UnlockDeleteRequest{ + // ... +} + + +read, err := client.DppResourceGuardProxyUnlockDelete(ctx, id, payload, dppresourceguardproxies.DefaultDppResourceGuardProxyUnlockDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/client.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/client.go new file mode 100644 index 00000000000..d0374e7e5bc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/client.go @@ -0,0 +1,26 @@ +package dppresourceguardproxies + +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 DppResourceGuardProxiesClient struct { + Client *resourcemanager.Client +} + +func NewDppResourceGuardProxiesClientWithBaseURI(sdkApi sdkEnv.Api) (*DppResourceGuardProxiesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "dppresourceguardproxies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DppResourceGuardProxiesClient: %+v", err) + } + + return &DppResourceGuardProxiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy.go new file mode 100644 index 00000000000..6f7a531c0ca --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy.go @@ -0,0 +1,139 @@ +package dppresourceguardproxies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupResourceGuardProxyId{}) +} + +var _ resourceids.ResourceId = &BackupResourceGuardProxyId{} + +// BackupResourceGuardProxyId is a struct representing the Resource ID for a Backup Resource Guard Proxy +type BackupResourceGuardProxyId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupResourceGuardProxyName string +} + +// NewBackupResourceGuardProxyID returns a new BackupResourceGuardProxyId struct +func NewBackupResourceGuardProxyID(subscriptionId string, resourceGroupName string, backupVaultName string, backupResourceGuardProxyName string) BackupResourceGuardProxyId { + return BackupResourceGuardProxyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupResourceGuardProxyName: backupResourceGuardProxyName, + } +} + +// ParseBackupResourceGuardProxyID parses 'input' into a BackupResourceGuardProxyId +func ParseBackupResourceGuardProxyID(input string) (*BackupResourceGuardProxyId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupResourceGuardProxyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupResourceGuardProxyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupResourceGuardProxyIDInsensitively parses 'input' case-insensitively into a BackupResourceGuardProxyId +// note: this method should only be used for API response data and not user input +func ParseBackupResourceGuardProxyIDInsensitively(input string) (*BackupResourceGuardProxyId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupResourceGuardProxyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupResourceGuardProxyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupResourceGuardProxyId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupResourceGuardProxyName, ok = input.Parsed["backupResourceGuardProxyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupResourceGuardProxyName", input) + } + + return nil +} + +// ValidateBackupResourceGuardProxyID checks that 'input' can be parsed as a Backup Resource Guard Proxy ID +func ValidateBackupResourceGuardProxyID(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 := ParseBackupResourceGuardProxyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Resource Guard Proxy ID +func (id BackupResourceGuardProxyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupResourceGuardProxies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupResourceGuardProxyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Resource Guard Proxy ID +func (id BackupResourceGuardProxyId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupResourceGuardProxies", "backupResourceGuardProxies", "backupResourceGuardProxies"), + resourceids.UserSpecifiedSegment("backupResourceGuardProxyName", "backupResourceGuardProxyName"), + } +} + +// String returns a human-readable description of this Backup Resource Guard Proxy ID +func (id BackupResourceGuardProxyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Resource Guard Proxy Name: %q", id.BackupResourceGuardProxyName), + } + return fmt.Sprintf("Backup Resource Guard Proxy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go new file mode 100644 index 00000000000..3b3bc8930ae --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupresourceguardproxy_test.go @@ -0,0 +1,327 @@ +package dppresourceguardproxies + +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 = &BackupResourceGuardProxyId{} + +func TestNewBackupResourceGuardProxyID(t *testing.T) { + id := NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupResourceGuardProxyName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.BackupResourceGuardProxyName != "backupResourceGuardProxyName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupResourceGuardProxyName'", id.BackupResourceGuardProxyName, "backupResourceGuardProxyName") + } +} + +func TestFormatBackupResourceGuardProxyID(t *testing.T) { + actual := NewBackupResourceGuardProxyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupResourceGuardProxyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies/backupResourceGuardProxyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupResourceGuardProxyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupResourceGuardProxyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies/backupResourceGuardProxyName", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupResourceGuardProxyName: "backupResourceGuardProxyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies/backupResourceGuardProxyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupResourceGuardProxyID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupResourceGuardProxyName != v.Expected.BackupResourceGuardProxyName { + t.Fatalf("Expected %q but got %q for BackupResourceGuardProxyName", v.Expected.BackupResourceGuardProxyName, actual.BackupResourceGuardProxyName) + } + + } +} + +func TestParseBackupResourceGuardProxyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupResourceGuardProxyId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPrEsOuRcEgUaRdPrOxIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies/backupResourceGuardProxyName", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupResourceGuardProxyName: "backupResourceGuardProxyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupResourceGuardProxies/backupResourceGuardProxyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPrEsOuRcEgUaRdPrOxIeS/bAcKuPrEsOuRcEgUaRdPrOxYnAmE", + Expected: &BackupResourceGuardProxyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + BackupResourceGuardProxyName: "bAcKuPrEsOuRcEgUaRdPrOxYnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPrEsOuRcEgUaRdPrOxIeS/bAcKuPrEsOuRcEgUaRdPrOxYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupResourceGuardProxyIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupResourceGuardProxyName != v.Expected.BackupResourceGuardProxyName { + t.Fatalf("Expected %q but got %q for BackupResourceGuardProxyName", v.Expected.BackupResourceGuardProxyName, actual.BackupResourceGuardProxyName) + } + + } +} + +func TestSegmentsForBackupResourceGuardProxyId(t *testing.T) { + segments := BackupResourceGuardProxyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupResourceGuardProxyId 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/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault.go new file mode 100644 index 00000000000..8d5e6414971 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault.go @@ -0,0 +1,130 @@ +package dppresourceguardproxies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupVaultId{}) +} + +var _ resourceids.ResourceId = &BackupVaultId{} + +// BackupVaultId is a struct representing the Resource ID for a Backup Vault +type BackupVaultId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string +} + +// NewBackupVaultID returns a new BackupVaultId struct +func NewBackupVaultID(subscriptionId string, resourceGroupName string, backupVaultName string) BackupVaultId { + return BackupVaultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + } +} + +// ParseBackupVaultID parses 'input' into a BackupVaultId +func ParseBackupVaultID(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupVaultIDInsensitively parses 'input' case-insensitively into a BackupVaultId +// note: this method should only be used for API response data and not user input +func ParseBackupVaultIDInsensitively(input string) (*BackupVaultId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupVaultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupVaultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupVaultId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + return nil +} + +// ValidateBackupVaultID checks that 'input' can be parsed as a Backup Vault ID +func ValidateBackupVaultID(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 := ParseBackupVaultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Vault ID +func (id BackupVaultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Vault ID +func (id BackupVaultId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + } +} + +// String returns a human-readable description of this Backup Vault ID +func (id BackupVaultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + } + return fmt.Sprintf("Backup Vault (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault_test.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault_test.go new file mode 100644 index 00000000000..7f72b2b11d4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/id_backupvault_test.go @@ -0,0 +1,282 @@ +package dppresourceguardproxies + +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 = &BackupVaultId{} + +func TestNewBackupVaultID(t *testing.T) { + id := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } +} + +func TestFormatBackupVaultID(t *testing.T) { + actual := NewBackupVaultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupVaultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestParseBackupVaultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupVaultId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Expected: &BackupVaultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupVaultIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + } +} + +func TestSegmentsForBackupVaultId(t *testing.T) { + segments := BackupVaultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupVaultId 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/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go new file mode 100644 index 00000000000..f66d7644b9c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxycreateorupdate.go @@ -0,0 +1,57 @@ +package dppresourceguardproxies + +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 DppResourceGuardProxyCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardProxyBaseResource +} + +// DppResourceGuardProxyCreateOrUpdate ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyCreateOrUpdate(ctx context.Context, id BackupResourceGuardProxyId, input ResourceGuardProxyBaseResource) (result DppResourceGuardProxyCreateOrUpdateOperationResponse, 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 ResourceGuardProxyBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go new file mode 100644 index 00000000000..86075b7794f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxydelete.go @@ -0,0 +1,47 @@ +package dppresourceguardproxies + +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 DppResourceGuardProxyDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DppResourceGuardProxyDelete ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyDelete(ctx context.Context, id BackupResourceGuardProxyId) (result DppResourceGuardProxyDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyget.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyget.go new file mode 100644 index 00000000000..a2c7afa278b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyget.go @@ -0,0 +1,53 @@ +package dppresourceguardproxies + +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 DppResourceGuardProxyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardProxyBaseResource +} + +// DppResourceGuardProxyGet ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyGet(ctx context.Context, id BackupResourceGuardProxyId) (result DppResourceGuardProxyGetOperationResponse, 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 ResourceGuardProxyBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxylist.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxylist.go new file mode 100644 index 00000000000..c0966522e2f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxylist.go @@ -0,0 +1,105 @@ +package dppresourceguardproxies + +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 DppResourceGuardProxyListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceGuardProxyBaseResource +} + +type DppResourceGuardProxyListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceGuardProxyBaseResource +} + +type DppResourceGuardProxyListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DppResourceGuardProxyListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DppResourceGuardProxyList ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyList(ctx context.Context, id BackupVaultId) (result DppResourceGuardProxyListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DppResourceGuardProxyListCustomPager{}, + Path: fmt.Sprintf("%s/backupResourceGuardProxies", 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 *[]ResourceGuardProxyBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DppResourceGuardProxyListComplete retrieves all the results into a single object +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyListComplete(ctx context.Context, id BackupVaultId) (DppResourceGuardProxyListCompleteResult, error) { + return c.DppResourceGuardProxyListCompleteMatchingPredicate(ctx, id, ResourceGuardProxyBaseResourceOperationPredicate{}) +} + +// DppResourceGuardProxyListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyListCompleteMatchingPredicate(ctx context.Context, id BackupVaultId, predicate ResourceGuardProxyBaseResourceOperationPredicate) (result DppResourceGuardProxyListCompleteResult, err error) { + items := make([]ResourceGuardProxyBaseResource, 0) + + resp, err := c.DppResourceGuardProxyList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DppResourceGuardProxyListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go new file mode 100644 index 00000000000..b823f13895a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/method_dppresourceguardproxyunlockdelete.go @@ -0,0 +1,87 @@ +package dppresourceguardproxies + +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 DppResourceGuardProxyUnlockDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *UnlockDeleteResponse +} + +type DppResourceGuardProxyUnlockDeleteOperationOptions struct { + XMsAuthorizationAuxiliary *string +} + +func DefaultDppResourceGuardProxyUnlockDeleteOperationOptions() DppResourceGuardProxyUnlockDeleteOperationOptions { + return DppResourceGuardProxyUnlockDeleteOperationOptions{} +} + +func (o DppResourceGuardProxyUnlockDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.XMsAuthorizationAuxiliary != nil { + out.Append("x-ms-authorization-auxiliary", fmt.Sprintf("%v", *o.XMsAuthorizationAuxiliary)) + } + return &out +} + +func (o DppResourceGuardProxyUnlockDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DppResourceGuardProxyUnlockDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// DppResourceGuardProxyUnlockDelete ... +func (c DppResourceGuardProxiesClient) DppResourceGuardProxyUnlockDelete(ctx context.Context, id BackupResourceGuardProxyId, input UnlockDeleteRequest, options DppResourceGuardProxyUnlockDeleteOperationOptions) (result DppResourceGuardProxyUnlockDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/unlockDelete", 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 UnlockDeleteResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardoperationdetail.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardoperationdetail.go new file mode 100644 index 00000000000..6540ed78351 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardoperationdetail.go @@ -0,0 +1,9 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardOperationDetail struct { + DefaultResourceRequest *string `json:"defaultResourceRequest,omitempty"` + VaultCriticalOperation *string `json:"vaultCriticalOperation,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybase.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybase.go new file mode 100644 index 00000000000..d752010f8cc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybase.go @@ -0,0 +1,11 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardProxyBase struct { + Description *string `json:"description,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + ResourceGuardOperationDetails *[]ResourceGuardOperationDetail `json:"resourceGuardOperationDetails,omitempty"` + ResourceGuardResourceId *string `json:"resourceGuardResourceId,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go new file mode 100644 index 00000000000..4e6713c4856 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_resourceguardproxybaseresource.go @@ -0,0 +1,16 @@ +package dppresourceguardproxies + +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 ResourceGuardProxyBaseResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGuardProxyBase `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleterequest.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleterequest.go new file mode 100644 index 00000000000..e5415cf7db3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleterequest.go @@ -0,0 +1,9 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnlockDeleteRequest struct { + ResourceGuardOperationRequests *[]string `json:"resourceGuardOperationRequests,omitempty"` + ResourceToBeDeleted *string `json:"resourceToBeDeleted,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleteresponse.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleteresponse.go new file mode 100644 index 00000000000..408d1ec0fc8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/model_unlockdeleteresponse.go @@ -0,0 +1,8 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnlockDeleteResponse struct { + UnlockDeleteExpiryTime *string `json:"unlockDeleteExpiryTime,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/predicates.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/predicates.go new file mode 100644 index 00000000000..6da3b96156e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/predicates.go @@ -0,0 +1,27 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardProxyBaseResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceGuardProxyBaseResourceOperationPredicate) Matches(input ResourceGuardProxyBaseResource) 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/dataprotection/2025-02-01/dppresourceguardproxies/version.go b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/version.go new file mode 100644 index 00000000000..29b153a8c07 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/dppresourceguardproxies/version.go @@ -0,0 +1,10 @@ +package dppresourceguardproxies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/dppresourceguardproxies/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/README.md b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/README.md new file mode 100644 index 00000000000..16fb13f17f9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints` Documentation + +The `fetchsecondaryrecoverypoints` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints" +``` + + +### Client Initialization + +```go +client := fetchsecondaryrecoverypoints.NewFetchSecondaryRecoveryPointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FetchSecondaryRecoveryPointsClient.List` + +```go +ctx := context.TODO() +id := fetchsecondaryrecoverypoints.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +payload := fetchsecondaryrecoverypoints.FetchSecondaryRPsRequestParameters{ + // ... +} + + +// alternatively `client.List(ctx, id, payload, fetchsecondaryrecoverypoints.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, payload, fetchsecondaryrecoverypoints.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/client.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/client.go new file mode 100644 index 00000000000..b57013621a5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/client.go @@ -0,0 +1,26 @@ +package fetchsecondaryrecoverypoints + +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 FetchSecondaryRecoveryPointsClient struct { + Client *resourcemanager.Client +} + +func NewFetchSecondaryRecoveryPointsClientWithBaseURI(sdkApi sdkEnv.Api) (*FetchSecondaryRecoveryPointsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "fetchsecondaryrecoverypoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FetchSecondaryRecoveryPointsClient: %+v", err) + } + + return &FetchSecondaryRecoveryPointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/constants.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/constants.go new file mode 100644 index 00000000000..4ad5deabceb --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/constants.go @@ -0,0 +1,101 @@ +package fetchsecondaryrecoverypoints + +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 RecoveryPointCompletionState string + +const ( + RecoveryPointCompletionStateCompleted RecoveryPointCompletionState = "Completed" + RecoveryPointCompletionStatePartial RecoveryPointCompletionState = "Partial" +) + +func PossibleValuesForRecoveryPointCompletionState() []string { + return []string{ + string(RecoveryPointCompletionStateCompleted), + string(RecoveryPointCompletionStatePartial), + } +} + +func (s *RecoveryPointCompletionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecoveryPointCompletionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecoveryPointCompletionState(input string) (*RecoveryPointCompletionState, error) { + vals := map[string]RecoveryPointCompletionState{ + "completed": RecoveryPointCompletionStateCompleted, + "partial": RecoveryPointCompletionStatePartial, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointCompletionState(input) + return &out, nil +} + +type RehydrationStatus string + +const ( + RehydrationStatusCOMPLETED RehydrationStatus = "COMPLETED" + RehydrationStatusCREATEINPROGRESS RehydrationStatus = "CREATE_IN_PROGRESS" + RehydrationStatusDELETED RehydrationStatus = "DELETED" + RehydrationStatusDELETEINPROGRESS RehydrationStatus = "DELETE_IN_PROGRESS" + RehydrationStatusFAILED RehydrationStatus = "FAILED" +) + +func PossibleValuesForRehydrationStatus() []string { + return []string{ + string(RehydrationStatusCOMPLETED), + string(RehydrationStatusCREATEINPROGRESS), + string(RehydrationStatusDELETED), + string(RehydrationStatusDELETEINPROGRESS), + string(RehydrationStatusFAILED), + } +} + +func (s *RehydrationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRehydrationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRehydrationStatus(input string) (*RehydrationStatus, error) { + vals := map[string]RehydrationStatus{ + "completed": RehydrationStatusCOMPLETED, + "create_in_progress": RehydrationStatusCREATEINPROGRESS, + "deleted": RehydrationStatusDELETED, + "delete_in_progress": RehydrationStatusDELETEINPROGRESS, + "failed": RehydrationStatusFAILED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RehydrationStatus(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation.go new file mode 100644 index 00000000000..5879bb8e5aa --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation.go @@ -0,0 +1,130 @@ +package fetchsecondaryrecoverypoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go new file mode 100644 index 00000000000..8f7a9e4627a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package fetchsecondaryrecoverypoints + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/method_list.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/method_list.go new file mode 100644 index 00000000000..529ba019df0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/method_list.go @@ -0,0 +1,134 @@ +package fetchsecondaryrecoverypoints + +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 *[]AzureBackupRecoveryPointResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureBackupRecoveryPointResource +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c FetchSecondaryRecoveryPointsClient) List(ctx context.Context, id ProviderLocationId, input FetchSecondaryRPsRequestParameters, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/fetchSecondaryRecoveryPoints", 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 *[]AzureBackupRecoveryPointResource `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 FetchSecondaryRecoveryPointsClient) ListComplete(ctx context.Context, id ProviderLocationId, input FetchSecondaryRPsRequestParameters, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, input, options, AzureBackupRecoveryPointResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FetchSecondaryRecoveryPointsClient) ListCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, input FetchSecondaryRPsRequestParameters, options ListOperationOptions, predicate AzureBackupRecoveryPointResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AzureBackupRecoveryPointResource, 0) + + resp, err := c.List(ctx, id, input, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go new file mode 100644 index 00000000000..87fc8c24a23 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackupdiscreterecoverypoint.go @@ -0,0 +1,60 @@ +package fetchsecondaryrecoverypoints + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRecoveryPoint = AzureBackupDiscreteRecoveryPoint{} + +type AzureBackupDiscreteRecoveryPoint struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` + RecoveryPointDataStoresDetails *[]RecoveryPointDataStoreDetails `json:"recoveryPointDataStoresDetails,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointState *RecoveryPointCompletionState `json:"recoveryPointState,omitempty"` + RecoveryPointTime string `json:"recoveryPointTime"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + RetentionTagName *string `json:"retentionTagName,omitempty"` + RetentionTagVersion *string `json:"retentionTagVersion,omitempty"` + + // Fields inherited from AzureBackupRecoveryPoint + + ObjectType string `json:"objectType"` +} + +func (s AzureBackupDiscreteRecoveryPoint) AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl { + return BaseAzureBackupRecoveryPointImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureBackupDiscreteRecoveryPoint{} + +func (s AzureBackupDiscreteRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupDiscreteRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + decoded["objectType"] = "AzureBackupDiscreteRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go new file mode 100644 index 00000000000..809598bdce8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypoint.go @@ -0,0 +1,75 @@ +package fetchsecondaryrecoverypoints + +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 AzureBackupRecoveryPoint interface { + AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl +} + +var _ AzureBackupRecoveryPoint = BaseAzureBackupRecoveryPointImpl{} + +type BaseAzureBackupRecoveryPointImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseAzureBackupRecoveryPointImpl) AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl { + return s +} + +var _ AzureBackupRecoveryPoint = RawAzureBackupRecoveryPointImpl{} + +// RawAzureBackupRecoveryPointImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAzureBackupRecoveryPointImpl struct { + azureBackupRecoveryPoint BaseAzureBackupRecoveryPointImpl + Type string + Values map[string]interface{} +} + +func (s RawAzureBackupRecoveryPointImpl) AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl { + return s.azureBackupRecoveryPoint +} + +func UnmarshalAzureBackupRecoveryPointImplementation(input []byte) (AzureBackupRecoveryPoint, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryPoint into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureBackupDiscreteRecoveryPoint") { + var out AzureBackupDiscreteRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupDiscreteRecoveryPoint: %+v", err) + } + return out, nil + } + + var parent BaseAzureBackupRecoveryPointImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseAzureBackupRecoveryPointImpl: %+v", err) + } + + return RawAzureBackupRecoveryPointImpl{ + azureBackupRecoveryPoint: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go new file mode 100644 index 00000000000..b5befa8a975 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_azurebackuprecoverypointresource.go @@ -0,0 +1,53 @@ +package fetchsecondaryrecoverypoints + +import ( + "encoding/json" + "fmt" + + "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 AzureBackupRecoveryPointResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties AzureBackupRecoveryPoint `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &AzureBackupRecoveryPointResource{} + +func (s *AzureBackupRecoveryPointResource) UnmarshalJSON(bytes []byte) error { + var decoded struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryPointResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := UnmarshalAzureBackupRecoveryPointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'AzureBackupRecoveryPointResource': %+v", err) + } + s.Properties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go new file mode 100644 index 00000000000..7a692e03408 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_fetchsecondaryrpsrequestparameters.go @@ -0,0 +1,9 @@ +package fetchsecondaryrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FetchSecondaryRPsRequestParameters struct { + SourceBackupInstanceId *string `json:"sourceBackupInstanceId,omitempty"` + SourceRegion *string `json:"sourceRegion,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go new file mode 100644 index 00000000000..abdf9b9007f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/model_recoverypointdatastoredetails.go @@ -0,0 +1,58 @@ +package fetchsecondaryrecoverypoints + +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 RecoveryPointDataStoreDetails struct { + CreationTime *string `json:"creationTime,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + Id *string `json:"id,omitempty"` + MetaData *string `json:"metaData,omitempty"` + RehydrationExpiryTime *string `json:"rehydrationExpiryTime,omitempty"` + RehydrationStatus *RehydrationStatus `json:"rehydrationStatus,omitempty"` + State *string `json:"state,omitempty"` + Type *string `json:"type,omitempty"` + Visible *bool `json:"visible,omitempty"` +} + +func (o *RecoveryPointDataStoreDetails) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetRehydrationExpiryTimeAsTime() (*time.Time, error) { + if o.RehydrationExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RehydrationExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetRehydrationExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RehydrationExpiryTime = &formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/predicates.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/predicates.go new file mode 100644 index 00000000000..b9a05d28a27 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/predicates.go @@ -0,0 +1,27 @@ +package fetchsecondaryrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRecoveryPointResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupRecoveryPointResourceOperationPredicate) Matches(input AzureBackupRecoveryPointResource) 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/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/version.go b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/version.go new file mode 100644 index 00000000000..ea6866f3ccd --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/fetchsecondaryrecoverypoints/version.go @@ -0,0 +1,10 @@ +package fetchsecondaryrecoverypoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/fetchsecondaryrecoverypoints/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/README.md b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/README.md new file mode 100644 index 00000000000..6d5e71c23fe --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges` Documentation + +The `findrestorabletimeranges` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges" +``` + + +### Client Initialization + +```go +client := findrestorabletimeranges.NewFindRestorableTimeRangesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FindRestorableTimeRangesClient.RestorableTimeRangesFind` + +```go +ctx := context.TODO() +id := findrestorabletimeranges.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +payload := findrestorabletimeranges.AzureBackupFindRestorableTimeRangesRequest{ + // ... +} + + +read, err := client.RestorableTimeRangesFind(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/dataprotection/2025-02-01/findrestorabletimeranges/client.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/client.go new file mode 100644 index 00000000000..d342b80d165 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/client.go @@ -0,0 +1,26 @@ +package findrestorabletimeranges + +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 FindRestorableTimeRangesClient struct { + Client *resourcemanager.Client +} + +func NewFindRestorableTimeRangesClientWithBaseURI(sdkApi sdkEnv.Api) (*FindRestorableTimeRangesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "findrestorabletimeranges", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FindRestorableTimeRangesClient: %+v", err) + } + + return &FindRestorableTimeRangesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/constants.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/constants.go new file mode 100644 index 00000000000..3afd71927af --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/constants.go @@ -0,0 +1,54 @@ +package findrestorabletimeranges + +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 RestoreSourceDataStoreType string + +const ( + RestoreSourceDataStoreTypeArchiveStore RestoreSourceDataStoreType = "ArchiveStore" + RestoreSourceDataStoreTypeOperationalStore RestoreSourceDataStoreType = "OperationalStore" + RestoreSourceDataStoreTypeVaultStore RestoreSourceDataStoreType = "VaultStore" +) + +func PossibleValuesForRestoreSourceDataStoreType() []string { + return []string{ + string(RestoreSourceDataStoreTypeArchiveStore), + string(RestoreSourceDataStoreTypeOperationalStore), + string(RestoreSourceDataStoreTypeVaultStore), + } +} + +func (s *RestoreSourceDataStoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestoreSourceDataStoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestoreSourceDataStoreType(input string) (*RestoreSourceDataStoreType, error) { + vals := map[string]RestoreSourceDataStoreType{ + "archivestore": RestoreSourceDataStoreTypeArchiveStore, + "operationalstore": RestoreSourceDataStoreTypeOperationalStore, + "vaultstore": RestoreSourceDataStoreTypeVaultStore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestoreSourceDataStoreType(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance.go new file mode 100644 index 00000000000..6ababa9f6f5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance.go @@ -0,0 +1,139 @@ +package findrestorabletimeranges + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupInstanceId{}) +} + +var _ resourceids.ResourceId = &BackupInstanceId{} + +// BackupInstanceId is a struct representing the Resource ID for a Backup Instance +type BackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string +} + +// NewBackupInstanceID returns a new BackupInstanceId struct +func NewBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string) BackupInstanceId { + return BackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + } +} + +// ParseBackupInstanceID parses 'input' into a BackupInstanceId +func ParseBackupInstanceID(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupInstanceIDInsensitively parses 'input' case-insensitively into a BackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseBackupInstanceIDInsensitively(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupInstanceId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + return nil +} + +// ValidateBackupInstanceID checks that 'input' can be parsed as a Backup Instance ID +func ValidateBackupInstanceID(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 := ParseBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Instance ID +func (id BackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Instance ID +func (id BackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceName"), + } +} + +// String returns a human-readable description of this Backup Instance ID +func (id BackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + } + return fmt.Sprintf("Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance_test.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance_test.go new file mode 100644 index 00000000000..b6a1a836563 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/id_backupinstance_test.go @@ -0,0 +1,327 @@ +package findrestorabletimeranges + +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 = &BackupInstanceId{} + +func TestNewBackupInstanceID(t *testing.T) { + id := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.BackupInstanceName != "backupInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceName") + } +} + +func TestFormatBackupInstanceID(t *testing.T) { + actual := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestParseBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + BackupInstanceName: "bAcKuPiNsTaNcEnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestSegmentsForBackupInstanceId(t *testing.T) { + segments := BackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupInstanceId 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/dataprotection/2025-02-01/findrestorabletimeranges/method_restorabletimerangesfind.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/method_restorabletimerangesfind.go new file mode 100644 index 00000000000..fab15204651 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/method_restorabletimerangesfind.go @@ -0,0 +1,58 @@ +package findrestorabletimeranges + +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 RestorableTimeRangesFindOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureBackupFindRestorableTimeRangesResponseResource +} + +// RestorableTimeRangesFind ... +func (c FindRestorableTimeRangesClient) RestorableTimeRangesFind(ctx context.Context, id BackupInstanceId, input AzureBackupFindRestorableTimeRangesRequest) (result RestorableTimeRangesFindOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/findRestorableTimeRanges", 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 AzureBackupFindRestorableTimeRangesResponseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go new file mode 100644 index 00000000000..3788f11d512 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesrequest.go @@ -0,0 +1,10 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupFindRestorableTimeRangesRequest struct { + EndTime *string `json:"endTime,omitempty"` + SourceDataStoreType RestoreSourceDataStoreType `json:"sourceDataStoreType"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go new file mode 100644 index 00000000000..2c361dccf44 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponse.go @@ -0,0 +1,9 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupFindRestorableTimeRangesResponse struct { + ObjectType *string `json:"objectType,omitempty"` + RestorableTimeRanges *[]RestorableTimeRange `json:"restorableTimeRanges,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go new file mode 100644 index 00000000000..bd16082c55f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_azurebackupfindrestorabletimerangesresponseresource.go @@ -0,0 +1,16 @@ +package findrestorabletimeranges + +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 AzureBackupFindRestorableTimeRangesResponseResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureBackupFindRestorableTimeRangesResponse `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_restorabletimerange.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_restorabletimerange.go new file mode 100644 index 00000000000..1ea7cdc9433 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/model_restorabletimerange.go @@ -0,0 +1,10 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableTimeRange struct { + EndTime string `json:"endTime"` + ObjectType *string `json:"objectType,omitempty"` + StartTime string `json:"startTime"` +} diff --git a/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/version.go b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/version.go new file mode 100644 index 00000000000..12dbecbff31 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/findrestorabletimeranges/version.go @@ -0,0 +1,10 @@ +package findrestorabletimeranges + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/findrestorabletimeranges/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/README.md b/resource-manager/dataprotection/2025-02-01/recoverypoint/README.md new file mode 100644 index 00000000000..63110dbf23f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/recoverypoint` Documentation + +The `recoverypoint` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/recoverypoint" +``` + + +### Client Initialization + +```go +client := recoverypoint.NewRecoveryPointClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoveryPointClient.Get` + +```go +ctx := context.TODO() +id := recoverypoint.NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName", "recoveryPointId") + +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: `RecoveryPointClient.List` + +```go +ctx := context.TODO() +id := recoverypoint.NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + +// alternatively `client.List(ctx, id, recoverypoint.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, recoverypoint.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/client.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/client.go new file mode 100644 index 00000000000..3808ce1905f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/client.go @@ -0,0 +1,26 @@ +package recoverypoint + +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 RecoveryPointClient struct { + Client *resourcemanager.Client +} + +func NewRecoveryPointClientWithBaseURI(sdkApi sdkEnv.Api) (*RecoveryPointClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "recoverypoint", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RecoveryPointClient: %+v", err) + } + + return &RecoveryPointClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/constants.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/constants.go new file mode 100644 index 00000000000..9a81c1ea973 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/constants.go @@ -0,0 +1,101 @@ +package recoverypoint + +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 RecoveryPointCompletionState string + +const ( + RecoveryPointCompletionStateCompleted RecoveryPointCompletionState = "Completed" + RecoveryPointCompletionStatePartial RecoveryPointCompletionState = "Partial" +) + +func PossibleValuesForRecoveryPointCompletionState() []string { + return []string{ + string(RecoveryPointCompletionStateCompleted), + string(RecoveryPointCompletionStatePartial), + } +} + +func (s *RecoveryPointCompletionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecoveryPointCompletionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecoveryPointCompletionState(input string) (*RecoveryPointCompletionState, error) { + vals := map[string]RecoveryPointCompletionState{ + "completed": RecoveryPointCompletionStateCompleted, + "partial": RecoveryPointCompletionStatePartial, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecoveryPointCompletionState(input) + return &out, nil +} + +type RehydrationStatus string + +const ( + RehydrationStatusCOMPLETED RehydrationStatus = "COMPLETED" + RehydrationStatusCREATEINPROGRESS RehydrationStatus = "CREATE_IN_PROGRESS" + RehydrationStatusDELETED RehydrationStatus = "DELETED" + RehydrationStatusDELETEINPROGRESS RehydrationStatus = "DELETE_IN_PROGRESS" + RehydrationStatusFAILED RehydrationStatus = "FAILED" +) + +func PossibleValuesForRehydrationStatus() []string { + return []string{ + string(RehydrationStatusCOMPLETED), + string(RehydrationStatusCREATEINPROGRESS), + string(RehydrationStatusDELETED), + string(RehydrationStatusDELETEINPROGRESS), + string(RehydrationStatusFAILED), + } +} + +func (s *RehydrationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRehydrationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRehydrationStatus(input string) (*RehydrationStatus, error) { + vals := map[string]RehydrationStatus{ + "completed": RehydrationStatusCOMPLETED, + "create_in_progress": RehydrationStatusCREATEINPROGRESS, + "deleted": RehydrationStatusDELETED, + "delete_in_progress": RehydrationStatusDELETEINPROGRESS, + "failed": RehydrationStatusFAILED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RehydrationStatus(input) + return &out, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance.go new file mode 100644 index 00000000000..26cc0f06e97 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance.go @@ -0,0 +1,139 @@ +package recoverypoint + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BackupInstanceId{}) +} + +var _ resourceids.ResourceId = &BackupInstanceId{} + +// BackupInstanceId is a struct representing the Resource ID for a Backup Instance +type BackupInstanceId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string +} + +// NewBackupInstanceID returns a new BackupInstanceId struct +func NewBackupInstanceID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string) BackupInstanceId { + return BackupInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + } +} + +// ParseBackupInstanceID parses 'input' into a BackupInstanceId +func ParseBackupInstanceID(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBackupInstanceIDInsensitively parses 'input' case-insensitively into a BackupInstanceId +// note: this method should only be used for API response data and not user input +func ParseBackupInstanceIDInsensitively(input string) (*BackupInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&BackupInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BackupInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BackupInstanceId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + return nil +} + +// ValidateBackupInstanceID checks that 'input' can be parsed as a Backup Instance ID +func ValidateBackupInstanceID(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 := ParseBackupInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Backup Instance ID +func (id BackupInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Backup Instance ID +func (id BackupInstanceId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceName"), + } +} + +// String returns a human-readable description of this Backup Instance ID +func (id BackupInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + } + return fmt.Sprintf("Backup Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance_test.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance_test.go new file mode 100644 index 00000000000..807cb4b10ae --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_backupinstance_test.go @@ -0,0 +1,327 @@ +package recoverypoint + +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 = &BackupInstanceId{} + +func TestNewBackupInstanceID(t *testing.T) { + id := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.BackupInstanceName != "backupInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceName") + } +} + +func TestFormatBackupInstanceID(t *testing.T) { + actual := NewBackupInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBackupInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestParseBackupInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BackupInstanceId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE", + Expected: &BackupInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + BackupInstanceName: "bAcKuPiNsTaNcEnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBackupInstanceIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + } +} + +func TestSegmentsForBackupInstanceId(t *testing.T) { + segments := BackupInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BackupInstanceId 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/dataprotection/2025-02-01/recoverypoint/id_recoverypoint.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint.go new file mode 100644 index 00000000000..f05d98b51c0 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint.go @@ -0,0 +1,148 @@ +package recoverypoint + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RecoveryPointId{}) +} + +var _ resourceids.ResourceId = &RecoveryPointId{} + +// RecoveryPointId is a struct representing the Resource ID for a Recovery Point +type RecoveryPointId struct { + SubscriptionId string + ResourceGroupName string + BackupVaultName string + BackupInstanceName string + RecoveryPointId string +} + +// NewRecoveryPointID returns a new RecoveryPointId struct +func NewRecoveryPointID(subscriptionId string, resourceGroupName string, backupVaultName string, backupInstanceName string, recoveryPointId string) RecoveryPointId { + return RecoveryPointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + BackupVaultName: backupVaultName, + BackupInstanceName: backupInstanceName, + RecoveryPointId: recoveryPointId, + } +} + +// ParseRecoveryPointID parses 'input' into a RecoveryPointId +func ParseRecoveryPointID(input string) (*RecoveryPointId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoveryPointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoveryPointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecoveryPointIDInsensitively parses 'input' case-insensitively into a RecoveryPointId +// note: this method should only be used for API response data and not user input +func ParseRecoveryPointIDInsensitively(input string) (*RecoveryPointId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoveryPointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoveryPointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecoveryPointId) 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.BackupVaultName, ok = input.Parsed["backupVaultName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupVaultName", input) + } + + if id.BackupInstanceName, ok = input.Parsed["backupInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "backupInstanceName", input) + } + + if id.RecoveryPointId, ok = input.Parsed["recoveryPointId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recoveryPointId", input) + } + + return nil +} + +// ValidateRecoveryPointID checks that 'input' can be parsed as a Recovery Point ID +func ValidateRecoveryPointID(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 := ParseRecoveryPointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recovery Point ID +func (id RecoveryPointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/backupVaults/%s/backupInstances/%s/recoveryPoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.BackupVaultName, id.BackupInstanceName, id.RecoveryPointId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recovery Point ID +func (id RecoveryPointId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticBackupVaults", "backupVaults", "backupVaults"), + resourceids.UserSpecifiedSegment("backupVaultName", "backupVaultName"), + resourceids.StaticSegment("staticBackupInstances", "backupInstances", "backupInstances"), + resourceids.UserSpecifiedSegment("backupInstanceName", "backupInstanceName"), + resourceids.StaticSegment("staticRecoveryPoints", "recoveryPoints", "recoveryPoints"), + resourceids.UserSpecifiedSegment("recoveryPointId", "recoveryPointId"), + } +} + +// String returns a human-readable description of this Recovery Point ID +func (id RecoveryPointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Backup Vault Name: %q", id.BackupVaultName), + fmt.Sprintf("Backup Instance Name: %q", id.BackupInstanceName), + fmt.Sprintf("Recovery Point: %q", id.RecoveryPointId), + } + return fmt.Sprintf("Recovery Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint_test.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint_test.go new file mode 100644 index 00000000000..8896fa388eb --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/id_recoverypoint_test.go @@ -0,0 +1,372 @@ +package recoverypoint + +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 = &RecoveryPointId{} + +func TestNewRecoveryPointID(t *testing.T) { + id := NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName", "recoveryPointId") + + 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.BackupVaultName != "backupVaultName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupVaultName'", id.BackupVaultName, "backupVaultName") + } + + if id.BackupInstanceName != "backupInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'BackupInstanceName'", id.BackupInstanceName, "backupInstanceName") + } + + if id.RecoveryPointId != "recoveryPointId" { + t.Fatalf("Expected %q but got %q for Segment 'RecoveryPointId'", id.RecoveryPointId, "recoveryPointId") + } +} + +func TestFormatRecoveryPointID(t *testing.T) { + actual := NewRecoveryPointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "backupVaultName", "backupInstanceName", "recoveryPointId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints/recoveryPointId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecoveryPointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoveryPointId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints/recoveryPointId", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + RecoveryPointId: "recoveryPointId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints/recoveryPointId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoveryPointID(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + if actual.RecoveryPointId != v.Expected.RecoveryPointId { + t.Fatalf("Expected %q but got %q for RecoveryPointId", v.Expected.RecoveryPointId, actual.RecoveryPointId) + } + + } +} + +func TestParseRecoveryPointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoveryPointId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE/rEcOvErYpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints/recoveryPointId", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + BackupVaultName: "backupVaultName", + BackupInstanceName: "backupInstanceName", + RecoveryPointId: "recoveryPointId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/backupVaults/backupVaultName/backupInstances/backupInstanceName/recoveryPoints/recoveryPointId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE/rEcOvErYpOiNtS/rEcOvErYpOiNtId", + Expected: &RecoveryPointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + BackupVaultName: "bAcKuPvAuLtNaMe", + BackupInstanceName: "bAcKuPiNsTaNcEnAmE", + RecoveryPointId: "rEcOvErYpOiNtId", + }, + }, + { + // 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.dAtApRoTeCtIoN/bAcKuPvAuLtS/bAcKuPvAuLtNaMe/bAcKuPiNsTaNcEs/bAcKuPiNsTaNcEnAmE/rEcOvErYpOiNtS/rEcOvErYpOiNtId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoveryPointIDInsensitively(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.BackupVaultName != v.Expected.BackupVaultName { + t.Fatalf("Expected %q but got %q for BackupVaultName", v.Expected.BackupVaultName, actual.BackupVaultName) + } + + if actual.BackupInstanceName != v.Expected.BackupInstanceName { + t.Fatalf("Expected %q but got %q for BackupInstanceName", v.Expected.BackupInstanceName, actual.BackupInstanceName) + } + + if actual.RecoveryPointId != v.Expected.RecoveryPointId { + t.Fatalf("Expected %q but got %q for RecoveryPointId", v.Expected.RecoveryPointId, actual.RecoveryPointId) + } + + } +} + +func TestSegmentsForRecoveryPointId(t *testing.T) { + segments := RecoveryPointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecoveryPointId 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/dataprotection/2025-02-01/recoverypoint/method_get.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/method_get.go new file mode 100644 index 00000000000..527ea0e9599 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/method_get.go @@ -0,0 +1,53 @@ +package recoverypoint + +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 *AzureBackupRecoveryPointResource +} + +// Get ... +func (c RecoveryPointClient) Get(ctx context.Context, id RecoveryPointId) (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 AzureBackupRecoveryPointResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/method_list.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/method_list.go new file mode 100644 index 00000000000..8c3642589d9 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/method_list.go @@ -0,0 +1,134 @@ +package recoverypoint + +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 *[]AzureBackupRecoveryPointResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureBackupRecoveryPointResource +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c RecoveryPointClient) List(ctx context.Context, id BackupInstanceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/recoveryPoints", 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 *[]AzureBackupRecoveryPointResource `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 RecoveryPointClient) ListComplete(ctx context.Context, id BackupInstanceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, AzureBackupRecoveryPointResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecoveryPointClient) ListCompleteMatchingPredicate(ctx context.Context, id BackupInstanceId, options ListOperationOptions, predicate AzureBackupRecoveryPointResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AzureBackupRecoveryPointResource, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go new file mode 100644 index 00000000000..b5e2e8ff589 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackupdiscreterecoverypoint.go @@ -0,0 +1,60 @@ +package recoverypoint + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AzureBackupRecoveryPoint = AzureBackupDiscreteRecoveryPoint{} + +type AzureBackupDiscreteRecoveryPoint struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyVersion *string `json:"policyVersion,omitempty"` + RecoveryPointDataStoresDetails *[]RecoveryPointDataStoreDetails `json:"recoveryPointDataStoresDetails,omitempty"` + RecoveryPointId *string `json:"recoveryPointId,omitempty"` + RecoveryPointState *RecoveryPointCompletionState `json:"recoveryPointState,omitempty"` + RecoveryPointTime string `json:"recoveryPointTime"` + RecoveryPointType *string `json:"recoveryPointType,omitempty"` + RetentionTagName *string `json:"retentionTagName,omitempty"` + RetentionTagVersion *string `json:"retentionTagVersion,omitempty"` + + // Fields inherited from AzureBackupRecoveryPoint + + ObjectType string `json:"objectType"` +} + +func (s AzureBackupDiscreteRecoveryPoint) AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl { + return BaseAzureBackupRecoveryPointImpl{ + ObjectType: s.ObjectType, + } +} + +var _ json.Marshaler = AzureBackupDiscreteRecoveryPoint{} + +func (s AzureBackupDiscreteRecoveryPoint) MarshalJSON() ([]byte, error) { + type wrapper AzureBackupDiscreteRecoveryPoint + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + decoded["objectType"] = "AzureBackupDiscreteRecoveryPoint" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureBackupDiscreteRecoveryPoint: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypoint.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypoint.go new file mode 100644 index 00000000000..6f966f91ddf --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypoint.go @@ -0,0 +1,75 @@ +package recoverypoint + +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 AzureBackupRecoveryPoint interface { + AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl +} + +var _ AzureBackupRecoveryPoint = BaseAzureBackupRecoveryPointImpl{} + +type BaseAzureBackupRecoveryPointImpl struct { + ObjectType string `json:"objectType"` +} + +func (s BaseAzureBackupRecoveryPointImpl) AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl { + return s +} + +var _ AzureBackupRecoveryPoint = RawAzureBackupRecoveryPointImpl{} + +// RawAzureBackupRecoveryPointImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawAzureBackupRecoveryPointImpl struct { + azureBackupRecoveryPoint BaseAzureBackupRecoveryPointImpl + Type string + Values map[string]interface{} +} + +func (s RawAzureBackupRecoveryPointImpl) AzureBackupRecoveryPoint() BaseAzureBackupRecoveryPointImpl { + return s.azureBackupRecoveryPoint +} + +func UnmarshalAzureBackupRecoveryPointImplementation(input []byte) (AzureBackupRecoveryPoint, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling AzureBackupRecoveryPoint into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["objectType"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "AzureBackupDiscreteRecoveryPoint") { + var out AzureBackupDiscreteRecoveryPoint + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureBackupDiscreteRecoveryPoint: %+v", err) + } + return out, nil + } + + var parent BaseAzureBackupRecoveryPointImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseAzureBackupRecoveryPointImpl: %+v", err) + } + + return RawAzureBackupRecoveryPointImpl{ + azureBackupRecoveryPoint: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypointresource.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypointresource.go new file mode 100644 index 00000000000..0922d2d0bc4 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_azurebackuprecoverypointresource.go @@ -0,0 +1,53 @@ +package recoverypoint + +import ( + "encoding/json" + "fmt" + + "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 AzureBackupRecoveryPointResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties AzureBackupRecoveryPoint `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &AzureBackupRecoveryPointResource{} + +func (s *AzureBackupRecoveryPointResource) UnmarshalJSON(bytes []byte) error { + var decoded struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AzureBackupRecoveryPointResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := UnmarshalAzureBackupRecoveryPointImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'AzureBackupRecoveryPointResource': %+v", err) + } + s.Properties = impl + } + + return nil +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/model_recoverypointdatastoredetails.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_recoverypointdatastoredetails.go new file mode 100644 index 00000000000..0cde4767bde --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/model_recoverypointdatastoredetails.go @@ -0,0 +1,58 @@ +package recoverypoint + +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 RecoveryPointDataStoreDetails struct { + CreationTime *string `json:"creationTime,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + Id *string `json:"id,omitempty"` + MetaData *string `json:"metaData,omitempty"` + RehydrationExpiryTime *string `json:"rehydrationExpiryTime,omitempty"` + RehydrationStatus *RehydrationStatus `json:"rehydrationStatus,omitempty"` + State *string `json:"state,omitempty"` + Type *string `json:"type,omitempty"` + Visible *bool `json:"visible,omitempty"` +} + +func (o *RecoveryPointDataStoreDetails) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *RecoveryPointDataStoreDetails) GetRehydrationExpiryTimeAsTime() (*time.Time, error) { + if o.RehydrationExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RehydrationExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoveryPointDataStoreDetails) SetRehydrationExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RehydrationExpiryTime = &formatted +} diff --git a/resource-manager/dataprotection/2025-02-01/recoverypoint/predicates.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/predicates.go new file mode 100644 index 00000000000..4c929e3a8cc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/predicates.go @@ -0,0 +1,27 @@ +package recoverypoint + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureBackupRecoveryPointResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureBackupRecoveryPointResourceOperationPredicate) Matches(input AzureBackupRecoveryPointResource) 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/dataprotection/2025-02-01/recoverypoint/version.go b/resource-manager/dataprotection/2025-02-01/recoverypoint/version.go new file mode 100644 index 00000000000..0b9f884f94c --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/recoverypoint/version.go @@ -0,0 +1,10 @@ +package recoverypoint + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/recoverypoint/2025-02-01" +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/README.md b/resource-manager/dataprotection/2025-02-01/resourceguards/README.md new file mode 100644 index 00000000000..4b2a4abde9f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/README.md @@ -0,0 +1,327 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/resourceguards` Documentation + +The `resourceguards` SDK allows for interaction with Azure Resource Manager `dataprotection` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2025-02-01/resourceguards" +``` + + +### Client Initialization + +```go +client := resourceguards.NewResourceGuardsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceGuardsClient.Delete` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.Get` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +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: `ResourceGuardsClient.GetBackupSecurityPINRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +// alternatively `client.GetBackupSecurityPINRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetBackupSecurityPINRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultBackupSecurityPINRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewGetBackupSecurityPINRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "getBackupSecurityPINRequestName") + +read, err := client.GetDefaultBackupSecurityPINRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultDeleteProtectedItemRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewDeleteProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "deleteProtectedItemRequestName") + +read, err := client.GetDefaultDeleteProtectedItemRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultDeleteResourceGuardProxyRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewDeleteResourceGuardProxyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "deleteResourceGuardProxyRequestName") + +read, err := client.GetDefaultDeleteResourceGuardProxyRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultDisableSoftDeleteRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewDisableSoftDeleteRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "disableSoftDeleteRequestName") + +read, err := client.GetDefaultDisableSoftDeleteRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultUpdateProtectedItemRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewUpdateProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "updateProtectedItemRequestName") + +read, err := client.GetDefaultUpdateProtectedItemRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDefaultUpdateProtectionPolicyRequestsObject` + +```go +ctx := context.TODO() +id := resourceguards.NewUpdateProtectionPolicyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "updateProtectionPolicyRequestName") + +read, err := client.GetDefaultUpdateProtectionPolicyRequestsObject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDeleteProtectedItemRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +// alternatively `client.GetDeleteProtectedItemRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetDeleteProtectedItemRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDeleteResourceGuardProxyRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +// alternatively `client.GetDeleteResourceGuardProxyRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetDeleteResourceGuardProxyRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetDisableSoftDeleteRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +// alternatively `client.GetDisableSoftDeleteRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetDisableSoftDeleteRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetResourcesInResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.GetResourcesInResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.GetResourcesInResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetResourcesInSubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.GetResourcesInSubscription(ctx, id)` can be used to do batched pagination +items, err := client.GetResourcesInSubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetUpdateProtectedItemRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +// alternatively `client.GetUpdateProtectedItemRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetUpdateProtectedItemRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.GetUpdateProtectionPolicyRequestsObjects` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +// alternatively `client.GetUpdateProtectionPolicyRequestsObjects(ctx, id)` can be used to do batched pagination +items, err := client.GetUpdateProtectionPolicyRequestsObjectsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGuardsClient.Patch` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +payload := resourceguards.PatchResourceGuardInput{ + // ... +} + + +read, err := client.Patch(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGuardsClient.Put` + +```go +ctx := context.TODO() +id := resourceguards.NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + +payload := resourceguards.ResourceGuardResource{ + // ... +} + + +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/dataprotection/2025-02-01/resourceguards/client.go b/resource-manager/dataprotection/2025-02-01/resourceguards/client.go new file mode 100644 index 00000000000..0f0913402ff --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/client.go @@ -0,0 +1,26 @@ +package resourceguards + +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 ResourceGuardsClient struct { + Client *resourcemanager.Client +} + +func NewResourceGuardsClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourceGuardsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "resourceguards", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourceGuardsClient: %+v", err) + } + + return &ResourceGuardsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/constants.go b/resource-manager/dataprotection/2025-02-01/resourceguards/constants.go new file mode 100644 index 00000000000..883176c506a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/constants.go @@ -0,0 +1,60 @@ +package resourceguards + +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 ( + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnknown ProvisioningState = "Unknown" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnknown), + 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{ + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "unknown": ProvisioningStateUnknown, + "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/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest.go new file mode 100644 index 00000000000..5df2a8b27db --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest.go @@ -0,0 +1,139 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeleteProtectedItemRequestId{}) +} + +var _ resourceids.ResourceId = &DeleteProtectedItemRequestId{} + +// DeleteProtectedItemRequestId is a struct representing the Resource ID for a Delete Protected Item Request +type DeleteProtectedItemRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + DeleteProtectedItemRequestName string +} + +// NewDeleteProtectedItemRequestID returns a new DeleteProtectedItemRequestId struct +func NewDeleteProtectedItemRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, deleteProtectedItemRequestName string) DeleteProtectedItemRequestId { + return DeleteProtectedItemRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + DeleteProtectedItemRequestName: deleteProtectedItemRequestName, + } +} + +// ParseDeleteProtectedItemRequestID parses 'input' into a DeleteProtectedItemRequestId +func ParseDeleteProtectedItemRequestID(input string) (*DeleteProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeleteProtectedItemRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteProtectedItemRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeleteProtectedItemRequestIDInsensitively parses 'input' case-insensitively into a DeleteProtectedItemRequestId +// note: this method should only be used for API response data and not user input +func ParseDeleteProtectedItemRequestIDInsensitively(input string) (*DeleteProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeleteProtectedItemRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteProtectedItemRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeleteProtectedItemRequestId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.DeleteProtectedItemRequestName, ok = input.Parsed["deleteProtectedItemRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deleteProtectedItemRequestName", input) + } + + return nil +} + +// ValidateDeleteProtectedItemRequestID checks that 'input' can be parsed as a Delete Protected Item Request ID +func ValidateDeleteProtectedItemRequestID(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 := ParseDeleteProtectedItemRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Delete Protected Item Request ID +func (id DeleteProtectedItemRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/deleteProtectedItemRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.DeleteProtectedItemRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Delete Protected Item Request ID +func (id DeleteProtectedItemRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + resourceids.StaticSegment("staticDeleteProtectedItemRequests", "deleteProtectedItemRequests", "deleteProtectedItemRequests"), + resourceids.UserSpecifiedSegment("deleteProtectedItemRequestName", "deleteProtectedItemRequestName"), + } +} + +// String returns a human-readable description of this Delete Protected Item Request ID +func (id DeleteProtectedItemRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Delete Protected Item Request Name: %q", id.DeleteProtectedItemRequestName), + } + return fmt.Sprintf("Delete Protected Item Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest_test.go new file mode 100644 index 00000000000..69a5e3310cc --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteprotecteditemrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +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 = &DeleteProtectedItemRequestId{} + +func TestNewDeleteProtectedItemRequestID(t *testing.T) { + id := NewDeleteProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "deleteProtectedItemRequestName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } + + if id.DeleteProtectedItemRequestName != "deleteProtectedItemRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'DeleteProtectedItemRequestName'", id.DeleteProtectedItemRequestName, "deleteProtectedItemRequestName") + } +} + +func TestFormatDeleteProtectedItemRequestID(t *testing.T) { + actual := NewDeleteProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "deleteProtectedItemRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests/deleteProtectedItemRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeleteProtectedItemRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests/deleteProtectedItemRequestName", + Expected: &DeleteProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + DeleteProtectedItemRequestName: "deleteProtectedItemRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests/deleteProtectedItemRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteProtectedItemRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteProtectedItemRequestName != v.Expected.DeleteProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for DeleteProtectedItemRequestName", v.Expected.DeleteProtectedItemRequestName, actual.DeleteProtectedItemRequestName) + } + + } +} + +func TestParseDeleteProtectedItemRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dElEtEpRoTeCtEdItEmReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests/deleteProtectedItemRequestName", + Expected: &DeleteProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + DeleteProtectedItemRequestName: "deleteProtectedItemRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteProtectedItemRequests/deleteProtectedItemRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dElEtEpRoTeCtEdItEmReQuEsTs/dElEtEpRoTeCtEdItEmReQuEsTnAmE", + Expected: &DeleteProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + DeleteProtectedItemRequestName: "dElEtEpRoTeCtEdItEmReQuEsTnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dElEtEpRoTeCtEdItEmReQuEsTs/dElEtEpRoTeCtEdItEmReQuEsTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteProtectedItemRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteProtectedItemRequestName != v.Expected.DeleteProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for DeleteProtectedItemRequestName", v.Expected.DeleteProtectedItemRequestName, actual.DeleteProtectedItemRequestName) + } + + } +} + +func TestSegmentsForDeleteProtectedItemRequestId(t *testing.T) { + segments := DeleteProtectedItemRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeleteProtectedItemRequestId 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/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest.go new file mode 100644 index 00000000000..5f1ebab8149 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest.go @@ -0,0 +1,139 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeleteResourceGuardProxyRequestId{}) +} + +var _ resourceids.ResourceId = &DeleteResourceGuardProxyRequestId{} + +// DeleteResourceGuardProxyRequestId is a struct representing the Resource ID for a Delete Resource Guard Proxy Request +type DeleteResourceGuardProxyRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + DeleteResourceGuardProxyRequestName string +} + +// NewDeleteResourceGuardProxyRequestID returns a new DeleteResourceGuardProxyRequestId struct +func NewDeleteResourceGuardProxyRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, deleteResourceGuardProxyRequestName string) DeleteResourceGuardProxyRequestId { + return DeleteResourceGuardProxyRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + DeleteResourceGuardProxyRequestName: deleteResourceGuardProxyRequestName, + } +} + +// ParseDeleteResourceGuardProxyRequestID parses 'input' into a DeleteResourceGuardProxyRequestId +func ParseDeleteResourceGuardProxyRequestID(input string) (*DeleteResourceGuardProxyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeleteResourceGuardProxyRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteResourceGuardProxyRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeleteResourceGuardProxyRequestIDInsensitively parses 'input' case-insensitively into a DeleteResourceGuardProxyRequestId +// note: this method should only be used for API response data and not user input +func ParseDeleteResourceGuardProxyRequestIDInsensitively(input string) (*DeleteResourceGuardProxyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeleteResourceGuardProxyRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeleteResourceGuardProxyRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeleteResourceGuardProxyRequestId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.DeleteResourceGuardProxyRequestName, ok = input.Parsed["deleteResourceGuardProxyRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deleteResourceGuardProxyRequestName", input) + } + + return nil +} + +// ValidateDeleteResourceGuardProxyRequestID checks that 'input' can be parsed as a Delete Resource Guard Proxy Request ID +func ValidateDeleteResourceGuardProxyRequestID(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 := ParseDeleteResourceGuardProxyRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Delete Resource Guard Proxy Request ID +func (id DeleteResourceGuardProxyRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/deleteResourceGuardProxyRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.DeleteResourceGuardProxyRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Delete Resource Guard Proxy Request ID +func (id DeleteResourceGuardProxyRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + resourceids.StaticSegment("staticDeleteResourceGuardProxyRequests", "deleteResourceGuardProxyRequests", "deleteResourceGuardProxyRequests"), + resourceids.UserSpecifiedSegment("deleteResourceGuardProxyRequestName", "deleteResourceGuardProxyRequestName"), + } +} + +// String returns a human-readable description of this Delete Resource Guard Proxy Request ID +func (id DeleteResourceGuardProxyRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Delete Resource Guard Proxy Request Name: %q", id.DeleteResourceGuardProxyRequestName), + } + return fmt.Sprintf("Delete Resource Guard Proxy Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest_test.go new file mode 100644 index 00000000000..22bd74e3abb --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_deleteresourceguardproxyrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +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 = &DeleteResourceGuardProxyRequestId{} + +func TestNewDeleteResourceGuardProxyRequestID(t *testing.T) { + id := NewDeleteResourceGuardProxyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "deleteResourceGuardProxyRequestName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } + + if id.DeleteResourceGuardProxyRequestName != "deleteResourceGuardProxyRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'DeleteResourceGuardProxyRequestName'", id.DeleteResourceGuardProxyRequestName, "deleteResourceGuardProxyRequestName") + } +} + +func TestFormatDeleteResourceGuardProxyRequestID(t *testing.T) { + actual := NewDeleteResourceGuardProxyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "deleteResourceGuardProxyRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeleteResourceGuardProxyRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteResourceGuardProxyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestName", + Expected: &DeleteResourceGuardProxyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + DeleteResourceGuardProxyRequestName: "deleteResourceGuardProxyRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteResourceGuardProxyRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteResourceGuardProxyRequestName != v.Expected.DeleteResourceGuardProxyRequestName { + t.Fatalf("Expected %q but got %q for DeleteResourceGuardProxyRequestName", v.Expected.DeleteResourceGuardProxyRequestName, actual.DeleteResourceGuardProxyRequestName) + } + + } +} + +func TestParseDeleteResourceGuardProxyRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeleteResourceGuardProxyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dElEtErEsOuRcEgUaRdPrOxYrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestName", + Expected: &DeleteResourceGuardProxyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + DeleteResourceGuardProxyRequestName: "deleteResourceGuardProxyRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/deleteResourceGuardProxyRequests/deleteResourceGuardProxyRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dElEtErEsOuRcEgUaRdPrOxYrEqUeStS/dElEtErEsOuRcEgUaRdPrOxYrEqUeStNaMe", + Expected: &DeleteResourceGuardProxyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + DeleteResourceGuardProxyRequestName: "dElEtErEsOuRcEgUaRdPrOxYrEqUeStNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dElEtErEsOuRcEgUaRdPrOxYrEqUeStS/dElEtErEsOuRcEgUaRdPrOxYrEqUeStNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeleteResourceGuardProxyRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DeleteResourceGuardProxyRequestName != v.Expected.DeleteResourceGuardProxyRequestName { + t.Fatalf("Expected %q but got %q for DeleteResourceGuardProxyRequestName", v.Expected.DeleteResourceGuardProxyRequestName, actual.DeleteResourceGuardProxyRequestName) + } + + } +} + +func TestSegmentsForDeleteResourceGuardProxyRequestId(t *testing.T) { + segments := DeleteResourceGuardProxyRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeleteResourceGuardProxyRequestId 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/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest.go new file mode 100644 index 00000000000..bd69590ab7e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest.go @@ -0,0 +1,139 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DisableSoftDeleteRequestId{}) +} + +var _ resourceids.ResourceId = &DisableSoftDeleteRequestId{} + +// DisableSoftDeleteRequestId is a struct representing the Resource ID for a Disable Soft Delete Request +type DisableSoftDeleteRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + DisableSoftDeleteRequestName string +} + +// NewDisableSoftDeleteRequestID returns a new DisableSoftDeleteRequestId struct +func NewDisableSoftDeleteRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, disableSoftDeleteRequestName string) DisableSoftDeleteRequestId { + return DisableSoftDeleteRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + DisableSoftDeleteRequestName: disableSoftDeleteRequestName, + } +} + +// ParseDisableSoftDeleteRequestID parses 'input' into a DisableSoftDeleteRequestId +func ParseDisableSoftDeleteRequestID(input string) (*DisableSoftDeleteRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&DisableSoftDeleteRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DisableSoftDeleteRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDisableSoftDeleteRequestIDInsensitively parses 'input' case-insensitively into a DisableSoftDeleteRequestId +// note: this method should only be used for API response data and not user input +func ParseDisableSoftDeleteRequestIDInsensitively(input string) (*DisableSoftDeleteRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&DisableSoftDeleteRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DisableSoftDeleteRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DisableSoftDeleteRequestId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.DisableSoftDeleteRequestName, ok = input.Parsed["disableSoftDeleteRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "disableSoftDeleteRequestName", input) + } + + return nil +} + +// ValidateDisableSoftDeleteRequestID checks that 'input' can be parsed as a Disable Soft Delete Request ID +func ValidateDisableSoftDeleteRequestID(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 := ParseDisableSoftDeleteRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Disable Soft Delete Request ID +func (id DisableSoftDeleteRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/disableSoftDeleteRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.DisableSoftDeleteRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Disable Soft Delete Request ID +func (id DisableSoftDeleteRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + resourceids.StaticSegment("staticDisableSoftDeleteRequests", "disableSoftDeleteRequests", "disableSoftDeleteRequests"), + resourceids.UserSpecifiedSegment("disableSoftDeleteRequestName", "disableSoftDeleteRequestName"), + } +} + +// String returns a human-readable description of this Disable Soft Delete Request ID +func (id DisableSoftDeleteRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Disable Soft Delete Request Name: %q", id.DisableSoftDeleteRequestName), + } + return fmt.Sprintf("Disable Soft Delete Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest_test.go new file mode 100644 index 00000000000..ed2e45df963 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_disablesoftdeleterequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +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 = &DisableSoftDeleteRequestId{} + +func TestNewDisableSoftDeleteRequestID(t *testing.T) { + id := NewDisableSoftDeleteRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "disableSoftDeleteRequestName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } + + if id.DisableSoftDeleteRequestName != "disableSoftDeleteRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'DisableSoftDeleteRequestName'", id.DisableSoftDeleteRequestName, "disableSoftDeleteRequestName") + } +} + +func TestFormatDisableSoftDeleteRequestID(t *testing.T) { + actual := NewDisableSoftDeleteRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "disableSoftDeleteRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests/disableSoftDeleteRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDisableSoftDeleteRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DisableSoftDeleteRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests/disableSoftDeleteRequestName", + Expected: &DisableSoftDeleteRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + DisableSoftDeleteRequestName: "disableSoftDeleteRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests/disableSoftDeleteRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDisableSoftDeleteRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DisableSoftDeleteRequestName != v.Expected.DisableSoftDeleteRequestName { + t.Fatalf("Expected %q but got %q for DisableSoftDeleteRequestName", v.Expected.DisableSoftDeleteRequestName, actual.DisableSoftDeleteRequestName) + } + + } +} + +func TestParseDisableSoftDeleteRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DisableSoftDeleteRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dIsAbLeSoFtDeLeTeReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests/disableSoftDeleteRequestName", + Expected: &DisableSoftDeleteRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + DisableSoftDeleteRequestName: "disableSoftDeleteRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/disableSoftDeleteRequests/disableSoftDeleteRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dIsAbLeSoFtDeLeTeReQuEsTs/dIsAbLeSoFtDeLeTeReQuEsTnAmE", + Expected: &DisableSoftDeleteRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + DisableSoftDeleteRequestName: "dIsAbLeSoFtDeLeTeReQuEsTnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/dIsAbLeSoFtDeLeTeReQuEsTs/dIsAbLeSoFtDeLeTeReQuEsTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDisableSoftDeleteRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.DisableSoftDeleteRequestName != v.Expected.DisableSoftDeleteRequestName { + t.Fatalf("Expected %q but got %q for DisableSoftDeleteRequestName", v.Expected.DisableSoftDeleteRequestName, actual.DisableSoftDeleteRequestName) + } + + } +} + +func TestSegmentsForDisableSoftDeleteRequestId(t *testing.T) { + segments := DisableSoftDeleteRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DisableSoftDeleteRequestId 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/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest.go new file mode 100644 index 00000000000..73508192a58 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest.go @@ -0,0 +1,139 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GetBackupSecurityPINRequestId{}) +} + +var _ resourceids.ResourceId = &GetBackupSecurityPINRequestId{} + +// GetBackupSecurityPINRequestId is a struct representing the Resource ID for a Get Backup Security P I N Request +type GetBackupSecurityPINRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + GetBackupSecurityPINRequestName string +} + +// NewGetBackupSecurityPINRequestID returns a new GetBackupSecurityPINRequestId struct +func NewGetBackupSecurityPINRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, getBackupSecurityPINRequestName string) GetBackupSecurityPINRequestId { + return GetBackupSecurityPINRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + GetBackupSecurityPINRequestName: getBackupSecurityPINRequestName, + } +} + +// ParseGetBackupSecurityPINRequestID parses 'input' into a GetBackupSecurityPINRequestId +func ParseGetBackupSecurityPINRequestID(input string) (*GetBackupSecurityPINRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&GetBackupSecurityPINRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GetBackupSecurityPINRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGetBackupSecurityPINRequestIDInsensitively parses 'input' case-insensitively into a GetBackupSecurityPINRequestId +// note: this method should only be used for API response data and not user input +func ParseGetBackupSecurityPINRequestIDInsensitively(input string) (*GetBackupSecurityPINRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&GetBackupSecurityPINRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GetBackupSecurityPINRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GetBackupSecurityPINRequestId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.GetBackupSecurityPINRequestName, ok = input.Parsed["getBackupSecurityPINRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "getBackupSecurityPINRequestName", input) + } + + return nil +} + +// ValidateGetBackupSecurityPINRequestID checks that 'input' can be parsed as a Get Backup Security P I N Request ID +func ValidateGetBackupSecurityPINRequestID(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 := ParseGetBackupSecurityPINRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Get Backup Security P I N Request ID +func (id GetBackupSecurityPINRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/getBackupSecurityPINRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.GetBackupSecurityPINRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Get Backup Security P I N Request ID +func (id GetBackupSecurityPINRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + resourceids.StaticSegment("staticGetBackupSecurityPINRequests", "getBackupSecurityPINRequests", "getBackupSecurityPINRequests"), + resourceids.UserSpecifiedSegment("getBackupSecurityPINRequestName", "getBackupSecurityPINRequestName"), + } +} + +// String returns a human-readable description of this Get Backup Security P I N Request ID +func (id GetBackupSecurityPINRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Get Backup Security P I N Request Name: %q", id.GetBackupSecurityPINRequestName), + } + return fmt.Sprintf("Get Backup Security P I N Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest_test.go new file mode 100644 index 00000000000..cd05f745583 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_getbackupsecuritypinrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +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 = &GetBackupSecurityPINRequestId{} + +func TestNewGetBackupSecurityPINRequestID(t *testing.T) { + id := NewGetBackupSecurityPINRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "getBackupSecurityPINRequestName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } + + if id.GetBackupSecurityPINRequestName != "getBackupSecurityPINRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'GetBackupSecurityPINRequestName'", id.GetBackupSecurityPINRequestName, "getBackupSecurityPINRequestName") + } +} + +func TestFormatGetBackupSecurityPINRequestID(t *testing.T) { + actual := NewGetBackupSecurityPINRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "getBackupSecurityPINRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests/getBackupSecurityPINRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGetBackupSecurityPINRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GetBackupSecurityPINRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests/getBackupSecurityPINRequestName", + Expected: &GetBackupSecurityPINRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + GetBackupSecurityPINRequestName: "getBackupSecurityPINRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests/getBackupSecurityPINRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGetBackupSecurityPINRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.GetBackupSecurityPINRequestName != v.Expected.GetBackupSecurityPINRequestName { + t.Fatalf("Expected %q but got %q for GetBackupSecurityPINRequestName", v.Expected.GetBackupSecurityPINRequestName, actual.GetBackupSecurityPINRequestName) + } + + } +} + +func TestParseGetBackupSecurityPINRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GetBackupSecurityPINRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/gEtBaCkUpSeCuRiTyPiNrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests/getBackupSecurityPINRequestName", + Expected: &GetBackupSecurityPINRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + GetBackupSecurityPINRequestName: "getBackupSecurityPINRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/getBackupSecurityPINRequests/getBackupSecurityPINRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/gEtBaCkUpSeCuRiTyPiNrEqUeStS/gEtBaCkUpSeCuRiTyPiNrEqUeStNaMe", + Expected: &GetBackupSecurityPINRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + GetBackupSecurityPINRequestName: "gEtBaCkUpSeCuRiTyPiNrEqUeStNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/gEtBaCkUpSeCuRiTyPiNrEqUeStS/gEtBaCkUpSeCuRiTyPiNrEqUeStNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGetBackupSecurityPINRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.GetBackupSecurityPINRequestName != v.Expected.GetBackupSecurityPINRequestName { + t.Fatalf("Expected %q but got %q for GetBackupSecurityPINRequestName", v.Expected.GetBackupSecurityPINRequestName, actual.GetBackupSecurityPINRequestName) + } + + } +} + +func TestSegmentsForGetBackupSecurityPINRequestId(t *testing.T) { + segments := GetBackupSecurityPINRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GetBackupSecurityPINRequestId 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/dataprotection/2025-02-01/resourceguards/id_resourceguard.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard.go new file mode 100644 index 00000000000..d25e5e58ab8 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard.go @@ -0,0 +1,130 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResourceGuardId{}) +} + +var _ resourceids.ResourceId = &ResourceGuardId{} + +// ResourceGuardId is a struct representing the Resource ID for a Resource Guard +type ResourceGuardId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string +} + +// NewResourceGuardID returns a new ResourceGuardId struct +func NewResourceGuardID(subscriptionId string, resourceGroupName string, resourceGuardName string) ResourceGuardId { + return ResourceGuardId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + } +} + +// ParseResourceGuardID parses 'input' into a ResourceGuardId +func ParseResourceGuardID(input string) (*ResourceGuardId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGuardId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGuardId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceGuardIDInsensitively parses 'input' case-insensitively into a ResourceGuardId +// note: this method should only be used for API response data and not user input +func ParseResourceGuardIDInsensitively(input string) (*ResourceGuardId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGuardId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGuardId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceGuardId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + return nil +} + +// ValidateResourceGuardID checks that 'input' can be parsed as a Resource Guard ID +func ValidateResourceGuardID(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 := ParseResourceGuardID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Guard ID +func (id ResourceGuardId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Guard ID +func (id ResourceGuardId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + } +} + +// String returns a human-readable description of this Resource Guard ID +func (id ResourceGuardId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + } + return fmt.Sprintf("Resource Guard (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard_test.go new file mode 100644 index 00000000000..74d59cc7473 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_resourceguard_test.go @@ -0,0 +1,282 @@ +package resourceguards + +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 = &ResourceGuardId{} + +func TestNewResourceGuardID(t *testing.T) { + id := NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } +} + +func TestFormatResourceGuardID(t *testing.T) { + actual := NewResourceGuardID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceGuardID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGuardId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Expected: &ResourceGuardId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGuardID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + } +} + +func TestParseResourceGuardIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGuardId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Expected: &ResourceGuardId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Expected: &ResourceGuardId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGuardIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + } +} + +func TestSegmentsForResourceGuardId(t *testing.T) { + segments := ResourceGuardId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceGuardId 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/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest.go new file mode 100644 index 00000000000..5375caa22ab --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest.go @@ -0,0 +1,139 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UpdateProtectedItemRequestId{}) +} + +var _ resourceids.ResourceId = &UpdateProtectedItemRequestId{} + +// UpdateProtectedItemRequestId is a struct representing the Resource ID for a Update Protected Item Request +type UpdateProtectedItemRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + UpdateProtectedItemRequestName string +} + +// NewUpdateProtectedItemRequestID returns a new UpdateProtectedItemRequestId struct +func NewUpdateProtectedItemRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, updateProtectedItemRequestName string) UpdateProtectedItemRequestId { + return UpdateProtectedItemRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + UpdateProtectedItemRequestName: updateProtectedItemRequestName, + } +} + +// ParseUpdateProtectedItemRequestID parses 'input' into a UpdateProtectedItemRequestId +func ParseUpdateProtectedItemRequestID(input string) (*UpdateProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateProtectedItemRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectedItemRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateProtectedItemRequestIDInsensitively parses 'input' case-insensitively into a UpdateProtectedItemRequestId +// note: this method should only be used for API response data and not user input +func ParseUpdateProtectedItemRequestIDInsensitively(input string) (*UpdateProtectedItemRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateProtectedItemRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectedItemRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateProtectedItemRequestId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.UpdateProtectedItemRequestName, ok = input.Parsed["updateProtectedItemRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateProtectedItemRequestName", input) + } + + return nil +} + +// ValidateUpdateProtectedItemRequestID checks that 'input' can be parsed as a Update Protected Item Request ID +func ValidateUpdateProtectedItemRequestID(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 := ParseUpdateProtectedItemRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update Protected Item Request ID +func (id UpdateProtectedItemRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/updateProtectedItemRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.UpdateProtectedItemRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update Protected Item Request ID +func (id UpdateProtectedItemRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + resourceids.StaticSegment("staticUpdateProtectedItemRequests", "updateProtectedItemRequests", "updateProtectedItemRequests"), + resourceids.UserSpecifiedSegment("updateProtectedItemRequestName", "updateProtectedItemRequestName"), + } +} + +// String returns a human-readable description of this Update Protected Item Request ID +func (id UpdateProtectedItemRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Update Protected Item Request Name: %q", id.UpdateProtectedItemRequestName), + } + return fmt.Sprintf("Update Protected Item Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest_test.go new file mode 100644 index 00000000000..32c7d482013 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotecteditemrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +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 = &UpdateProtectedItemRequestId{} + +func TestNewUpdateProtectedItemRequestID(t *testing.T) { + id := NewUpdateProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "updateProtectedItemRequestName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } + + if id.UpdateProtectedItemRequestName != "updateProtectedItemRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateProtectedItemRequestName'", id.UpdateProtectedItemRequestName, "updateProtectedItemRequestName") + } +} + +func TestFormatUpdateProtectedItemRequestID(t *testing.T) { + actual := NewUpdateProtectedItemRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "updateProtectedItemRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests/updateProtectedItemRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateProtectedItemRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests/updateProtectedItemRequestName", + Expected: &UpdateProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + UpdateProtectedItemRequestName: "updateProtectedItemRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests/updateProtectedItemRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectedItemRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectedItemRequestName != v.Expected.UpdateProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectedItemRequestName", v.Expected.UpdateProtectedItemRequestName, actual.UpdateProtectedItemRequestName) + } + + } +} + +func TestParseUpdateProtectedItemRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectedItemRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/uPdAtEpRoTeCtEdItEmReQuEsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests/updateProtectedItemRequestName", + Expected: &UpdateProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + UpdateProtectedItemRequestName: "updateProtectedItemRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectedItemRequests/updateProtectedItemRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/uPdAtEpRoTeCtEdItEmReQuEsTs/uPdAtEpRoTeCtEdItEmReQuEsTnAmE", + Expected: &UpdateProtectedItemRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + UpdateProtectedItemRequestName: "uPdAtEpRoTeCtEdItEmReQuEsTnAmE", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/uPdAtEpRoTeCtEdItEmReQuEsTs/uPdAtEpRoTeCtEdItEmReQuEsTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectedItemRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectedItemRequestName != v.Expected.UpdateProtectedItemRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectedItemRequestName", v.Expected.UpdateProtectedItemRequestName, actual.UpdateProtectedItemRequestName) + } + + } +} + +func TestSegmentsForUpdateProtectedItemRequestId(t *testing.T) { + segments := UpdateProtectedItemRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateProtectedItemRequestId 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/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest.go new file mode 100644 index 00000000000..ad9cdaf67e7 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest.go @@ -0,0 +1,139 @@ +package resourceguards + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UpdateProtectionPolicyRequestId{}) +} + +var _ resourceids.ResourceId = &UpdateProtectionPolicyRequestId{} + +// UpdateProtectionPolicyRequestId is a struct representing the Resource ID for a Update Protection Policy Request +type UpdateProtectionPolicyRequestId struct { + SubscriptionId string + ResourceGroupName string + ResourceGuardName string + UpdateProtectionPolicyRequestName string +} + +// NewUpdateProtectionPolicyRequestID returns a new UpdateProtectionPolicyRequestId struct +func NewUpdateProtectionPolicyRequestID(subscriptionId string, resourceGroupName string, resourceGuardName string, updateProtectionPolicyRequestName string) UpdateProtectionPolicyRequestId { + return UpdateProtectionPolicyRequestId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceGuardName: resourceGuardName, + UpdateProtectionPolicyRequestName: updateProtectionPolicyRequestName, + } +} + +// ParseUpdateProtectionPolicyRequestID parses 'input' into a UpdateProtectionPolicyRequestId +func ParseUpdateProtectionPolicyRequestID(input string) (*UpdateProtectionPolicyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateProtectionPolicyRequestId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectionPolicyRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUpdateProtectionPolicyRequestIDInsensitively parses 'input' case-insensitively into a UpdateProtectionPolicyRequestId +// note: this method should only be used for API response data and not user input +func ParseUpdateProtectionPolicyRequestIDInsensitively(input string) (*UpdateProtectionPolicyRequestId, error) { + parser := resourceids.NewParserFromResourceIdType(&UpdateProtectionPolicyRequestId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UpdateProtectionPolicyRequestId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UpdateProtectionPolicyRequestId) 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.ResourceGuardName, ok = input.Parsed["resourceGuardName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGuardName", input) + } + + if id.UpdateProtectionPolicyRequestName, ok = input.Parsed["updateProtectionPolicyRequestName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "updateProtectionPolicyRequestName", input) + } + + return nil +} + +// ValidateUpdateProtectionPolicyRequestID checks that 'input' can be parsed as a Update Protection Policy Request ID +func ValidateUpdateProtectionPolicyRequestID(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 := ParseUpdateProtectionPolicyRequestID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Update Protection Policy Request ID +func (id UpdateProtectionPolicyRequestId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataProtection/resourceGuards/%s/updateProtectionPolicyRequests/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceGuardName, id.UpdateProtectionPolicyRequestName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Update Protection Policy Request ID +func (id UpdateProtectionPolicyRequestId) 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("staticMicrosoftDataProtection", "Microsoft.DataProtection", "Microsoft.DataProtection"), + resourceids.StaticSegment("staticResourceGuards", "resourceGuards", "resourceGuards"), + resourceids.UserSpecifiedSegment("resourceGuardName", "resourceGuardName"), + resourceids.StaticSegment("staticUpdateProtectionPolicyRequests", "updateProtectionPolicyRequests", "updateProtectionPolicyRequests"), + resourceids.UserSpecifiedSegment("updateProtectionPolicyRequestName", "updateProtectionPolicyRequestName"), + } +} + +// String returns a human-readable description of this Update Protection Policy Request ID +func (id UpdateProtectionPolicyRequestId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Guard Name: %q", id.ResourceGuardName), + fmt.Sprintf("Update Protection Policy Request Name: %q", id.UpdateProtectionPolicyRequestName), + } + return fmt.Sprintf("Update Protection Policy Request (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest_test.go b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest_test.go new file mode 100644 index 00000000000..5fbbb38db64 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/id_updateprotectionpolicyrequest_test.go @@ -0,0 +1,327 @@ +package resourceguards + +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 = &UpdateProtectionPolicyRequestId{} + +func TestNewUpdateProtectionPolicyRequestID(t *testing.T) { + id := NewUpdateProtectionPolicyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "updateProtectionPolicyRequestName") + + 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.ResourceGuardName != "resourceGuardName" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGuardName'", id.ResourceGuardName, "resourceGuardName") + } + + if id.UpdateProtectionPolicyRequestName != "updateProtectionPolicyRequestName" { + t.Fatalf("Expected %q but got %q for Segment 'UpdateProtectionPolicyRequestName'", id.UpdateProtectionPolicyRequestName, "updateProtectionPolicyRequestName") + } +} + +func TestFormatUpdateProtectionPolicyRequestID(t *testing.T) { + actual := NewUpdateProtectionPolicyRequestID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceGuardName", "updateProtectionPolicyRequestName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests/updateProtectionPolicyRequestName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUpdateProtectionPolicyRequestID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectionPolicyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests/updateProtectionPolicyRequestName", + Expected: &UpdateProtectionPolicyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + UpdateProtectionPolicyRequestName: "updateProtectionPolicyRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests/updateProtectionPolicyRequestName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectionPolicyRequestID(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectionPolicyRequestName != v.Expected.UpdateProtectionPolicyRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectionPolicyRequestName", v.Expected.UpdateProtectionPolicyRequestName, actual.UpdateProtectionPolicyRequestName) + } + + } +} + +func TestParseUpdateProtectionPolicyRequestIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UpdateProtectionPolicyRequestId + }{ + { + // 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.DataProtection", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/uPdAtEpRoTeCtIoNpOlIcYrEqUeStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests/updateProtectionPolicyRequestName", + Expected: &UpdateProtectionPolicyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceGuardName: "resourceGuardName", + UpdateProtectionPolicyRequestName: "updateProtectionPolicyRequestName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DataProtection/resourceGuards/resourceGuardName/updateProtectionPolicyRequests/updateProtectionPolicyRequestName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/uPdAtEpRoTeCtIoNpOlIcYrEqUeStS/uPdAtEpRoTeCtIoNpOlIcYrEqUeStNaMe", + Expected: &UpdateProtectionPolicyRequestId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceGuardName: "rEsOuRcEgUaRdNaMe", + UpdateProtectionPolicyRequestName: "uPdAtEpRoTeCtIoNpOlIcYrEqUeStNaMe", + }, + }, + { + // 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.dAtApRoTeCtIoN/rEsOuRcEgUaRdS/rEsOuRcEgUaRdNaMe/uPdAtEpRoTeCtIoNpOlIcYrEqUeStS/uPdAtEpRoTeCtIoNpOlIcYrEqUeStNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUpdateProtectionPolicyRequestIDInsensitively(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.ResourceGuardName != v.Expected.ResourceGuardName { + t.Fatalf("Expected %q but got %q for ResourceGuardName", v.Expected.ResourceGuardName, actual.ResourceGuardName) + } + + if actual.UpdateProtectionPolicyRequestName != v.Expected.UpdateProtectionPolicyRequestName { + t.Fatalf("Expected %q but got %q for UpdateProtectionPolicyRequestName", v.Expected.UpdateProtectionPolicyRequestName, actual.UpdateProtectionPolicyRequestName) + } + + } +} + +func TestSegmentsForUpdateProtectionPolicyRequestId(t *testing.T) { + segments := UpdateProtectionPolicyRequestId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UpdateProtectionPolicyRequestId 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/dataprotection/2025-02-01/resourceguards/method_delete.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_delete.go new file mode 100644 index 00000000000..7641951700d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_delete.go @@ -0,0 +1,47 @@ +package resourceguards + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ResourceGuardsClient) Delete(ctx context.Context, id ResourceGuardId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_get.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_get.go new file mode 100644 index 00000000000..8c3fae9b334 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_get.go @@ -0,0 +1,53 @@ +package resourceguards + +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 *ResourceGuardResource +} + +// Get ... +func (c ResourceGuardsClient) Get(ctx context.Context, id ResourceGuardId) (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 ResourceGuardResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go new file mode 100644 index 00000000000..eb8eaeca22e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getbackupsecuritypinrequestsobjects.go @@ -0,0 +1,105 @@ +package resourceguards + +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 GetBackupSecurityPINRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetBackupSecurityPINRequestsObjectsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DppBaseResource +} + +type GetBackupSecurityPINRequestsObjectsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetBackupSecurityPINRequestsObjectsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetBackupSecurityPINRequestsObjects ... +func (c ResourceGuardsClient) GetBackupSecurityPINRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetBackupSecurityPINRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetBackupSecurityPINRequestsObjectsCustomPager{}, + Path: fmt.Sprintf("%s/getBackupSecurityPINRequests", 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 *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetBackupSecurityPINRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetBackupSecurityPINRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetBackupSecurityPINRequestsObjectsCompleteResult, error) { + return c.GetBackupSecurityPINRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetBackupSecurityPINRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetBackupSecurityPINRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetBackupSecurityPINRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetBackupSecurityPINRequestsObjects(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetBackupSecurityPINRequestsObjectsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go new file mode 100644 index 00000000000..c4c17baa63e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultbackupsecuritypinrequestsobject.go @@ -0,0 +1,53 @@ +package resourceguards + +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 GetDefaultBackupSecurityPINRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultBackupSecurityPINRequestsObject ... +func (c ResourceGuardsClient) GetDefaultBackupSecurityPINRequestsObject(ctx context.Context, id GetBackupSecurityPINRequestId) (result GetDefaultBackupSecurityPINRequestsObjectOperationResponse, 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 DppBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go new file mode 100644 index 00000000000..01a918c9ed2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteprotecteditemrequestsobject.go @@ -0,0 +1,53 @@ +package resourceguards + +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 GetDefaultDeleteProtectedItemRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultDeleteProtectedItemRequestsObject ... +func (c ResourceGuardsClient) GetDefaultDeleteProtectedItemRequestsObject(ctx context.Context, id DeleteProtectedItemRequestId) (result GetDefaultDeleteProtectedItemRequestsObjectOperationResponse, 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 DppBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go new file mode 100644 index 00000000000..94bb22e07d2 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdeleteresourceguardproxyrequestsobject.go @@ -0,0 +1,53 @@ +package resourceguards + +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 GetDefaultDeleteResourceGuardProxyRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultDeleteResourceGuardProxyRequestsObject ... +func (c ResourceGuardsClient) GetDefaultDeleteResourceGuardProxyRequestsObject(ctx context.Context, id DeleteResourceGuardProxyRequestId) (result GetDefaultDeleteResourceGuardProxyRequestsObjectOperationResponse, 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 DppBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go new file mode 100644 index 00000000000..cf1270f04a5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultdisablesoftdeleterequestsobject.go @@ -0,0 +1,53 @@ +package resourceguards + +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 GetDefaultDisableSoftDeleteRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultDisableSoftDeleteRequestsObject ... +func (c ResourceGuardsClient) GetDefaultDisableSoftDeleteRequestsObject(ctx context.Context, id DisableSoftDeleteRequestId) (result GetDefaultDisableSoftDeleteRequestsObjectOperationResponse, 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 DppBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go new file mode 100644 index 00000000000..22159bc163f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotecteditemrequestsobject.go @@ -0,0 +1,53 @@ +package resourceguards + +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 GetDefaultUpdateProtectedItemRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultUpdateProtectedItemRequestsObject ... +func (c ResourceGuardsClient) GetDefaultUpdateProtectedItemRequestsObject(ctx context.Context, id UpdateProtectedItemRequestId) (result GetDefaultUpdateProtectedItemRequestsObjectOperationResponse, 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 DppBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go new file mode 100644 index 00000000000..a2389d2fd93 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdefaultupdateprotectionpolicyrequestsobject.go @@ -0,0 +1,53 @@ +package resourceguards + +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 GetDefaultUpdateProtectionPolicyRequestsObjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DppBaseResource +} + +// GetDefaultUpdateProtectionPolicyRequestsObject ... +func (c ResourceGuardsClient) GetDefaultUpdateProtectionPolicyRequestsObject(ctx context.Context, id UpdateProtectionPolicyRequestId) (result GetDefaultUpdateProtectionPolicyRequestsObjectOperationResponse, 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 DppBaseResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go new file mode 100644 index 00000000000..ce93828e11f --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteprotecteditemrequestsobjects.go @@ -0,0 +1,105 @@ +package resourceguards + +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 GetDeleteProtectedItemRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetDeleteProtectedItemRequestsObjectsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DppBaseResource +} + +type GetDeleteProtectedItemRequestsObjectsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetDeleteProtectedItemRequestsObjectsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetDeleteProtectedItemRequestsObjects ... +func (c ResourceGuardsClient) GetDeleteProtectedItemRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetDeleteProtectedItemRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetDeleteProtectedItemRequestsObjectsCustomPager{}, + Path: fmt.Sprintf("%s/deleteProtectedItemRequests", 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 *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetDeleteProtectedItemRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetDeleteProtectedItemRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetDeleteProtectedItemRequestsObjectsCompleteResult, error) { + return c.GetDeleteProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetDeleteProtectedItemRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetDeleteProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetDeleteProtectedItemRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetDeleteProtectedItemRequestsObjects(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetDeleteProtectedItemRequestsObjectsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go new file mode 100644 index 00000000000..5f987f2de5d --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdeleteresourceguardproxyrequestsobjects.go @@ -0,0 +1,105 @@ +package resourceguards + +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 GetDeleteResourceGuardProxyRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetDeleteResourceGuardProxyRequestsObjectsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DppBaseResource +} + +type GetDeleteResourceGuardProxyRequestsObjectsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetDeleteResourceGuardProxyRequestsObjectsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetDeleteResourceGuardProxyRequestsObjects ... +func (c ResourceGuardsClient) GetDeleteResourceGuardProxyRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetDeleteResourceGuardProxyRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetDeleteResourceGuardProxyRequestsObjectsCustomPager{}, + Path: fmt.Sprintf("%s/deleteResourceGuardProxyRequests", 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 *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetDeleteResourceGuardProxyRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetDeleteResourceGuardProxyRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetDeleteResourceGuardProxyRequestsObjectsCompleteResult, error) { + return c.GetDeleteResourceGuardProxyRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetDeleteResourceGuardProxyRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetDeleteResourceGuardProxyRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetDeleteResourceGuardProxyRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetDeleteResourceGuardProxyRequestsObjects(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetDeleteResourceGuardProxyRequestsObjectsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go new file mode 100644 index 00000000000..eae3ca213ba --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getdisablesoftdeleterequestsobjects.go @@ -0,0 +1,105 @@ +package resourceguards + +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 GetDisableSoftDeleteRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetDisableSoftDeleteRequestsObjectsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DppBaseResource +} + +type GetDisableSoftDeleteRequestsObjectsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetDisableSoftDeleteRequestsObjectsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetDisableSoftDeleteRequestsObjects ... +func (c ResourceGuardsClient) GetDisableSoftDeleteRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetDisableSoftDeleteRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetDisableSoftDeleteRequestsObjectsCustomPager{}, + Path: fmt.Sprintf("%s/disableSoftDeleteRequests", 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 *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetDisableSoftDeleteRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetDisableSoftDeleteRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetDisableSoftDeleteRequestsObjectsCompleteResult, error) { + return c.GetDisableSoftDeleteRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetDisableSoftDeleteRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetDisableSoftDeleteRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetDisableSoftDeleteRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetDisableSoftDeleteRequestsObjects(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetDisableSoftDeleteRequestsObjectsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinresourcegroup.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinresourcegroup.go new file mode 100644 index 00000000000..9a343eb189a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinresourcegroup.go @@ -0,0 +1,106 @@ +package resourceguards + +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 GetResourcesInResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceGuardResource +} + +type GetResourcesInResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceGuardResource +} + +type GetResourcesInResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetResourcesInResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetResourcesInResourceGroup ... +func (c ResourceGuardsClient) GetResourcesInResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result GetResourcesInResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetResourcesInResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/resourceGuards", 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 *[]ResourceGuardResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetResourcesInResourceGroupComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetResourcesInResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (GetResourcesInResourceGroupCompleteResult, error) { + return c.GetResourcesInResourceGroupCompleteMatchingPredicate(ctx, id, ResourceGuardResourceOperationPredicate{}) +} + +// GetResourcesInResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetResourcesInResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ResourceGuardResourceOperationPredicate) (result GetResourcesInResourceGroupCompleteResult, err error) { + items := make([]ResourceGuardResource, 0) + + resp, err := c.GetResourcesInResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetResourcesInResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinsubscription.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinsubscription.go new file mode 100644 index 00000000000..7eeda1e8c26 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getresourcesinsubscription.go @@ -0,0 +1,106 @@ +package resourceguards + +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 GetResourcesInSubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceGuardResource +} + +type GetResourcesInSubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceGuardResource +} + +type GetResourcesInSubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetResourcesInSubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetResourcesInSubscription ... +func (c ResourceGuardsClient) GetResourcesInSubscription(ctx context.Context, id commonids.SubscriptionId) (result GetResourcesInSubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetResourcesInSubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.DataProtection/resourceGuards", 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 *[]ResourceGuardResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetResourcesInSubscriptionComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetResourcesInSubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (GetResourcesInSubscriptionCompleteResult, error) { + return c.GetResourcesInSubscriptionCompleteMatchingPredicate(ctx, id, ResourceGuardResourceOperationPredicate{}) +} + +// GetResourcesInSubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetResourcesInSubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ResourceGuardResourceOperationPredicate) (result GetResourcesInSubscriptionCompleteResult, err error) { + items := make([]ResourceGuardResource, 0) + + resp, err := c.GetResourcesInSubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetResourcesInSubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go new file mode 100644 index 00000000000..940b6f72f0e --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotecteditemrequestsobjects.go @@ -0,0 +1,105 @@ +package resourceguards + +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 GetUpdateProtectedItemRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetUpdateProtectedItemRequestsObjectsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DppBaseResource +} + +type GetUpdateProtectedItemRequestsObjectsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetUpdateProtectedItemRequestsObjectsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetUpdateProtectedItemRequestsObjects ... +func (c ResourceGuardsClient) GetUpdateProtectedItemRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetUpdateProtectedItemRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetUpdateProtectedItemRequestsObjectsCustomPager{}, + Path: fmt.Sprintf("%s/updateProtectedItemRequests", 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 *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetUpdateProtectedItemRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetUpdateProtectedItemRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetUpdateProtectedItemRequestsObjectsCompleteResult, error) { + return c.GetUpdateProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetUpdateProtectedItemRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetUpdateProtectedItemRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetUpdateProtectedItemRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetUpdateProtectedItemRequestsObjects(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetUpdateProtectedItemRequestsObjectsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go new file mode 100644 index 00000000000..fc30cd7b71a --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_getupdateprotectionpolicyrequestsobjects.go @@ -0,0 +1,105 @@ +package resourceguards + +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 GetUpdateProtectionPolicyRequestsObjectsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DppBaseResource +} + +type GetUpdateProtectionPolicyRequestsObjectsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DppBaseResource +} + +type GetUpdateProtectionPolicyRequestsObjectsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *GetUpdateProtectionPolicyRequestsObjectsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// GetUpdateProtectionPolicyRequestsObjects ... +func (c ResourceGuardsClient) GetUpdateProtectionPolicyRequestsObjects(ctx context.Context, id ResourceGuardId) (result GetUpdateProtectionPolicyRequestsObjectsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &GetUpdateProtectionPolicyRequestsObjectsCustomPager{}, + Path: fmt.Sprintf("%s/updateProtectionPolicyRequests", 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 *[]DppBaseResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GetUpdateProtectionPolicyRequestsObjectsComplete retrieves all the results into a single object +func (c ResourceGuardsClient) GetUpdateProtectionPolicyRequestsObjectsComplete(ctx context.Context, id ResourceGuardId) (GetUpdateProtectionPolicyRequestsObjectsCompleteResult, error) { + return c.GetUpdateProtectionPolicyRequestsObjectsCompleteMatchingPredicate(ctx, id, DppBaseResourceOperationPredicate{}) +} + +// GetUpdateProtectionPolicyRequestsObjectsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGuardsClient) GetUpdateProtectionPolicyRequestsObjectsCompleteMatchingPredicate(ctx context.Context, id ResourceGuardId, predicate DppBaseResourceOperationPredicate) (result GetUpdateProtectionPolicyRequestsObjectsCompleteResult, err error) { + items := make([]DppBaseResource, 0) + + resp, err := c.GetUpdateProtectionPolicyRequestsObjects(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = GetUpdateProtectionPolicyRequestsObjectsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_patch.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_patch.go new file mode 100644 index 00000000000..0f38b0517b3 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_patch.go @@ -0,0 +1,57 @@ +package resourceguards + +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 PatchOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGuardResource +} + +// Patch ... +func (c ResourceGuardsClient) Patch(ctx context.Context, id ResourceGuardId, input PatchResourceGuardInput) (result PatchOperationResponse, 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 ResourceGuardResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/method_put.go b/resource-manager/dataprotection/2025-02-01/resourceguards/method_put.go new file mode 100644 index 00000000000..c71ad58adca --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/method_put.go @@ -0,0 +1,58 @@ +package resourceguards + +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 *ResourceGuardResource +} + +// Put ... +func (c ResourceGuardsClient) Put(ctx context.Context, id ResourceGuardId, input ResourceGuardResource) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ResourceGuardResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/model_dppbaseresource.go b/resource-manager/dataprotection/2025-02-01/resourceguards/model_dppbaseresource.go new file mode 100644 index 00000000000..68d4e93d8b5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/model_dppbaseresource.go @@ -0,0 +1,10 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppBaseResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/model_patchresourceguardinput.go b/resource-manager/dataprotection/2025-02-01/resourceguards/model_patchresourceguardinput.go new file mode 100644 index 00000000000..f1fedc23f9b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/model_patchresourceguardinput.go @@ -0,0 +1,8 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchResourceGuardInput struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguard.go b/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguard.go new file mode 100644 index 00000000000..968af9fa9f5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguard.go @@ -0,0 +1,12 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuard struct { + AllowAutoApprovals *bool `json:"allowAutoApprovals,omitempty"` + Description *string `json:"description,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ResourceGuardOperations *[]ResourceGuardOperation `json:"resourceGuardOperations,omitempty"` + VaultCriticalOperationExclusionList *[]string `json:"vaultCriticalOperationExclusionList,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardoperation.go b/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardoperation.go new file mode 100644 index 00000000000..db7b25d6e59 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardoperation.go @@ -0,0 +1,9 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGuardOperation struct { + RequestResourceType *string `json:"requestResourceType,omitempty"` + VaultCriticalOperation *string `json:"vaultCriticalOperation,omitempty"` +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardresource.go b/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardresource.go new file mode 100644 index 00000000000..16508017629 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/model_resourceguardresource.go @@ -0,0 +1,19 @@ +package resourceguards + +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 ResourceGuardResource struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGuard `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/dataprotection/2025-02-01/resourceguards/predicates.go b/resource-manager/dataprotection/2025-02-01/resourceguards/predicates.go new file mode 100644 index 00000000000..839d8fbca1b --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/predicates.go @@ -0,0 +1,60 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DppBaseResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DppBaseResourceOperationPredicate) Matches(input DppBaseResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ResourceGuardResourceOperationPredicate struct { + ETag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ResourceGuardResourceOperationPredicate) Matches(input ResourceGuardResource) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/dataprotection/2025-02-01/resourceguards/version.go b/resource-manager/dataprotection/2025-02-01/resourceguards/version.go new file mode 100644 index 00000000000..b0e6cedc2b5 --- /dev/null +++ b/resource-manager/dataprotection/2025-02-01/resourceguards/version.go @@ -0,0 +1,10 @@ +package resourceguards + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/resourceguards/2025-02-01" +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/README.md b/resource-manager/hybridcompute/2025-01-13/agentversions/README.md new file mode 100644 index 00000000000..9bc6d12b979 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/agentversions` Documentation + +The `agentversions` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/agentversions" +``` + + +### Client Initialization + +```go +client := agentversions.NewAgentVersionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AgentVersionsClient.AgentVersionGet` + +```go +ctx := context.TODO() +id := agentversions.NewAgentVersionID("osTypeName", "agentVersionName") + +read, err := client.AgentVersionGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AgentVersionsClient.AgentVersionList` + +```go +ctx := context.TODO() +id := agentversions.NewOsTypeID("osTypeName") + +// alternatively `client.AgentVersionList(ctx, id)` can be used to do batched pagination +items, err := client.AgentVersionListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/client.go b/resource-manager/hybridcompute/2025-01-13/agentversions/client.go new file mode 100644 index 00000000000..43ff0e88098 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/client.go @@ -0,0 +1,26 @@ +package agentversions + +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 AgentVersionsClient struct { + Client *resourcemanager.Client +} + +func NewAgentVersionsClientWithBaseURI(sdkApi sdkEnv.Api) (*AgentVersionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "agentversions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AgentVersionsClient: %+v", err) + } + + return &AgentVersionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion.go b/resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion.go new file mode 100644 index 00000000000..db8c8fb3be8 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion.go @@ -0,0 +1,121 @@ +package agentversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AgentVersionId{}) +} + +var _ resourceids.ResourceId = &AgentVersionId{} + +// AgentVersionId is a struct representing the Resource ID for a Agent Version +type AgentVersionId struct { + OsTypeName string + AgentVersionName string +} + +// NewAgentVersionID returns a new AgentVersionId struct +func NewAgentVersionID(osTypeName string, agentVersionName string) AgentVersionId { + return AgentVersionId{ + OsTypeName: osTypeName, + AgentVersionName: agentVersionName, + } +} + +// ParseAgentVersionID parses 'input' into a AgentVersionId +func ParseAgentVersionID(input string) (*AgentVersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&AgentVersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AgentVersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAgentVersionIDInsensitively parses 'input' case-insensitively into a AgentVersionId +// note: this method should only be used for API response data and not user input +func ParseAgentVersionIDInsensitively(input string) (*AgentVersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&AgentVersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AgentVersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AgentVersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.OsTypeName, ok = input.Parsed["osTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "osTypeName", input) + } + + if id.AgentVersionName, ok = input.Parsed["agentVersionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "agentVersionName", input) + } + + return nil +} + +// ValidateAgentVersionID checks that 'input' can be parsed as a Agent Version ID +func ValidateAgentVersionID(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 := ParseAgentVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Agent Version ID +func (id AgentVersionId) ID() string { + fmtString := "/providers/Microsoft.HybridCompute/osType/%s/agentVersions/%s" + return fmt.Sprintf(fmtString, id.OsTypeName, id.AgentVersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Agent Version ID +func (id AgentVersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticOsType", "osType", "osType"), + resourceids.UserSpecifiedSegment("osTypeName", "osTypeName"), + resourceids.StaticSegment("staticAgentVersions", "agentVersions", "agentVersions"), + resourceids.UserSpecifiedSegment("agentVersionName", "agentVersionName"), + } +} + +// String returns a human-readable description of this Agent Version ID +func (id AgentVersionId) String() string { + components := []string{ + fmt.Sprintf("Os Type Name: %q", id.OsTypeName), + fmt.Sprintf("Agent Version Name: %q", id.AgentVersionName), + } + return fmt.Sprintf("Agent Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion_test.go b/resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion_test.go new file mode 100644 index 00000000000..f1531e02399 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/id_agentversion_test.go @@ -0,0 +1,237 @@ +package agentversions + +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 = &AgentVersionId{} + +func TestNewAgentVersionID(t *testing.T) { + id := NewAgentVersionID("osTypeName", "agentVersionName") + + if id.OsTypeName != "osTypeName" { + t.Fatalf("Expected %q but got %q for Segment 'OsTypeName'", id.OsTypeName, "osTypeName") + } + + if id.AgentVersionName != "agentVersionName" { + t.Fatalf("Expected %q but got %q for Segment 'AgentVersionName'", id.AgentVersionName, "agentVersionName") + } +} + +func TestFormatAgentVersionID(t *testing.T) { + actual := NewAgentVersionID("osTypeName", "agentVersionName").ID() + expected := "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions/agentVersionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAgentVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AgentVersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions/agentVersionName", + Expected: &AgentVersionId{ + OsTypeName: "osTypeName", + AgentVersionName: "agentVersionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions/agentVersionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAgentVersionID(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.OsTypeName != v.Expected.OsTypeName { + t.Fatalf("Expected %q but got %q for OsTypeName", v.Expected.OsTypeName, actual.OsTypeName) + } + + if actual.AgentVersionName != v.Expected.AgentVersionName { + t.Fatalf("Expected %q but got %q for AgentVersionName", v.Expected.AgentVersionName, actual.AgentVersionName) + } + + } +} + +func TestParseAgentVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AgentVersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE/oStYpEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE/oStYpEnAmE/aGeNtVeRsIoNs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions/agentVersionName", + Expected: &AgentVersionId{ + OsTypeName: "osTypeName", + AgentVersionName: "agentVersionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/agentVersions/agentVersionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE/oStYpEnAmE/aGeNtVeRsIoNs/aGeNtVeRsIoNnAmE", + Expected: &AgentVersionId{ + OsTypeName: "oStYpEnAmE", + AgentVersionName: "aGeNtVeRsIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE/oStYpEnAmE/aGeNtVeRsIoNs/aGeNtVeRsIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAgentVersionIDInsensitively(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.OsTypeName != v.Expected.OsTypeName { + t.Fatalf("Expected %q but got %q for OsTypeName", v.Expected.OsTypeName, actual.OsTypeName) + } + + if actual.AgentVersionName != v.Expected.AgentVersionName { + t.Fatalf("Expected %q but got %q for AgentVersionName", v.Expected.AgentVersionName, actual.AgentVersionName) + } + + } +} + +func TestSegmentsForAgentVersionId(t *testing.T) { + segments := AgentVersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AgentVersionId 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/hybridcompute/2025-01-13/agentversions/id_ostype.go b/resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype.go new file mode 100644 index 00000000000..58b12967543 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype.go @@ -0,0 +1,112 @@ +package agentversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OsTypeId{}) +} + +var _ resourceids.ResourceId = &OsTypeId{} + +// OsTypeId is a struct representing the Resource ID for a Os Type +type OsTypeId struct { + OsTypeName string +} + +// NewOsTypeID returns a new OsTypeId struct +func NewOsTypeID(osTypeName string) OsTypeId { + return OsTypeId{ + OsTypeName: osTypeName, + } +} + +// ParseOsTypeID parses 'input' into a OsTypeId +func ParseOsTypeID(input string) (*OsTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&OsTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OsTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOsTypeIDInsensitively parses 'input' case-insensitively into a OsTypeId +// note: this method should only be used for API response data and not user input +func ParseOsTypeIDInsensitively(input string) (*OsTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&OsTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OsTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OsTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.OsTypeName, ok = input.Parsed["osTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "osTypeName", input) + } + + return nil +} + +// ValidateOsTypeID checks that 'input' can be parsed as a Os Type ID +func ValidateOsTypeID(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 := ParseOsTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Os Type ID +func (id OsTypeId) ID() string { + fmtString := "/providers/Microsoft.HybridCompute/osType/%s" + return fmt.Sprintf(fmtString, id.OsTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Os Type ID +func (id OsTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticOsType", "osType", "osType"), + resourceids.UserSpecifiedSegment("osTypeName", "osTypeName"), + } +} + +// String returns a human-readable description of this Os Type ID +func (id OsTypeId) String() string { + components := []string{ + fmt.Sprintf("Os Type Name: %q", id.OsTypeName), + } + return fmt.Sprintf("Os Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype_test.go b/resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype_test.go new file mode 100644 index 00000000000..e99bd3f66a4 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/id_ostype_test.go @@ -0,0 +1,192 @@ +package agentversions + +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 = &OsTypeId{} + +func TestNewOsTypeID(t *testing.T) { + id := NewOsTypeID("osTypeName") + + if id.OsTypeName != "osTypeName" { + t.Fatalf("Expected %q but got %q for Segment 'OsTypeName'", id.OsTypeName, "osTypeName") + } +} + +func TestFormatOsTypeID(t *testing.T) { + actual := NewOsTypeID("osTypeName").ID() + expected := "/providers/Microsoft.HybridCompute/osType/osTypeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOsTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OsTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName", + Expected: &OsTypeId{ + OsTypeName: "osTypeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOsTypeID(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.OsTypeName != v.Expected.OsTypeName { + t.Fatalf("Expected %q but got %q for OsTypeName", v.Expected.OsTypeName, actual.OsTypeName) + } + + } +} + +func TestParseOsTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OsTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/osType", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName", + Expected: &OsTypeId{ + OsTypeName: "osTypeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/osType/osTypeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE/oStYpEnAmE", + Expected: &OsTypeId{ + OsTypeName: "oStYpEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/oStYpE/oStYpEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOsTypeIDInsensitively(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.OsTypeName != v.Expected.OsTypeName { + t.Fatalf("Expected %q but got %q for OsTypeName", v.Expected.OsTypeName, actual.OsTypeName) + } + + } +} + +func TestSegmentsForOsTypeId(t *testing.T) { + segments := OsTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OsTypeId 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/hybridcompute/2025-01-13/agentversions/method_agentversionget.go b/resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionget.go new file mode 100644 index 00000000000..f65b1e9ebcc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionget.go @@ -0,0 +1,53 @@ +package agentversions + +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 AgentVersionGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AgentVersion +} + +// AgentVersionGet ... +func (c AgentVersionsClient) AgentVersionGet(ctx context.Context, id AgentVersionId) (result AgentVersionGetOperationResponse, 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 AgentVersion + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionlist.go b/resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionlist.go new file mode 100644 index 00000000000..a256ba792dd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/method_agentversionlist.go @@ -0,0 +1,105 @@ +package agentversions + +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 AgentVersionListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AgentVersion +} + +type AgentVersionListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AgentVersion +} + +type AgentVersionListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AgentVersionListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AgentVersionList ... +func (c AgentVersionsClient) AgentVersionList(ctx context.Context, id OsTypeId) (result AgentVersionListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AgentVersionListCustomPager{}, + Path: fmt.Sprintf("%s/agentVersions", 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 *[]AgentVersion `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AgentVersionListComplete retrieves all the results into a single object +func (c AgentVersionsClient) AgentVersionListComplete(ctx context.Context, id OsTypeId) (AgentVersionListCompleteResult, error) { + return c.AgentVersionListCompleteMatchingPredicate(ctx, id, AgentVersionOperationPredicate{}) +} + +// AgentVersionListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AgentVersionsClient) AgentVersionListCompleteMatchingPredicate(ctx context.Context, id OsTypeId, predicate AgentVersionOperationPredicate) (result AgentVersionListCompleteResult, err error) { + items := make([]AgentVersion, 0) + + resp, err := c.AgentVersionList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AgentVersionListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/model_agentversion.go b/resource-manager/hybridcompute/2025-01-13/agentversions/model_agentversion.go new file mode 100644 index 00000000000..118edfd2707 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/model_agentversion.go @@ -0,0 +1,10 @@ +package agentversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentVersion struct { + AgentVersion *string `json:"agentVersion,omitempty"` + DownloadLink *string `json:"downloadLink,omitempty"` + OsType *string `json:"osType,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/predicates.go b/resource-manager/hybridcompute/2025-01-13/agentversions/predicates.go new file mode 100644 index 00000000000..e6c94b5c059 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/predicates.go @@ -0,0 +1,27 @@ +package agentversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentVersionOperationPredicate struct { + AgentVersion *string + DownloadLink *string + OsType *string +} + +func (p AgentVersionOperationPredicate) Matches(input AgentVersion) bool { + + if p.AgentVersion != nil && (input.AgentVersion == nil || *p.AgentVersion != *input.AgentVersion) { + return false + } + + if p.DownloadLink != nil && (input.DownloadLink == nil || *p.DownloadLink != *input.DownloadLink) { + return false + } + + if p.OsType != nil && (input.OsType == nil || *p.OsType != *input.OsType) { + return false + } + + return true +} diff --git a/resource-manager/hybridcompute/2025-01-13/agentversions/version.go b/resource-manager/hybridcompute/2025-01-13/agentversions/version.go new file mode 100644 index 00000000000..da6f84c79fd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/agentversions/version.go @@ -0,0 +1,10 @@ +package agentversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/agentversions/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/client.go b/resource-manager/hybridcompute/2025-01-13/client.go new file mode 100644 index 00000000000..82fc80600ff --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/client.go @@ -0,0 +1,181 @@ +package v2025_01_13 + +// 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/hybridcompute/2025-01-13/agentversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/extensions" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/gateways" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/licenseprofiles" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/licenses" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineextensions" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineextensionssetup" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineruncommands" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machines" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/networkconfigurations" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/privatelinkscopes" + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/settings" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AgentVersions *agentversions.AgentVersionsClient + Extensions *extensions.ExtensionsClient + Gateways *gateways.GatewaysClient + HybridIdentityMetadata *hybrididentitymetadata.HybridIdentityMetadataClient + LicenseProfiles *licenseprofiles.LicenseProfilesClient + Licenses *licenses.LicensesClient + MachineExtensions *machineextensions.MachineExtensionsClient + MachineExtensionsSetup *machineextensionssetup.MachineExtensionsSetupClient + MachineExtensionsUpgrade *machineextensionsupgrade.MachineExtensionsUpgradeClient + MachineNetworkProfile *machinenetworkprofile.MachineNetworkProfileClient + MachineRunCommands *machineruncommands.MachineRunCommandsClient + Machines *machines.MachinesClient + NetworkConfigurations *networkconfigurations.NetworkConfigurationsClient + NetworkSecurityPerimeterConfiguration *networksecurityperimeterconfiguration.NetworkSecurityPerimeterConfigurationClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + PrivateLinkScopes *privatelinkscopes.PrivateLinkScopesClient + Settings *settings.SettingsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + agentVersionsClient, err := agentversions.NewAgentVersionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AgentVersions client: %+v", err) + } + configureFunc(agentVersionsClient.Client) + + extensionsClient, err := extensions.NewExtensionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Extensions client: %+v", err) + } + configureFunc(extensionsClient.Client) + + gatewaysClient, err := gateways.NewGatewaysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Gateways client: %+v", err) + } + configureFunc(gatewaysClient.Client) + + hybridIdentityMetadataClient, err := hybrididentitymetadata.NewHybridIdentityMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building HybridIdentityMetadata client: %+v", err) + } + configureFunc(hybridIdentityMetadataClient.Client) + + licenseProfilesClient, err := licenseprofiles.NewLicenseProfilesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LicenseProfiles client: %+v", err) + } + configureFunc(licenseProfilesClient.Client) + + licensesClient, err := licenses.NewLicensesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Licenses client: %+v", err) + } + configureFunc(licensesClient.Client) + + machineExtensionsClient, err := machineextensions.NewMachineExtensionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MachineExtensions client: %+v", err) + } + configureFunc(machineExtensionsClient.Client) + + machineExtensionsSetupClient, err := machineextensionssetup.NewMachineExtensionsSetupClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MachineExtensionsSetup client: %+v", err) + } + configureFunc(machineExtensionsSetupClient.Client) + + machineExtensionsUpgradeClient, err := machineextensionsupgrade.NewMachineExtensionsUpgradeClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MachineExtensionsUpgrade client: %+v", err) + } + configureFunc(machineExtensionsUpgradeClient.Client) + + machineNetworkProfileClient, err := machinenetworkprofile.NewMachineNetworkProfileClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MachineNetworkProfile client: %+v", err) + } + configureFunc(machineNetworkProfileClient.Client) + + machineRunCommandsClient, err := machineruncommands.NewMachineRunCommandsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MachineRunCommands client: %+v", err) + } + configureFunc(machineRunCommandsClient.Client) + + machinesClient, err := machines.NewMachinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Machines client: %+v", err) + } + configureFunc(machinesClient.Client) + + networkConfigurationsClient, err := networkconfigurations.NewNetworkConfigurationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NetworkConfigurations client: %+v", err) + } + configureFunc(networkConfigurationsClient.Client) + + networkSecurityPerimeterConfigurationClient, err := networksecurityperimeterconfiguration.NewNetworkSecurityPerimeterConfigurationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NetworkSecurityPerimeterConfiguration client: %+v", err) + } + configureFunc(networkSecurityPerimeterConfigurationClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + privateLinkScopesClient, err := privatelinkscopes.NewPrivateLinkScopesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkScopes client: %+v", err) + } + configureFunc(privateLinkScopesClient.Client) + + settingsClient, err := settings.NewSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Settings client: %+v", err) + } + configureFunc(settingsClient.Client) + + return &Client{ + AgentVersions: agentVersionsClient, + Extensions: extensionsClient, + Gateways: gatewaysClient, + HybridIdentityMetadata: hybridIdentityMetadataClient, + LicenseProfiles: licenseProfilesClient, + Licenses: licensesClient, + MachineExtensions: machineExtensionsClient, + MachineExtensionsSetup: machineExtensionsSetupClient, + MachineExtensionsUpgrade: machineExtensionsUpgradeClient, + MachineNetworkProfile: machineNetworkProfileClient, + MachineRunCommands: machineRunCommandsClient, + Machines: machinesClient, + NetworkConfigurations: networkConfigurationsClient, + NetworkSecurityPerimeterConfiguration: networkSecurityPerimeterConfigurationClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + PrivateLinkScopes: privateLinkScopesClient, + Settings: settingsClient, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/README.md b/resource-manager/hybridcompute/2025-01-13/extensions/README.md new file mode 100644 index 00000000000..13c6cec3cf8 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/README.md @@ -0,0 +1,119 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/extensions` Documentation + +The `extensions` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/extensions" +``` + + +### Client Initialization + +```go +client := extensions.NewExtensionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ExtensionsClient.ExtensionMetadataGet` + +```go +ctx := context.TODO() +id := extensions.NewExtensionTypeVersionID("12345678-1234-9876-4563-123456789012", "locationName", "publisherName", "extensionTypeName", "versionName") + +read, err := client.ExtensionMetadataGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExtensionsClient.ExtensionMetadataList` + +```go +ctx := context.TODO() +id := extensions.NewPublisherExtensionTypeID("12345678-1234-9876-4563-123456789012", "locationName", "publisherName", "extensionTypeName") + +read, err := client.ExtensionMetadataList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExtensionsClient.ExtensionMetadataV2Get` + +```go +ctx := context.TODO() +id := extensions.NewVersionID("locationName", "publisherName", "extensionTypeName", "versionName") + +read, err := client.ExtensionMetadataV2Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExtensionsClient.ExtensionMetadataV2List` + +```go +ctx := context.TODO() +id := extensions.NewExtensionTypeID("locationName", "publisherName", "extensionTypeName") + +// alternatively `client.ExtensionMetadataV2List(ctx, id)` can be used to do batched pagination +items, err := client.ExtensionMetadataV2ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ExtensionsClient.ExtensionPublisherList` + +```go +ctx := context.TODO() +id := extensions.NewLocationID("locationName") + +// alternatively `client.ExtensionPublisherList(ctx, id)` can be used to do batched pagination +items, err := client.ExtensionPublisherListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ExtensionsClient.ExtensionTypeList` + +```go +ctx := context.TODO() +id := extensions.NewPublisherID("locationName", "publisherName") + +// alternatively `client.ExtensionTypeList(ctx, id)` can be used to do batched pagination +items, err := client.ExtensionTypeListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/client.go b/resource-manager/hybridcompute/2025-01-13/extensions/client.go new file mode 100644 index 00000000000..682e8266708 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/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.NewClient(sdkApi, "extensions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ExtensionsClient: %+v", err) + } + + return &ExtensionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype.go new file mode 100644 index 00000000000..50a97a2cadc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype.go @@ -0,0 +1,130 @@ +package extensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExtensionTypeId{}) +} + +var _ resourceids.ResourceId = &ExtensionTypeId{} + +// ExtensionTypeId is a struct representing the Resource ID for a Extension Type +type ExtensionTypeId struct { + LocationName string + PublisherName string + ExtensionTypeName string +} + +// NewExtensionTypeID returns a new ExtensionTypeId struct +func NewExtensionTypeID(locationName string, publisherName string, extensionTypeName string) ExtensionTypeId { + return ExtensionTypeId{ + LocationName: locationName, + PublisherName: publisherName, + ExtensionTypeName: extensionTypeName, + } +} + +// ParseExtensionTypeID parses 'input' into a ExtensionTypeId +func ParseExtensionTypeID(input string) (*ExtensionTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExtensionTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExtensionTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExtensionTypeIDInsensitively parses 'input' case-insensitively into a ExtensionTypeId +// note: this method should only be used for API response data and not user input +func ParseExtensionTypeIDInsensitively(input string) (*ExtensionTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExtensionTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExtensionTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExtensionTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.ExtensionTypeName, ok = input.Parsed["extensionTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "extensionTypeName", input) + } + + return nil +} + +// ValidateExtensionTypeID checks that 'input' can be parsed as a Extension Type ID +func ValidateExtensionTypeID(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 := ParseExtensionTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Extension Type ID +func (id ExtensionTypeId) ID() string { + fmtString := "/providers/Microsoft.HybridCompute/locations/%s/publishers/%s/extensionTypes/%s" + return fmt.Sprintf(fmtString, id.LocationName, id.PublisherName, id.ExtensionTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Extension Type ID +func (id ExtensionTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherName"), + resourceids.StaticSegment("staticExtensionTypes", "extensionTypes", "extensionTypes"), + resourceids.UserSpecifiedSegment("extensionTypeName", "extensionTypeName"), + } +} + +// String returns a human-readable description of this Extension Type ID +func (id ExtensionTypeId) String() string { + components := []string{ + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Extension Type Name: %q", id.ExtensionTypeName), + } + return fmt.Sprintf("Extension Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype_test.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype_test.go new file mode 100644 index 00000000000..e23c0e3641e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontype_test.go @@ -0,0 +1,282 @@ +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 = &ExtensionTypeId{} + +func TestNewExtensionTypeID(t *testing.T) { + id := NewExtensionTypeID("locationName", "publisherName", "extensionTypeName") + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.PublisherName != "publisherName" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherName") + } + + if id.ExtensionTypeName != "extensionTypeName" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionTypeName'", id.ExtensionTypeName, "extensionTypeName") + } +} + +func TestFormatExtensionTypeID(t *testing.T) { + actual := NewExtensionTypeID("locationName", "publisherName", "extensionTypeName").ID() + expected := "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExtensionTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Expected: &ExtensionTypeId{ + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionTypeID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + } +} + +func TestParseExtensionTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Expected: &ExtensionTypeId{ + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe", + Expected: &ExtensionTypeId{ + LocationName: "lOcAtIoNnAmE", + PublisherName: "pUbLiShErNaMe", + ExtensionTypeName: "eXtEnSiOnTyPeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionTypeIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + } +} + +func TestSegmentsForExtensionTypeId(t *testing.T) { + segments := ExtensionTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExtensionTypeId 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/hybridcompute/2025-01-13/extensions/id_extensiontypeversion.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion.go new file mode 100644 index 00000000000..760911b3bb9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion.go @@ -0,0 +1,148 @@ +package extensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExtensionTypeVersionId{}) +} + +var _ resourceids.ResourceId = &ExtensionTypeVersionId{} + +// ExtensionTypeVersionId is a struct representing the Resource ID for a Extension Type Version +type ExtensionTypeVersionId struct { + SubscriptionId string + LocationName string + PublisherName string + ExtensionTypeName string + VersionName string +} + +// NewExtensionTypeVersionID returns a new ExtensionTypeVersionId struct +func NewExtensionTypeVersionID(subscriptionId string, locationName string, publisherName string, extensionTypeName string, versionName string) ExtensionTypeVersionId { + return ExtensionTypeVersionId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + PublisherName: publisherName, + ExtensionTypeName: extensionTypeName, + VersionName: versionName, + } +} + +// ParseExtensionTypeVersionID parses 'input' into a ExtensionTypeVersionId +func ParseExtensionTypeVersionID(input string) (*ExtensionTypeVersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExtensionTypeVersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExtensionTypeVersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExtensionTypeVersionIDInsensitively parses 'input' case-insensitively into a ExtensionTypeVersionId +// note: this method should only be used for API response data and not user input +func ParseExtensionTypeVersionIDInsensitively(input string) (*ExtensionTypeVersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExtensionTypeVersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExtensionTypeVersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExtensionTypeVersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.ExtensionTypeName, ok = input.Parsed["extensionTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "extensionTypeName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateExtensionTypeVersionID checks that 'input' can be parsed as a Extension Type Version ID +func ValidateExtensionTypeVersionID(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 := ParseExtensionTypeVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Extension Type Version ID +func (id ExtensionTypeVersionId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.HybridCompute/locations/%s/publishers/%s/extensionTypes/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.PublisherName, id.ExtensionTypeName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Extension Type Version ID +func (id ExtensionTypeVersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherName"), + resourceids.StaticSegment("staticExtensionTypes", "extensionTypes", "extensionTypes"), + resourceids.UserSpecifiedSegment("extensionTypeName", "extensionTypeName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + } +} + +// String returns a human-readable description of this Extension Type Version ID +func (id ExtensionTypeVersionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Extension Type Name: %q", id.ExtensionTypeName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Extension Type Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion_test.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion_test.go new file mode 100644 index 00000000000..d2dd2229093 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_extensiontypeversion_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 = &ExtensionTypeVersionId{} + +func TestNewExtensionTypeVersionID(t *testing.T) { + id := NewExtensionTypeVersionID("12345678-1234-9876-4563-123456789012", "locationName", "publisherName", "extensionTypeName", "versionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.PublisherName != "publisherName" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherName") + } + + if id.ExtensionTypeName != "extensionTypeName" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionTypeName'", id.ExtensionTypeName, "extensionTypeName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } +} + +func TestFormatExtensionTypeVersionID(t *testing.T) { + actual := NewExtensionTypeVersionID("12345678-1234-9876-4563-123456789012", "locationName", "publisherName", "extensionTypeName", "versionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExtensionTypeVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionTypeVersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName", + Expected: &ExtensionTypeVersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionTypeVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestParseExtensionTypeVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionTypeVersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName", + Expected: &ExtensionTypeVersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/vErSiOnS/vErSiOnNaMe", + Expected: &ExtensionTypeVersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + PublisherName: "pUbLiShErNaMe", + ExtensionTypeName: "eXtEnSiOnTyPeNaMe", + VersionName: "vErSiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/vErSiOnS/vErSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionTypeVersionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestSegmentsForExtensionTypeVersionId(t *testing.T) { + segments := ExtensionTypeVersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExtensionTypeVersionId 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/hybridcompute/2025-01-13/extensions/id_location.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_location.go new file mode 100644 index 00000000000..0eb8c45b2a9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_location.go @@ -0,0 +1,112 @@ +package extensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(locationName string) LocationId { + return LocationId{ + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/providers/Microsoft.HybridCompute/locations/%s" + return fmt.Sprintf(fmtString, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_location_test.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_location_test.go new file mode 100644 index 00000000000..e905679af40 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_location_test.go @@ -0,0 +1,192 @@ +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("locationName") + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("locationName").ID() + expected := "/providers/Microsoft.HybridCompute/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Expected: &LocationId{ + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Expected: &LocationId{ + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/hybridcompute/2025-01-13/extensions/id_publisher.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisher.go new file mode 100644 index 00000000000..31f04280748 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisher.go @@ -0,0 +1,121 @@ +package extensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PublisherId{}) +} + +var _ resourceids.ResourceId = &PublisherId{} + +// PublisherId is a struct representing the Resource ID for a Publisher +type PublisherId struct { + LocationName string + PublisherName string +} + +// NewPublisherID returns a new PublisherId struct +func NewPublisherID(locationName string, publisherName string) PublisherId { + return PublisherId{ + LocationName: locationName, + 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", 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 := "/providers/Microsoft.HybridCompute/locations/%s/publishers/%s" + return fmt.Sprintf(fmtString, id.LocationName, 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("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherName"), + } +} + +// String returns a human-readable description of this Publisher ID +func (id PublisherId) String() string { + components := []string{ + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + } + return fmt.Sprintf("Publisher (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_publisher_test.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisher_test.go new file mode 100644 index 00000000000..38e2dc462d3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisher_test.go @@ -0,0 +1,237 @@ +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 = &PublisherId{} + +func TestNewPublisherID(t *testing.T) { + id := NewPublisherID("locationName", "publisherName") + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.PublisherName != "publisherName" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherName") + } +} + +func TestFormatPublisherID(t *testing.T) { + actual := NewPublisherID("locationName", "publisherName").ID() + expected := "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName" + 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: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Expected: &PublisherId{ + LocationName: "locationName", + PublisherName: "publisherName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + 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: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Expected: &PublisherId{ + LocationName: "locationName", + PublisherName: "publisherName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe", + Expected: &PublisherId{ + LocationName: "lOcAtIoNnAmE", + PublisherName: "pUbLiShErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + 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/hybridcompute/2025-01-13/extensions/id_publisherextensiontype.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype.go new file mode 100644 index 00000000000..97a0470a9ae --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype.go @@ -0,0 +1,139 @@ +package extensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PublisherExtensionTypeId{}) +} + +var _ resourceids.ResourceId = &PublisherExtensionTypeId{} + +// PublisherExtensionTypeId is a struct representing the Resource ID for a Publisher Extension Type +type PublisherExtensionTypeId struct { + SubscriptionId string + LocationName string + PublisherName string + ExtensionTypeName string +} + +// NewPublisherExtensionTypeID returns a new PublisherExtensionTypeId struct +func NewPublisherExtensionTypeID(subscriptionId string, locationName string, publisherName string, extensionTypeName string) PublisherExtensionTypeId { + return PublisherExtensionTypeId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + PublisherName: publisherName, + ExtensionTypeName: extensionTypeName, + } +} + +// ParsePublisherExtensionTypeID parses 'input' into a PublisherExtensionTypeId +func ParsePublisherExtensionTypeID(input string) (*PublisherExtensionTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&PublisherExtensionTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PublisherExtensionTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePublisherExtensionTypeIDInsensitively parses 'input' case-insensitively into a PublisherExtensionTypeId +// note: this method should only be used for API response data and not user input +func ParsePublisherExtensionTypeIDInsensitively(input string) (*PublisherExtensionTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&PublisherExtensionTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PublisherExtensionTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PublisherExtensionTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.ExtensionTypeName, ok = input.Parsed["extensionTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "extensionTypeName", input) + } + + return nil +} + +// ValidatePublisherExtensionTypeID checks that 'input' can be parsed as a Publisher Extension Type ID +func ValidatePublisherExtensionTypeID(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 := ParsePublisherExtensionTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Publisher Extension Type ID +func (id PublisherExtensionTypeId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.HybridCompute/locations/%s/publishers/%s/extensionTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.PublisherName, id.ExtensionTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Publisher Extension Type ID +func (id PublisherExtensionTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherName"), + resourceids.StaticSegment("staticExtensionTypes", "extensionTypes", "extensionTypes"), + resourceids.UserSpecifiedSegment("extensionTypeName", "extensionTypeName"), + } +} + +// String returns a human-readable description of this Publisher Extension Type ID +func (id PublisherExtensionTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Extension Type Name: %q", id.ExtensionTypeName), + } + return fmt.Sprintf("Publisher Extension Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype_test.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype_test.go new file mode 100644 index 00000000000..5e63f542111 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_publisherextensiontype_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 = &PublisherExtensionTypeId{} + +func TestNewPublisherExtensionTypeID(t *testing.T) { + id := NewPublisherExtensionTypeID("12345678-1234-9876-4563-123456789012", "locationName", "publisherName", "extensionTypeName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.PublisherName != "publisherName" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherName") + } + + if id.ExtensionTypeName != "extensionTypeName" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionTypeName'", id.ExtensionTypeName, "extensionTypeName") + } +} + +func TestFormatPublisherExtensionTypeID(t *testing.T) { + actual := NewPublisherExtensionTypeID("12345678-1234-9876-4563-123456789012", "locationName", "publisherName", "extensionTypeName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePublisherExtensionTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PublisherExtensionTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Expected: &PublisherExtensionTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePublisherExtensionTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + } +} + +func TestParsePublisherExtensionTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PublisherExtensionTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Expected: &PublisherExtensionTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe", + Expected: &PublisherExtensionTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + PublisherName: "pUbLiShErNaMe", + ExtensionTypeName: "eXtEnSiOnTyPeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePublisherExtensionTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + } +} + +func TestSegmentsForPublisherExtensionTypeId(t *testing.T) { + segments := PublisherExtensionTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PublisherExtensionTypeId 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/hybridcompute/2025-01-13/extensions/id_version.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_version.go new file mode 100644 index 00000000000..517bd1ed89f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_version.go @@ -0,0 +1,139 @@ +package extensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VersionId{}) +} + +var _ resourceids.ResourceId = &VersionId{} + +// VersionId is a struct representing the Resource ID for a Version +type VersionId struct { + LocationName string + PublisherName string + ExtensionTypeName string + VersionName string +} + +// NewVersionID returns a new VersionId struct +func NewVersionID(locationName string, publisherName string, extensionTypeName string, versionName string) VersionId { + return VersionId{ + LocationName: locationName, + PublisherName: publisherName, + ExtensionTypeName: extensionTypeName, + VersionName: versionName, + } +} + +// ParseVersionID parses 'input' into a VersionId +func ParseVersionID(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVersionIDInsensitively parses 'input' case-insensitively into a VersionId +// note: this method should only be used for API response data and not user input +func ParseVersionIDInsensitively(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.PublisherName, ok = input.Parsed["publisherName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "publisherName", input) + } + + if id.ExtensionTypeName, ok = input.Parsed["extensionTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "extensionTypeName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateVersionID checks that 'input' can be parsed as a Version ID +func ValidateVersionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Version ID +func (id VersionId) ID() string { + fmtString := "/providers/Microsoft.HybridCompute/locations/%s/publishers/%s/extensionTypes/%s/versions/%s" + return fmt.Sprintf(fmtString, id.LocationName, id.PublisherName, id.ExtensionTypeName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Version ID +func (id VersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticPublishers", "publishers", "publishers"), + resourceids.UserSpecifiedSegment("publisherName", "publisherName"), + resourceids.StaticSegment("staticExtensionTypes", "extensionTypes", "extensionTypes"), + resourceids.UserSpecifiedSegment("extensionTypeName", "extensionTypeName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + } +} + +// String returns a human-readable description of this Version ID +func (id VersionId) String() string { + components := []string{ + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Publisher Name: %q", id.PublisherName), + fmt.Sprintf("Extension Type Name: %q", id.ExtensionTypeName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/id_version_test.go b/resource-manager/hybridcompute/2025-01-13/extensions/id_version_test.go new file mode 100644 index 00000000000..021ebe6d368 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/id_version_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 = &VersionId{} + +func TestNewVersionID(t *testing.T) { + id := NewVersionID("locationName", "publisherName", "extensionTypeName", "versionName") + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.PublisherName != "publisherName" { + t.Fatalf("Expected %q but got %q for Segment 'PublisherName'", id.PublisherName, "publisherName") + } + + if id.ExtensionTypeName != "extensionTypeName" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionTypeName'", id.ExtensionTypeName, "extensionTypeName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("locationName", "publisherName", "extensionTypeName", "versionName").ID() + expected := "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName", + Expected: &VersionId{ + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestParseVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName", + Expected: &VersionId{ + LocationName: "locationName", + PublisherName: "publisherName", + ExtensionTypeName: "extensionTypeName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.HybridCompute/locations/locationName/publishers/publisherName/extensionTypes/extensionTypeName/versions/versionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/vErSiOnS/vErSiOnNaMe", + Expected: &VersionId{ + LocationName: "lOcAtIoNnAmE", + PublisherName: "pUbLiShErNaMe", + ExtensionTypeName: "eXtEnSiOnTyPeNaMe", + VersionName: "vErSiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pUbLiShErS/pUbLiShErNaMe/eXtEnSiOnTyPeS/eXtEnSiOnTyPeNaMe/vErSiOnS/vErSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PublisherName != v.Expected.PublisherName { + t.Fatalf("Expected %q but got %q for PublisherName", v.Expected.PublisherName, actual.PublisherName) + } + + if actual.ExtensionTypeName != v.Expected.ExtensionTypeName { + t.Fatalf("Expected %q but got %q for ExtensionTypeName", v.Expected.ExtensionTypeName, actual.ExtensionTypeName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestSegmentsForVersionId(t *testing.T) { + segments := VersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VersionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadataget.go b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadataget.go new file mode 100644 index 00000000000..37761c8d4d0 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadataget.go @@ -0,0 +1,53 @@ +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 ExtensionMetadataGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtensionValue +} + +// ExtensionMetadataGet ... +func (c ExtensionsClient) ExtensionMetadataGet(ctx context.Context, id ExtensionTypeVersionId) (result ExtensionMetadataGetOperationResponse, 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 ExtensionValue + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatalist.go b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatalist.go new file mode 100644 index 00000000000..5b8b570b900 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatalist.go @@ -0,0 +1,54 @@ +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 ExtensionMetadataListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtensionValueListResult +} + +// ExtensionMetadataList ... +func (c ExtensionsClient) ExtensionMetadataList(ctx context.Context, id PublisherExtensionTypeId) (result ExtensionMetadataListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ExtensionValueListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2get.go b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2get.go new file mode 100644 index 00000000000..d27311ff408 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2get.go @@ -0,0 +1,53 @@ +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 ExtensionMetadataV2GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtensionValueV2 +} + +// ExtensionMetadataV2Get ... +func (c ExtensionsClient) ExtensionMetadataV2Get(ctx context.Context, id VersionId) (result ExtensionMetadataV2GetOperationResponse, 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 ExtensionValueV2 + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2list.go b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2list.go new file mode 100644 index 00000000000..652f75409f5 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionmetadatav2list.go @@ -0,0 +1,105 @@ +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 ExtensionMetadataV2ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtensionValueV2 +} + +type ExtensionMetadataV2ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtensionValueV2 +} + +type ExtensionMetadataV2ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ExtensionMetadataV2ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ExtensionMetadataV2List ... +func (c ExtensionsClient) ExtensionMetadataV2List(ctx context.Context, id ExtensionTypeId) (result ExtensionMetadataV2ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ExtensionMetadataV2ListCustomPager{}, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ExtensionValueV2 `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExtensionMetadataV2ListComplete retrieves all the results into a single object +func (c ExtensionsClient) ExtensionMetadataV2ListComplete(ctx context.Context, id ExtensionTypeId) (ExtensionMetadataV2ListCompleteResult, error) { + return c.ExtensionMetadataV2ListCompleteMatchingPredicate(ctx, id, ExtensionValueV2OperationPredicate{}) +} + +// ExtensionMetadataV2ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ExtensionsClient) ExtensionMetadataV2ListCompleteMatchingPredicate(ctx context.Context, id ExtensionTypeId, predicate ExtensionValueV2OperationPredicate) (result ExtensionMetadataV2ListCompleteResult, err error) { + items := make([]ExtensionValueV2, 0) + + resp, err := c.ExtensionMetadataV2List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExtensionMetadataV2ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionpublisherlist.go b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionpublisherlist.go new file mode 100644 index 00000000000..b51713b8d5c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensionpublisherlist.go @@ -0,0 +1,105 @@ +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 ExtensionPublisherListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtensionPublisher +} + +type ExtensionPublisherListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtensionPublisher +} + +type ExtensionPublisherListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ExtensionPublisherListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ExtensionPublisherList ... +func (c ExtensionsClient) ExtensionPublisherList(ctx context.Context, id LocationId) (result ExtensionPublisherListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ExtensionPublisherListCustomPager{}, + 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 *[]ExtensionPublisher `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExtensionPublisherListComplete retrieves all the results into a single object +func (c ExtensionsClient) ExtensionPublisherListComplete(ctx context.Context, id LocationId) (ExtensionPublisherListCompleteResult, error) { + return c.ExtensionPublisherListCompleteMatchingPredicate(ctx, id, ExtensionPublisherOperationPredicate{}) +} + +// ExtensionPublisherListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ExtensionsClient) ExtensionPublisherListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate ExtensionPublisherOperationPredicate) (result ExtensionPublisherListCompleteResult, err error) { + items := make([]ExtensionPublisher, 0) + + resp, err := c.ExtensionPublisherList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExtensionPublisherListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/method_extensiontypelist.go b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensiontypelist.go new file mode 100644 index 00000000000..d68032bd46f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/method_extensiontypelist.go @@ -0,0 +1,105 @@ +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 ExtensionTypeListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtensionType +} + +type ExtensionTypeListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtensionType +} + +type ExtensionTypeListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ExtensionTypeListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ExtensionTypeList ... +func (c ExtensionsClient) ExtensionTypeList(ctx context.Context, id PublisherId) (result ExtensionTypeListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ExtensionTypeListCustomPager{}, + Path: fmt.Sprintf("%s/extensionTypes", 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 *[]ExtensionType `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExtensionTypeListComplete retrieves all the results into a single object +func (c ExtensionsClient) ExtensionTypeListComplete(ctx context.Context, id PublisherId) (ExtensionTypeListCompleteResult, error) { + return c.ExtensionTypeListCompleteMatchingPredicate(ctx, id, ExtensionTypeOperationPredicate{}) +} + +// ExtensionTypeListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ExtensionsClient) ExtensionTypeListCompleteMatchingPredicate(ctx context.Context, id PublisherId, predicate ExtensionTypeOperationPredicate) (result ExtensionTypeListCompleteResult, err error) { + items := make([]ExtensionType, 0) + + resp, err := c.ExtensionTypeList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExtensionTypeListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionpublisher.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionpublisher.go new file mode 100644 index 00000000000..9eee9213e3d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionpublisher.go @@ -0,0 +1,9 @@ +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 ExtensionPublisher struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensiontype.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensiontype.go new file mode 100644 index 00000000000..581a18ef9fd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensiontype.go @@ -0,0 +1,9 @@ +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 ExtensionType struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalue.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalue.go new file mode 100644 index 00000000000..6dd976ec34c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalue.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 ExtensionValue struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtensionValueProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluelistresult.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluelistresult.go new file mode 100644 index 00000000000..06a10203391 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluelistresult.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 ExtensionValueListResult struct { + Value *[]ExtensionValue `json:"value,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalueproperties.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalueproperties.go new file mode 100644 index 00000000000..8b1eac1d9c6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvalueproperties.go @@ -0,0 +1,10 @@ +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 ExtensionValueProperties struct { + ExtensionType *string `json:"extensionType,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2.go new file mode 100644 index 00000000000..fba9e8ea186 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2.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 ExtensionValueV2 struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtensionValueV2Properties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2properties.go b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2properties.go new file mode 100644 index 00000000000..a5e0e7ce48a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/model_extensionvaluev2properties.go @@ -0,0 +1,14 @@ +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 ExtensionValueV2Properties struct { + Architecture *[]string `json:"architecture,omitempty"` + ExtensionSignatureUri *string `json:"extensionSignatureUri,omitempty"` + ExtensionType *string `json:"extensionType,omitempty"` + ExtensionUris *[]string `json:"extensionUris,omitempty"` + OperatingSystem *string `json:"operatingSystem,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/extensions/predicates.go b/resource-manager/hybridcompute/2025-01-13/extensions/predicates.go new file mode 100644 index 00000000000..ae7fa658731 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/predicates.go @@ -0,0 +1,63 @@ +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 ExtensionPublisherOperationPredicate struct { + Id *string + Name *string +} + +func (p ExtensionPublisherOperationPredicate) Matches(input ExtensionPublisher) 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 + } + + return true +} + +type ExtensionTypeOperationPredicate struct { + Id *string + Name *string +} + +func (p ExtensionTypeOperationPredicate) Matches(input ExtensionType) 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 + } + + return true +} + +type ExtensionValueV2OperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExtensionValueV2OperationPredicate) Matches(input ExtensionValueV2) 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/hybridcompute/2025-01-13/extensions/version.go b/resource-manager/hybridcompute/2025-01-13/extensions/version.go new file mode 100644 index 00000000000..0c308ac1ce6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/extensions/version.go @@ -0,0 +1,10 @@ +package extensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/extensions/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/README.md b/resource-manager/hybridcompute/2025-01-13/gateways/README.md new file mode 100644 index 00000000000..5d8f0fe4968 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/README.md @@ -0,0 +1,121 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/gateways` Documentation + +The `gateways` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/gateways" +``` + + +### Client Initialization + +```go +client := gateways.NewGatewaysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GatewaysClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := gateways.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName") + +payload := gateways.Gateway{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `GatewaysClient.Delete` + +```go +ctx := context.TODO() +id := gateways.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GatewaysClient.Get` + +```go +ctx := context.TODO() +id := gateways.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName") + +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: `GatewaysClient.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: `GatewaysClient.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: `GatewaysClient.Update` + +```go +ctx := context.TODO() +id := gateways.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName") + +payload := gateways.GatewayUpdate{ + // ... +} + + +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/hybridcompute/2025-01-13/gateways/client.go b/resource-manager/hybridcompute/2025-01-13/gateways/client.go new file mode 100644 index 00000000000..619859eca8a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/client.go @@ -0,0 +1,26 @@ +package gateways + +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 GatewaysClient struct { + Client *resourcemanager.Client +} + +func NewGatewaysClientWithBaseURI(sdkApi sdkEnv.Api) (*GatewaysClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "gateways", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GatewaysClient: %+v", err) + } + + return &GatewaysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/constants.go b/resource-manager/hybridcompute/2025-01-13/gateways/constants.go new file mode 100644 index 00000000000..e4a0c9ca443 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/constants.go @@ -0,0 +1,107 @@ +package gateways + +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 GatewayType string + +const ( + GatewayTypePublic GatewayType = "Public" +) + +func PossibleValuesForGatewayType() []string { + return []string{ + string(GatewayTypePublic), + } +} + +func (s *GatewayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGatewayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGatewayType(input string) (*GatewayType, error) { + vals := map[string]GatewayType{ + "public": GatewayTypePublic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GatewayType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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/hybridcompute/2025-01-13/gateways/id_gateway.go b/resource-manager/hybridcompute/2025-01-13/gateways/id_gateway.go new file mode 100644 index 00000000000..06d488e55df --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/id_gateway.go @@ -0,0 +1,130 @@ +package gateways + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GatewayId{}) +} + +var _ resourceids.ResourceId = &GatewayId{} + +// GatewayId is a struct representing the Resource ID for a Gateway +type GatewayId struct { + SubscriptionId string + ResourceGroupName string + GatewayName string +} + +// NewGatewayID returns a new GatewayId struct +func NewGatewayID(subscriptionId string, resourceGroupName string, gatewayName string) GatewayId { + return GatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + GatewayName: gatewayName, + } +} + +// ParseGatewayID parses 'input' into a GatewayId +func ParseGatewayID(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGatewayIDInsensitively parses 'input' case-insensitively into a GatewayId +// note: this method should only be used for API response data and not user input +func ParseGatewayIDInsensitively(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GatewayId) 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.GatewayName, ok = input.Parsed["gatewayName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayName", input) + } + + return nil +} + +// ValidateGatewayID checks that 'input' can be parsed as a Gateway ID +func ValidateGatewayID(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 := ParseGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gateway ID +func (id GatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.GatewayName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gateway ID +func (id GatewayId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayName", "gatewayName"), + } +} + +// String returns a human-readable description of this Gateway ID +func (id GatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Gateway Name: %q", id.GatewayName), + } + return fmt.Sprintf("Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/id_gateway_test.go b/resource-manager/hybridcompute/2025-01-13/gateways/id_gateway_test.go new file mode 100644 index 00000000000..c3f7a3b0229 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/id_gateway_test.go @@ -0,0 +1,282 @@ +package gateways + +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 = &GatewayId{} + +func TestNewGatewayID(t *testing.T) { + id := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName") + + 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.GatewayName != "gatewayName" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayName'", id.GatewayName, "gatewayName") + } +} + +func TestFormatGatewayID(t *testing.T) { + actual := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "gatewayName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways/gatewayName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways/gatewayName", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways/gatewayName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayID(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.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestParseGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways/gatewayName", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + GatewayName: "gatewayName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/gateways/gatewayName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/gAtEwAyS/gAtEwAyNaMe", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + GatewayName: "gAtEwAyNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/gAtEwAyS/gAtEwAyNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayIDInsensitively(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.GatewayName != v.Expected.GatewayName { + t.Fatalf("Expected %q but got %q for GatewayName", v.Expected.GatewayName, actual.GatewayName) + } + + } +} + +func TestSegmentsForGatewayId(t *testing.T) { + segments := GatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GatewayId 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/hybridcompute/2025-01-13/gateways/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/gateways/method_createorupdate.go new file mode 100644 index 00000000000..5c2a73c25dd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/method_createorupdate.go @@ -0,0 +1,75 @@ +package gateways + +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 *Gateway +} + +// CreateOrUpdate ... +func (c GatewaysClient) CreateOrUpdate(ctx context.Context, id GatewayId, input Gateway) (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 GatewaysClient) CreateOrUpdateThenPoll(ctx context.Context, id GatewayId, input Gateway) 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/hybridcompute/2025-01-13/gateways/method_delete.go b/resource-manager/hybridcompute/2025-01-13/gateways/method_delete.go new file mode 100644 index 00000000000..23a7f2823ca --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/method_delete.go @@ -0,0 +1,70 @@ +package gateways + +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 GatewaysClient) Delete(ctx context.Context, id GatewayId) (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 GatewaysClient) DeleteThenPoll(ctx context.Context, id GatewayId) 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/hybridcompute/2025-01-13/gateways/method_get.go b/resource-manager/hybridcompute/2025-01-13/gateways/method_get.go new file mode 100644 index 00000000000..b91c910e9eb --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/method_get.go @@ -0,0 +1,53 @@ +package gateways + +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 *Gateway +} + +// Get ... +func (c GatewaysClient) Get(ctx context.Context, id GatewayId) (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 Gateway + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/method_listbyresourcegroup.go b/resource-manager/hybridcompute/2025-01-13/gateways/method_listbyresourcegroup.go new file mode 100644 index 00000000000..0066264b985 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package gateways + +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 *[]Gateway +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Gateway +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c GatewaysClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/gateways", 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 *[]Gateway `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 GatewaysClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, GatewayOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GatewaysClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate GatewayOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Gateway, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/method_listbysubscription.go b/resource-manager/hybridcompute/2025-01-13/gateways/method_listbysubscription.go new file mode 100644 index 00000000000..de43592e7e3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/method_listbysubscription.go @@ -0,0 +1,106 @@ +package gateways + +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 *[]Gateway +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Gateway +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c GatewaysClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/gateways", 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 *[]Gateway `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 GatewaysClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, GatewayOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GatewaysClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate GatewayOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Gateway, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/method_update.go b/resource-manager/hybridcompute/2025-01-13/gateways/method_update.go new file mode 100644 index 00000000000..2311bdbf3a2 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/method_update.go @@ -0,0 +1,57 @@ +package gateways + +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 *Gateway +} + +// Update ... +func (c GatewaysClient) Update(ctx context.Context, id GatewayId, input GatewayUpdate) (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 Gateway + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/model_gateway.go b/resource-manager/hybridcompute/2025-01-13/gateways/model_gateway.go new file mode 100644 index 00000000000..7a0f1f3b8d9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/model_gateway.go @@ -0,0 +1,18 @@ +package gateways + +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 Gateway struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *GatewayProperties `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/hybridcompute/2025-01-13/gateways/model_gatewayproperties.go b/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayproperties.go new file mode 100644 index 00000000000..27a7e2d9e3e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayproperties.go @@ -0,0 +1,12 @@ +package gateways + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayProperties struct { + AllowedFeatures *[]string `json:"allowedFeatures,omitempty"` + GatewayEndpoint *string `json:"gatewayEndpoint,omitempty"` + GatewayId *string `json:"gatewayId,omitempty"` + GatewayType *GatewayType `json:"gatewayType,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdate.go b/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdate.go new file mode 100644 index 00000000000..03476753214 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdate.go @@ -0,0 +1,9 @@ +package gateways + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayUpdate struct { + Properties *GatewayUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdateproperties.go new file mode 100644 index 00000000000..5dff0db897f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/model_gatewayupdateproperties.go @@ -0,0 +1,8 @@ +package gateways + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayUpdateProperties struct { + AllowedFeatures *[]string `json:"allowedFeatures,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/gateways/predicates.go b/resource-manager/hybridcompute/2025-01-13/gateways/predicates.go new file mode 100644 index 00000000000..63a395f8d5b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/predicates.go @@ -0,0 +1,32 @@ +package gateways + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GatewayOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p GatewayOperationPredicate) Matches(input Gateway) 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/hybridcompute/2025-01-13/gateways/version.go b/resource-manager/hybridcompute/2025-01-13/gateways/version.go new file mode 100644 index 00000000000..43dea4f50fd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/gateways/version.go @@ -0,0 +1,10 @@ +package gateways + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/gateways/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/README.md b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/README.md new file mode 100644 index 00000000000..394f27ae60e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata` Documentation + +The `hybrididentitymetadata` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/hybrididentitymetadata" +``` + + +### Client Initialization + +```go +client := hybrididentitymetadata.NewHybridIdentityMetadataClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `HybridIdentityMetadataClient.Get` + +```go +ctx := context.TODO() +id := hybrididentitymetadata.NewHybridIdentityMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "hybridIdentityMetadataName") + +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: `HybridIdentityMetadataClient.ListByMachines` + +```go +ctx := context.TODO() +id := hybrididentitymetadata.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +// alternatively `client.ListByMachines(ctx, id)` can be used to do batched pagination +items, err := client.ListByMachinesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/client.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/client.go new file mode 100644 index 00000000000..94125d9df11 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/client.go @@ -0,0 +1,26 @@ +package hybrididentitymetadata + +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 HybridIdentityMetadataClient struct { + Client *resourcemanager.Client +} + +func NewHybridIdentityMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*HybridIdentityMetadataClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "hybrididentitymetadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating HybridIdentityMetadataClient: %+v", err) + } + + return &HybridIdentityMetadataClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata.go new file mode 100644 index 00000000000..4738685f063 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata.go @@ -0,0 +1,139 @@ +package hybrididentitymetadata + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&HybridIdentityMetadataId{}) +} + +var _ resourceids.ResourceId = &HybridIdentityMetadataId{} + +// HybridIdentityMetadataId is a struct representing the Resource ID for a Hybrid Identity Metadata +type HybridIdentityMetadataId struct { + SubscriptionId string + ResourceGroupName string + MachineName string + HybridIdentityMetadataName string +} + +// NewHybridIdentityMetadataID returns a new HybridIdentityMetadataId struct +func NewHybridIdentityMetadataID(subscriptionId string, resourceGroupName string, machineName string, hybridIdentityMetadataName string) HybridIdentityMetadataId { + return HybridIdentityMetadataId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + HybridIdentityMetadataName: hybridIdentityMetadataName, + } +} + +// ParseHybridIdentityMetadataID parses 'input' into a HybridIdentityMetadataId +func ParseHybridIdentityMetadataID(input string) (*HybridIdentityMetadataId, error) { + parser := resourceids.NewParserFromResourceIdType(&HybridIdentityMetadataId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := HybridIdentityMetadataId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseHybridIdentityMetadataIDInsensitively parses 'input' case-insensitively into a HybridIdentityMetadataId +// note: this method should only be used for API response data and not user input +func ParseHybridIdentityMetadataIDInsensitively(input string) (*HybridIdentityMetadataId, error) { + parser := resourceids.NewParserFromResourceIdType(&HybridIdentityMetadataId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := HybridIdentityMetadataId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *HybridIdentityMetadataId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + if id.HybridIdentityMetadataName, ok = input.Parsed["hybridIdentityMetadataName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "hybridIdentityMetadataName", input) + } + + return nil +} + +// ValidateHybridIdentityMetadataID checks that 'input' can be parsed as a Hybrid Identity Metadata ID +func ValidateHybridIdentityMetadataID(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 := ParseHybridIdentityMetadataID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Hybrid Identity Metadata ID +func (id HybridIdentityMetadataId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s/hybridIdentityMetadata/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName, id.HybridIdentityMetadataName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Hybrid Identity Metadata ID +func (id HybridIdentityMetadataId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + resourceids.StaticSegment("staticHybridIdentityMetadata", "hybridIdentityMetadata", "hybridIdentityMetadata"), + resourceids.UserSpecifiedSegment("hybridIdentityMetadataName", "hybridIdentityMetadataName"), + } +} + +// String returns a human-readable description of this Hybrid Identity Metadata ID +func (id HybridIdentityMetadataId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + fmt.Sprintf("Hybrid Identity Metadata Name: %q", id.HybridIdentityMetadataName), + } + return fmt.Sprintf("Hybrid Identity Metadata (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata_test.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata_test.go new file mode 100644 index 00000000000..302dc29e61d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_hybrididentitymetadata_test.go @@ -0,0 +1,327 @@ +package hybrididentitymetadata + +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 = &HybridIdentityMetadataId{} + +func TestNewHybridIdentityMetadataID(t *testing.T) { + id := NewHybridIdentityMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "hybridIdentityMetadataName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } + + if id.HybridIdentityMetadataName != "hybridIdentityMetadataName" { + t.Fatalf("Expected %q but got %q for Segment 'HybridIdentityMetadataName'", id.HybridIdentityMetadataName, "hybridIdentityMetadataName") + } +} + +func TestFormatHybridIdentityMetadataID(t *testing.T) { + actual := NewHybridIdentityMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "hybridIdentityMetadataName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata/hybridIdentityMetadataName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseHybridIdentityMetadataID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HybridIdentityMetadataId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata/hybridIdentityMetadataName", + Expected: &HybridIdentityMetadataId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + HybridIdentityMetadataName: "hybridIdentityMetadataName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata/hybridIdentityMetadataName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHybridIdentityMetadataID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + if actual.HybridIdentityMetadataName != v.Expected.HybridIdentityMetadataName { + t.Fatalf("Expected %q but got %q for HybridIdentityMetadataName", v.Expected.HybridIdentityMetadataName, actual.HybridIdentityMetadataName) + } + + } +} + +func TestParseHybridIdentityMetadataIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *HybridIdentityMetadataId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/hYbRiDiDeNtItYmEtAdAtA", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata/hybridIdentityMetadataName", + Expected: &HybridIdentityMetadataId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + HybridIdentityMetadataName: "hybridIdentityMetadataName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/hybridIdentityMetadata/hybridIdentityMetadataName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/hYbRiDiDeNtItYmEtAdAtA/hYbRiDiDeNtItYmEtAdAtAnAmE", + Expected: &HybridIdentityMetadataId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + HybridIdentityMetadataName: "hYbRiDiDeNtItYmEtAdAtAnAmE", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/hYbRiDiDeNtItYmEtAdAtA/hYbRiDiDeNtItYmEtAdAtAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseHybridIdentityMetadataIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + if actual.HybridIdentityMetadataName != v.Expected.HybridIdentityMetadataName { + t.Fatalf("Expected %q but got %q for HybridIdentityMetadataName", v.Expected.HybridIdentityMetadataName, actual.HybridIdentityMetadataName) + } + + } +} + +func TestSegmentsForHybridIdentityMetadataId(t *testing.T) { + segments := HybridIdentityMetadataId{}.Segments() + if len(segments) == 0 { + t.Fatalf("HybridIdentityMetadataId 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/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine.go new file mode 100644 index 00000000000..83755805139 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine.go @@ -0,0 +1,130 @@ +package hybrididentitymetadata + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine_test.go new file mode 100644 index 00000000000..d555e9d5180 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/id_machine_test.go @@ -0,0 +1,282 @@ +package hybrididentitymetadata + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/hybrididentitymetadata/method_get.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_get.go new file mode 100644 index 00000000000..6ed3a97b3ef --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_get.go @@ -0,0 +1,53 @@ +package hybrididentitymetadata + +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 *HybridIdentityMetadata +} + +// Get ... +func (c HybridIdentityMetadataClient) Get(ctx context.Context, id HybridIdentityMetadataId) (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 HybridIdentityMetadata + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_listbymachines.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_listbymachines.go new file mode 100644 index 00000000000..31acb60ec54 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/method_listbymachines.go @@ -0,0 +1,105 @@ +package hybrididentitymetadata + +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 ListByMachinesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]HybridIdentityMetadata +} + +type ListByMachinesCompleteResult struct { + LatestHttpResponse *http.Response + Items []HybridIdentityMetadata +} + +type ListByMachinesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByMachinesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByMachines ... +func (c HybridIdentityMetadataClient) ListByMachines(ctx context.Context, id MachineId) (result ListByMachinesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByMachinesCustomPager{}, + Path: fmt.Sprintf("%s/hybridIdentityMetadata", 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 *[]HybridIdentityMetadata `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByMachinesComplete retrieves all the results into a single object +func (c HybridIdentityMetadataClient) ListByMachinesComplete(ctx context.Context, id MachineId) (ListByMachinesCompleteResult, error) { + return c.ListByMachinesCompleteMatchingPredicate(ctx, id, HybridIdentityMetadataOperationPredicate{}) +} + +// ListByMachinesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c HybridIdentityMetadataClient) ListByMachinesCompleteMatchingPredicate(ctx context.Context, id MachineId, predicate HybridIdentityMetadataOperationPredicate) (result ListByMachinesCompleteResult, err error) { + items := make([]HybridIdentityMetadata, 0) + + resp, err := c.ListByMachines(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByMachinesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadata.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadata.go new file mode 100644 index 00000000000..301219b821b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadata.go @@ -0,0 +1,16 @@ +package hybrididentitymetadata + +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 HybridIdentityMetadata struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties HybridIdentityMetadataProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadataproperties.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadataproperties.go new file mode 100644 index 00000000000..29d73ca4c9a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/model_hybrididentitymetadataproperties.go @@ -0,0 +1,14 @@ +package hybrididentitymetadata + +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 HybridIdentityMetadataProperties struct { + Identity *identity.SystemAssigned `json:"identity,omitempty"` + PublicKey *string `json:"publicKey,omitempty"` + VMId *string `json:"vmId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/predicates.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/predicates.go new file mode 100644 index 00000000000..5e9f9c439d5 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/predicates.go @@ -0,0 +1,27 @@ +package hybrididentitymetadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridIdentityMetadataOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p HybridIdentityMetadataOperationPredicate) Matches(input HybridIdentityMetadata) 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/hybridcompute/2025-01-13/hybrididentitymetadata/version.go b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/version.go new file mode 100644 index 00000000000..535f911b240 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/hybrididentitymetadata/version.go @@ -0,0 +1,10 @@ +package hybrididentitymetadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/hybrididentitymetadata/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/README.md b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/README.md new file mode 100644 index 00000000000..29509259330 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/licenseprofiles` Documentation + +The `licenseprofiles` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/licenseprofiles" +``` + + +### Client Initialization + +```go +client := licenseprofiles.NewLicenseProfilesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LicenseProfilesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := licenseprofiles.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := licenseprofiles.LicenseProfile{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LicenseProfilesClient.Delete` + +```go +ctx := context.TODO() +id := licenseprofiles.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LicenseProfilesClient.Get` + +```go +ctx := context.TODO() +id := licenseprofiles.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +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: `LicenseProfilesClient.List` + +```go +ctx := context.TODO() +id := licenseprofiles.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +// 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: `LicenseProfilesClient.Update` + +```go +ctx := context.TODO() +id := licenseprofiles.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := licenseprofiles.LicenseProfileUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/client.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/client.go new file mode 100644 index 00000000000..587d7982b51 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/client.go @@ -0,0 +1,26 @@ +package licenseprofiles + +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 LicenseProfilesClient struct { + Client *resourcemanager.Client +} + +func NewLicenseProfilesClientWithBaseURI(sdkApi sdkEnv.Api) (*LicenseProfilesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "licenseprofiles", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LicenseProfilesClient: %+v", err) + } + + return &LicenseProfilesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/constants.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/constants.go new file mode 100644 index 00000000000..2c4d8a89037 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/constants.go @@ -0,0 +1,330 @@ +package licenseprofiles + +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 EsuEligibility string + +const ( + EsuEligibilityEligible EsuEligibility = "Eligible" + EsuEligibilityIneligible EsuEligibility = "Ineligible" + EsuEligibilityUnknown EsuEligibility = "Unknown" +) + +func PossibleValuesForEsuEligibility() []string { + return []string{ + string(EsuEligibilityEligible), + string(EsuEligibilityIneligible), + string(EsuEligibilityUnknown), + } +} + +func (s *EsuEligibility) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEsuEligibility(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEsuEligibility(input string) (*EsuEligibility, error) { + vals := map[string]EsuEligibility{ + "eligible": EsuEligibilityEligible, + "ineligible": EsuEligibilityIneligible, + "unknown": EsuEligibilityUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EsuEligibility(input) + return &out, nil +} + +type EsuKeyState string + +const ( + EsuKeyStateActive EsuKeyState = "Active" + EsuKeyStateInactive EsuKeyState = "Inactive" +) + +func PossibleValuesForEsuKeyState() []string { + return []string{ + string(EsuKeyStateActive), + string(EsuKeyStateInactive), + } +} + +func (s *EsuKeyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEsuKeyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEsuKeyState(input string) (*EsuKeyState, error) { + vals := map[string]EsuKeyState{ + "active": EsuKeyStateActive, + "inactive": EsuKeyStateInactive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EsuKeyState(input) + return &out, nil +} + +type EsuServerType string + +const ( + EsuServerTypeDatacenter EsuServerType = "Datacenter" + EsuServerTypeStandard EsuServerType = "Standard" +) + +func PossibleValuesForEsuServerType() []string { + return []string{ + string(EsuServerTypeDatacenter), + string(EsuServerTypeStandard), + } +} + +func (s *EsuServerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEsuServerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEsuServerType(input string) (*EsuServerType, error) { + vals := map[string]EsuServerType{ + "datacenter": EsuServerTypeDatacenter, + "standard": EsuServerTypeStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EsuServerType(input) + return &out, nil +} + +type LicenseProfileProductType string + +const ( + LicenseProfileProductTypeWindowsIoTEnterprise LicenseProfileProductType = "WindowsIoTEnterprise" + LicenseProfileProductTypeWindowsServer LicenseProfileProductType = "WindowsServer" +) + +func PossibleValuesForLicenseProfileProductType() []string { + return []string{ + string(LicenseProfileProductTypeWindowsIoTEnterprise), + string(LicenseProfileProductTypeWindowsServer), + } +} + +func (s *LicenseProfileProductType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseProfileProductType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseProfileProductType(input string) (*LicenseProfileProductType, error) { + vals := map[string]LicenseProfileProductType{ + "windowsiotenterprise": LicenseProfileProductTypeWindowsIoTEnterprise, + "windowsserver": LicenseProfileProductTypeWindowsServer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseProfileProductType(input) + return &out, nil +} + +type LicenseProfileSubscriptionStatus string + +const ( + LicenseProfileSubscriptionStatusDisabled LicenseProfileSubscriptionStatus = "Disabled" + LicenseProfileSubscriptionStatusDisabling LicenseProfileSubscriptionStatus = "Disabling" + LicenseProfileSubscriptionStatusEnabled LicenseProfileSubscriptionStatus = "Enabled" + LicenseProfileSubscriptionStatusEnabling LicenseProfileSubscriptionStatus = "Enabling" + LicenseProfileSubscriptionStatusFailed LicenseProfileSubscriptionStatus = "Failed" + LicenseProfileSubscriptionStatusUnknown LicenseProfileSubscriptionStatus = "Unknown" +) + +func PossibleValuesForLicenseProfileSubscriptionStatus() []string { + return []string{ + string(LicenseProfileSubscriptionStatusDisabled), + string(LicenseProfileSubscriptionStatusDisabling), + string(LicenseProfileSubscriptionStatusEnabled), + string(LicenseProfileSubscriptionStatusEnabling), + string(LicenseProfileSubscriptionStatusFailed), + string(LicenseProfileSubscriptionStatusUnknown), + } +} + +func (s *LicenseProfileSubscriptionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseProfileSubscriptionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseProfileSubscriptionStatus(input string) (*LicenseProfileSubscriptionStatus, error) { + vals := map[string]LicenseProfileSubscriptionStatus{ + "disabled": LicenseProfileSubscriptionStatusDisabled, + "disabling": LicenseProfileSubscriptionStatusDisabling, + "enabled": LicenseProfileSubscriptionStatusEnabled, + "enabling": LicenseProfileSubscriptionStatusEnabling, + "failed": LicenseProfileSubscriptionStatusFailed, + "unknown": LicenseProfileSubscriptionStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseProfileSubscriptionStatus(input) + return &out, nil +} + +type LicenseProfileSubscriptionStatusUpdate string + +const ( + LicenseProfileSubscriptionStatusUpdateDisable LicenseProfileSubscriptionStatusUpdate = "Disable" + LicenseProfileSubscriptionStatusUpdateEnable LicenseProfileSubscriptionStatusUpdate = "Enable" +) + +func PossibleValuesForLicenseProfileSubscriptionStatusUpdate() []string { + return []string{ + string(LicenseProfileSubscriptionStatusUpdateDisable), + string(LicenseProfileSubscriptionStatusUpdateEnable), + } +} + +func (s *LicenseProfileSubscriptionStatusUpdate) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseProfileSubscriptionStatusUpdate(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseProfileSubscriptionStatusUpdate(input string) (*LicenseProfileSubscriptionStatusUpdate, error) { + vals := map[string]LicenseProfileSubscriptionStatusUpdate{ + "disable": LicenseProfileSubscriptionStatusUpdateDisable, + "enable": LicenseProfileSubscriptionStatusUpdateEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseProfileSubscriptionStatusUpdate(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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/hybridcompute/2025-01-13/licenseprofiles/id_machine.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine.go new file mode 100644 index 00000000000..f9f26212e08 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine.go @@ -0,0 +1,130 @@ +package licenseprofiles + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine_test.go new file mode 100644 index 00000000000..4c7c6f7a0e6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/id_machine_test.go @@ -0,0 +1,282 @@ +package licenseprofiles + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/licenseprofiles/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_createorupdate.go new file mode 100644 index 00000000000..cb83be0f458 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_createorupdate.go @@ -0,0 +1,75 @@ +package licenseprofiles + +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 *LicenseProfile +} + +// CreateOrUpdate ... +func (c LicenseProfilesClient) CreateOrUpdate(ctx context.Context, id MachineId, input LicenseProfile) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/licenseProfiles/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c LicenseProfilesClient) CreateOrUpdateThenPoll(ctx context.Context, id MachineId, input LicenseProfile) 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/hybridcompute/2025-01-13/licenseprofiles/method_delete.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_delete.go new file mode 100644 index 00000000000..0bfcebcafef --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_delete.go @@ -0,0 +1,70 @@ +package licenseprofiles + +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 LicenseProfilesClient) Delete(ctx context.Context, id MachineId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/licenseProfiles/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 LicenseProfilesClient) DeleteThenPoll(ctx context.Context, id MachineId) 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/hybridcompute/2025-01-13/licenseprofiles/method_get.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_get.go new file mode 100644 index 00000000000..279fdf2630a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_get.go @@ -0,0 +1,54 @@ +package licenseprofiles + +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 *LicenseProfile +} + +// Get ... +func (c LicenseProfilesClient) Get(ctx context.Context, id MachineId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/licenseProfiles/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 LicenseProfile + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_list.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_list.go new file mode 100644 index 00000000000..26a2001c916 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_list.go @@ -0,0 +1,105 @@ +package licenseprofiles + +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 *[]LicenseProfile +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []LicenseProfile +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c LicenseProfilesClient) List(ctx context.Context, id MachineId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/licenseProfiles", 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 *[]LicenseProfile `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 LicenseProfilesClient) ListComplete(ctx context.Context, id MachineId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, LicenseProfileOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LicenseProfilesClient) ListCompleteMatchingPredicate(ctx context.Context, id MachineId, predicate LicenseProfileOperationPredicate) (result ListCompleteResult, err error) { + items := make([]LicenseProfile, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_update.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_update.go new file mode 100644 index 00000000000..df693a0faac --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/method_update.go @@ -0,0 +1,75 @@ +package licenseprofiles + +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 *LicenseProfile +} + +// Update ... +func (c LicenseProfilesClient) Update(ctx context.Context, id MachineId, input LicenseProfileUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/licenseProfiles/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c LicenseProfilesClient) UpdateThenPoll(ctx context.Context, id MachineId, input LicenseProfileUpdate) 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/hybridcompute/2025-01-13/licenseprofiles/model_erroradditionalinfo.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_erroradditionalinfo.go new file mode 100644 index 00000000000..446674fb266 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_errordetail.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_errordetail.go new file mode 100644 index 00000000000..99884f376cf --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_errordetail.go @@ -0,0 +1,12 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorDetail `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esukey.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esukey.go new file mode 100644 index 00000000000..e8ab1175d7e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esukey.go @@ -0,0 +1,9 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EsuKey struct { + LicenseStatus *int64 `json:"licenseStatus,omitempty"` + Sku *string `json:"sku,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esuprofileupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esuprofileupdateproperties.go new file mode 100644 index 00000000000..1196b4ce9ff --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_esuprofileupdateproperties.go @@ -0,0 +1,8 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EsuProfileUpdateProperties struct { + AssignedLicense *string `json:"assignedLicense,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofile.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofile.go new file mode 100644 index 00000000000..12fd7af9a65 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofile.go @@ -0,0 +1,18 @@ +package licenseprofiles + +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 LicenseProfile struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *LicenseProfileProperties `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/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmesuproperties.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmesuproperties.go new file mode 100644 index 00000000000..36a6e9f8eef --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmesuproperties.go @@ -0,0 +1,13 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileArmEsuProperties struct { + AssignedLicense *string `json:"assignedLicense,omitempty"` + AssignedLicenseImmutableId *string `json:"assignedLicenseImmutableId,omitempty"` + EsuEligibility *EsuEligibility `json:"esuEligibility,omitempty"` + EsuKeyState *EsuKeyState `json:"esuKeyState,omitempty"` + EsuKeys *[]EsuKey `json:"esuKeys,omitempty"` + ServerType *EsuServerType `json:"serverType,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmproductprofileproperties.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmproductprofileproperties.go new file mode 100644 index 00000000000..3e5f227a1fc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilearmproductprofileproperties.go @@ -0,0 +1,69 @@ +package licenseprofiles + +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 LicenseProfileArmProductProfileProperties struct { + BillingEndDate *string `json:"billingEndDate,omitempty"` + BillingStartDate *string `json:"billingStartDate,omitempty"` + DisenrollmentDate *string `json:"disenrollmentDate,omitempty"` + EnrollmentDate *string `json:"enrollmentDate,omitempty"` + Error *ErrorDetail `json:"error,omitempty"` + ProductFeatures *[]ProductFeature `json:"productFeatures,omitempty"` + ProductType *LicenseProfileProductType `json:"productType,omitempty"` + SubscriptionStatus *LicenseProfileSubscriptionStatus `json:"subscriptionStatus,omitempty"` +} + +func (o *LicenseProfileArmProductProfileProperties) GetBillingEndDateAsTime() (*time.Time, error) { + if o.BillingEndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingEndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetBillingEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingEndDate = &formatted +} + +func (o *LicenseProfileArmProductProfileProperties) GetBillingStartDateAsTime() (*time.Time, error) { + if o.BillingStartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingStartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetBillingStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingStartDate = &formatted +} + +func (o *LicenseProfileArmProductProfileProperties) GetDisenrollmentDateAsTime() (*time.Time, error) { + if o.DisenrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DisenrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetDisenrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DisenrollmentDate = &formatted +} + +func (o *LicenseProfileArmProductProfileProperties) GetEnrollmentDateAsTime() (*time.Time, error) { + if o.EnrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EnrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetEnrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EnrollmentDate = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileproperties.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileproperties.go new file mode 100644 index 00000000000..440ee28d7d8 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileproperties.go @@ -0,0 +1,11 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileProperties struct { + EsuProfile *LicenseProfileArmEsuProperties `json:"esuProfile,omitempty"` + ProductProfile *LicenseProfileArmProductProfileProperties `json:"productProfile,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SoftwareAssurance *LicenseProfilePropertiesSoftwareAssurance `json:"softwareAssurance,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilepropertiessoftwareassurance.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilepropertiessoftwareassurance.go new file mode 100644 index 00000000000..36b6491fc1b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofilepropertiessoftwareassurance.go @@ -0,0 +1,8 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfilePropertiesSoftwareAssurance struct { + SoftwareAssuranceCustomer *bool `json:"softwareAssuranceCustomer,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdate.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdate.go new file mode 100644 index 00000000000..af75c3770bf --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdate.go @@ -0,0 +1,9 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileUpdate struct { + Properties *LicenseProfileUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdateproperties.go new file mode 100644 index 00000000000..4716a59271e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdateproperties.go @@ -0,0 +1,10 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileUpdateProperties struct { + EsuProfile *EsuProfileUpdateProperties `json:"esuProfile,omitempty"` + ProductProfile *ProductProfileUpdateProperties `json:"productProfile,omitempty"` + SoftwareAssurance *LicenseProfileUpdatePropertiesSoftwareAssurance `json:"softwareAssurance,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdatepropertiessoftwareassurance.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdatepropertiessoftwareassurance.go new file mode 100644 index 00000000000..d31a53676ec --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_licenseprofileupdatepropertiessoftwareassurance.go @@ -0,0 +1,8 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileUpdatePropertiesSoftwareAssurance struct { + SoftwareAssuranceCustomer *bool `json:"softwareAssuranceCustomer,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeature.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeature.go new file mode 100644 index 00000000000..c8bb2caa861 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeature.go @@ -0,0 +1,68 @@ +package licenseprofiles + +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 ProductFeature struct { + BillingEndDate *string `json:"billingEndDate,omitempty"` + BillingStartDate *string `json:"billingStartDate,omitempty"` + DisenrollmentDate *string `json:"disenrollmentDate,omitempty"` + EnrollmentDate *string `json:"enrollmentDate,omitempty"` + Error *ErrorDetail `json:"error,omitempty"` + Name *string `json:"name,omitempty"` + SubscriptionStatus *LicenseProfileSubscriptionStatus `json:"subscriptionStatus,omitempty"` +} + +func (o *ProductFeature) GetBillingEndDateAsTime() (*time.Time, error) { + if o.BillingEndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingEndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetBillingEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingEndDate = &formatted +} + +func (o *ProductFeature) GetBillingStartDateAsTime() (*time.Time, error) { + if o.BillingStartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingStartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetBillingStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingStartDate = &formatted +} + +func (o *ProductFeature) GetDisenrollmentDateAsTime() (*time.Time, error) { + if o.DisenrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DisenrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetDisenrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DisenrollmentDate = &formatted +} + +func (o *ProductFeature) GetEnrollmentDateAsTime() (*time.Time, error) { + if o.EnrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EnrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetEnrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EnrollmentDate = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeatureupdate.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeatureupdate.go new file mode 100644 index 00000000000..87884710c9f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productfeatureupdate.go @@ -0,0 +1,9 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductFeatureUpdate struct { + Name *string `json:"name,omitempty"` + SubscriptionStatus *LicenseProfileSubscriptionStatusUpdate `json:"subscriptionStatus,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productprofileupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productprofileupdateproperties.go new file mode 100644 index 00000000000..20854ac4109 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/model_productprofileupdateproperties.go @@ -0,0 +1,10 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductProfileUpdateProperties struct { + ProductFeatures *[]ProductFeatureUpdate `json:"productFeatures,omitempty"` + ProductType *LicenseProfileProductType `json:"productType,omitempty"` + SubscriptionStatus *LicenseProfileSubscriptionStatusUpdate `json:"subscriptionStatus,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenseprofiles/predicates.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/predicates.go new file mode 100644 index 00000000000..60132d00c13 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/predicates.go @@ -0,0 +1,32 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p LicenseProfileOperationPredicate) Matches(input LicenseProfile) 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/hybridcompute/2025-01-13/licenseprofiles/version.go b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/version.go new file mode 100644 index 00000000000..86b35b0e7ae --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenseprofiles/version.go @@ -0,0 +1,10 @@ +package licenseprofiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/licenseprofiles/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/README.md b/resource-manager/hybridcompute/2025-01-13/licenses/README.md new file mode 100644 index 00000000000..4b84cf66a14 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/README.md @@ -0,0 +1,134 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/licenses` Documentation + +The `licenses` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/licenses" +``` + + +### Client Initialization + +```go +client := licenses.NewLicensesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LicensesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := licenses.NewLicenseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "licenseName") + +payload := licenses.License{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LicensesClient.Delete` + +```go +ctx := context.TODO() +id := licenses.NewLicenseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "licenseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LicensesClient.Get` + +```go +ctx := context.TODO() +id := licenses.NewLicenseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "licenseName") + +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: `LicensesClient.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: `LicensesClient.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: `LicensesClient.Update` + +```go +ctx := context.TODO() +id := licenses.NewLicenseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "licenseName") + +payload := licenses.LicenseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LicensesClient.ValidateLicense` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := licenses.License{ + // ... +} + + +if err := client.ValidateLicenseThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/client.go b/resource-manager/hybridcompute/2025-01-13/licenses/client.go new file mode 100644 index 00000000000..a12e02e31a2 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/client.go @@ -0,0 +1,26 @@ +package licenses + +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 LicensesClient struct { + Client *resourcemanager.Client +} + +func NewLicensesClientWithBaseURI(sdkApi sdkEnv.Api) (*LicensesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "licenses", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LicensesClient: %+v", err) + } + + return &LicensesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/constants.go b/resource-manager/hybridcompute/2025-01-13/licenses/constants.go new file mode 100644 index 00000000000..9bdf6c5df3d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/constants.go @@ -0,0 +1,315 @@ +package licenses + +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 LicenseCoreType string + +const ( + LicenseCoreTypePCore LicenseCoreType = "pCore" + LicenseCoreTypeVCore LicenseCoreType = "vCore" +) + +func PossibleValuesForLicenseCoreType() []string { + return []string{ + string(LicenseCoreTypePCore), + string(LicenseCoreTypeVCore), + } +} + +func (s *LicenseCoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseCoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseCoreType(input string) (*LicenseCoreType, error) { + vals := map[string]LicenseCoreType{ + "pcore": LicenseCoreTypePCore, + "vcore": LicenseCoreTypeVCore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseCoreType(input) + return &out, nil +} + +type LicenseEdition string + +const ( + LicenseEditionDatacenter LicenseEdition = "Datacenter" + LicenseEditionStandard LicenseEdition = "Standard" +) + +func PossibleValuesForLicenseEdition() []string { + return []string{ + string(LicenseEditionDatacenter), + string(LicenseEditionStandard), + } +} + +func (s *LicenseEdition) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseEdition(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseEdition(input string) (*LicenseEdition, error) { + vals := map[string]LicenseEdition{ + "datacenter": LicenseEditionDatacenter, + "standard": LicenseEditionStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseEdition(input) + return &out, nil +} + +type LicenseState string + +const ( + LicenseStateActivated LicenseState = "Activated" + LicenseStateDeactivated LicenseState = "Deactivated" +) + +func PossibleValuesForLicenseState() []string { + return []string{ + string(LicenseStateActivated), + string(LicenseStateDeactivated), + } +} + +func (s *LicenseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseState(input string) (*LicenseState, error) { + vals := map[string]LicenseState{ + "activated": LicenseStateActivated, + "deactivated": LicenseStateDeactivated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseState(input) + return &out, nil +} + +type LicenseTarget string + +const ( + LicenseTargetWindowsServerTwoZeroOneTwo LicenseTarget = "Windows Server 2012" + LicenseTargetWindowsServerTwoZeroOneTwoRTwo LicenseTarget = "Windows Server 2012 R2" +) + +func PossibleValuesForLicenseTarget() []string { + return []string{ + string(LicenseTargetWindowsServerTwoZeroOneTwo), + string(LicenseTargetWindowsServerTwoZeroOneTwoRTwo), + } +} + +func (s *LicenseTarget) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseTarget(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseTarget(input string) (*LicenseTarget, error) { + vals := map[string]LicenseTarget{ + "windows server 2012": LicenseTargetWindowsServerTwoZeroOneTwo, + "windows server 2012 r2": LicenseTargetWindowsServerTwoZeroOneTwoRTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseTarget(input) + return &out, nil +} + +type LicenseType string + +const ( + LicenseTypeESU LicenseType = "ESU" +) + +func PossibleValuesForLicenseType() []string { + return []string{ + string(LicenseTypeESU), + } +} + +func (s *LicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseType(input string) (*LicenseType, error) { + vals := map[string]LicenseType{ + "esu": LicenseTypeESU, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseType(input) + return &out, nil +} + +type ProgramYear string + +const ( + ProgramYearYearOne ProgramYear = "Year 1" + ProgramYearYearThree ProgramYear = "Year 3" + ProgramYearYearTwo ProgramYear = "Year 2" +) + +func PossibleValuesForProgramYear() []string { + return []string{ + string(ProgramYearYearOne), + string(ProgramYearYearThree), + string(ProgramYearYearTwo), + } +} + +func (s *ProgramYear) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProgramYear(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProgramYear(input string) (*ProgramYear, error) { + vals := map[string]ProgramYear{ + "year 1": ProgramYearYearOne, + "year 3": ProgramYearYearThree, + "year 2": ProgramYearYearTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProgramYear(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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/hybridcompute/2025-01-13/licenses/id_license.go b/resource-manager/hybridcompute/2025-01-13/licenses/id_license.go new file mode 100644 index 00000000000..48367c0ac0a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/id_license.go @@ -0,0 +1,130 @@ +package licenses + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LicenseId{}) +} + +var _ resourceids.ResourceId = &LicenseId{} + +// LicenseId is a struct representing the Resource ID for a License +type LicenseId struct { + SubscriptionId string + ResourceGroupName string + LicenseName string +} + +// NewLicenseID returns a new LicenseId struct +func NewLicenseID(subscriptionId string, resourceGroupName string, licenseName string) LicenseId { + return LicenseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LicenseName: licenseName, + } +} + +// ParseLicenseID parses 'input' into a LicenseId +func ParseLicenseID(input string) (*LicenseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LicenseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LicenseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLicenseIDInsensitively parses 'input' case-insensitively into a LicenseId +// note: this method should only be used for API response data and not user input +func ParseLicenseIDInsensitively(input string) (*LicenseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LicenseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LicenseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LicenseId) 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.LicenseName, ok = input.Parsed["licenseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "licenseName", input) + } + + return nil +} + +// ValidateLicenseID checks that 'input' can be parsed as a License ID +func ValidateLicenseID(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 := ParseLicenseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted License ID +func (id LicenseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/licenses/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LicenseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this License ID +func (id LicenseId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLicenses", "licenses", "licenses"), + resourceids.UserSpecifiedSegment("licenseName", "licenseName"), + } +} + +// String returns a human-readable description of this License ID +func (id LicenseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("License Name: %q", id.LicenseName), + } + return fmt.Sprintf("License (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/id_license_test.go b/resource-manager/hybridcompute/2025-01-13/licenses/id_license_test.go new file mode 100644 index 00000000000..9803c8a2bfc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/id_license_test.go @@ -0,0 +1,282 @@ +package licenses + +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 = &LicenseId{} + +func TestNewLicenseID(t *testing.T) { + id := NewLicenseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "licenseName") + + 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.LicenseName != "licenseName" { + t.Fatalf("Expected %q but got %q for Segment 'LicenseName'", id.LicenseName, "licenseName") + } +} + +func TestFormatLicenseID(t *testing.T) { + actual := NewLicenseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "licenseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses/licenseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLicenseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LicenseId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses/licenseName", + Expected: &LicenseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LicenseName: "licenseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses/licenseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLicenseID(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.LicenseName != v.Expected.LicenseName { + t.Fatalf("Expected %q but got %q for LicenseName", v.Expected.LicenseName, actual.LicenseName) + } + + } +} + +func TestParseLicenseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LicenseId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lIcEnSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses/licenseName", + Expected: &LicenseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LicenseName: "licenseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/licenses/licenseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lIcEnSeS/lIcEnSeNaMe", + Expected: &LicenseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LicenseName: "lIcEnSeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/lIcEnSeS/lIcEnSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLicenseIDInsensitively(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.LicenseName != v.Expected.LicenseName { + t.Fatalf("Expected %q but got %q for LicenseName", v.Expected.LicenseName, actual.LicenseName) + } + + } +} + +func TestSegmentsForLicenseId(t *testing.T) { + segments := LicenseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LicenseId 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/hybridcompute/2025-01-13/licenses/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_createorupdate.go new file mode 100644 index 00000000000..b572729126d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_createorupdate.go @@ -0,0 +1,74 @@ +package licenses + +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 *License +} + +// CreateOrUpdate ... +func (c LicensesClient) CreateOrUpdate(ctx context.Context, id LicenseId, input License) (result CreateOrUpdateOperationResponse, 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c LicensesClient) CreateOrUpdateThenPoll(ctx context.Context, id LicenseId, input License) 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/hybridcompute/2025-01-13/licenses/method_delete.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_delete.go new file mode 100644 index 00000000000..4a42150f68c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_delete.go @@ -0,0 +1,70 @@ +package licenses + +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 LicensesClient) Delete(ctx context.Context, id LicenseId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c LicensesClient) DeleteThenPoll(ctx context.Context, id LicenseId) 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/hybridcompute/2025-01-13/licenses/method_get.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_get.go new file mode 100644 index 00000000000..7247d371818 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_get.go @@ -0,0 +1,53 @@ +package licenses + +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 *License +} + +// Get ... +func (c LicensesClient) Get(ctx context.Context, id LicenseId) (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 License + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/method_listbyresourcegroup.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_listbyresourcegroup.go new file mode 100644 index 00000000000..39343752c8a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package licenses + +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 *[]License +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []License +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c LicensesClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/licenses", 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 *[]License `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 LicensesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, LicenseOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LicensesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate LicenseOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]License, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/method_listbysubscription.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_listbysubscription.go new file mode 100644 index 00000000000..7b0ddcef051 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_listbysubscription.go @@ -0,0 +1,106 @@ +package licenses + +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 *[]License +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []License +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c LicensesClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/licenses", 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 *[]License `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 LicensesClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, LicenseOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LicensesClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate LicenseOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]License, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/method_update.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_update.go new file mode 100644 index 00000000000..703baa380b2 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_update.go @@ -0,0 +1,74 @@ +package licenses + +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 *License +} + +// Update ... +func (c LicensesClient) Update(ctx context.Context, id LicenseId, input LicenseUpdate) (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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c LicensesClient) UpdateThenPoll(ctx context.Context, id LicenseId, input LicenseUpdate) 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/hybridcompute/2025-01-13/licenses/method_validatelicense.go b/resource-manager/hybridcompute/2025-01-13/licenses/method_validatelicense.go new file mode 100644 index 00000000000..0806e4c02d6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/method_validatelicense.go @@ -0,0 +1,75 @@ +package licenses + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateLicenseOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *License +} + +// ValidateLicense ... +func (c LicensesClient) ValidateLicense(ctx context.Context, id commonids.SubscriptionId, input License) (result ValidateLicenseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/validateLicense", 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 +} + +// ValidateLicenseThenPoll performs ValidateLicense then polls until it's completed +func (c LicensesClient) ValidateLicenseThenPoll(ctx context.Context, id commonids.SubscriptionId, input License) error { + result, err := c.ValidateLicense(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateLicense: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateLicense: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/model_license.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_license.go new file mode 100644 index 00000000000..815628a1884 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_license.go @@ -0,0 +1,18 @@ +package licenses + +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 License struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *LicenseProperties `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/hybridcompute/2025-01-13/licenses/model_licensedetails.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_licensedetails.go new file mode 100644 index 00000000000..5f54022ca0c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_licensedetails.go @@ -0,0 +1,15 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseDetails struct { + AssignedLicenses *int64 `json:"assignedLicenses,omitempty"` + Edition *LicenseEdition `json:"edition,omitempty"` + ImmutableId *string `json:"immutableId,omitempty"` + Processors *int64 `json:"processors,omitempty"` + State *LicenseState `json:"state,omitempty"` + Target *LicenseTarget `json:"target,omitempty"` + Type *LicenseCoreType `json:"type,omitempty"` + VolumeLicenseDetails *[]VolumeLicenseDetails `json:"volumeLicenseDetails,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseproperties.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseproperties.go new file mode 100644 index 00000000000..6c006867ae2 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseproperties.go @@ -0,0 +1,11 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProperties struct { + LicenseDetails *LicenseDetails `json:"licenseDetails,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdate.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdate.go new file mode 100644 index 00000000000..bf63b4ceb25 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdate.go @@ -0,0 +1,9 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseUpdate struct { + Properties *LicenseUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdateproperties.go new file mode 100644 index 00000000000..e455468786a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdateproperties.go @@ -0,0 +1,9 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseUpdateProperties struct { + LicenseDetails *LicenseUpdatePropertiesLicenseDetails `json:"licenseDetails,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdatepropertieslicensedetails.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdatepropertieslicensedetails.go new file mode 100644 index 00000000000..3e0d33eef6b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_licenseupdatepropertieslicensedetails.go @@ -0,0 +1,12 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseUpdatePropertiesLicenseDetails struct { + Edition *LicenseEdition `json:"edition,omitempty"` + Processors *int64 `json:"processors,omitempty"` + State *LicenseState `json:"state,omitempty"` + Target *LicenseTarget `json:"target,omitempty"` + Type *LicenseCoreType `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/model_volumelicensedetails.go b/resource-manager/hybridcompute/2025-01-13/licenses/model_volumelicensedetails.go new file mode 100644 index 00000000000..4064f981b57 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/model_volumelicensedetails.go @@ -0,0 +1,9 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VolumeLicenseDetails struct { + InvoiceId *string `json:"invoiceId,omitempty"` + ProgramYear *ProgramYear `json:"programYear,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/licenses/predicates.go b/resource-manager/hybridcompute/2025-01-13/licenses/predicates.go new file mode 100644 index 00000000000..1f36d46b8b3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/predicates.go @@ -0,0 +1,32 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p LicenseOperationPredicate) Matches(input License) 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/hybridcompute/2025-01-13/licenses/version.go b/resource-manager/hybridcompute/2025-01-13/licenses/version.go new file mode 100644 index 00000000000..7ac573db494 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/licenses/version.go @@ -0,0 +1,10 @@ +package licenses + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/licenses/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/README.md b/resource-manager/hybridcompute/2025-01-13/machineextensions/README.md new file mode 100644 index 00000000000..330710f2ccd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineextensions` Documentation + +The `machineextensions` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/machineextensions" +``` + + +### Client Initialization + +```go +client := machineextensions.NewMachineExtensionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachineExtensionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := machineextensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "extensionName") + +payload := machineextensions.MachineExtension{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachineExtensionsClient.Delete` + +```go +ctx := context.TODO() +id := machineextensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "extensionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachineExtensionsClient.Get` + +```go +ctx := context.TODO() +id := machineextensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "extensionName") + +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: `MachineExtensionsClient.List` + +```go +ctx := context.TODO() +id := machineextensions.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +// alternatively `client.List(ctx, id, machineextensions.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, machineextensions.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MachineExtensionsClient.Update` + +```go +ctx := context.TODO() +id := machineextensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "extensionName") + +payload := machineextensions.MachineExtensionUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/client.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/client.go new file mode 100644 index 00000000000..63a73f0818b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/client.go @@ -0,0 +1,26 @@ +package machineextensions + +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 MachineExtensionsClient struct { + Client *resourcemanager.Client +} + +func NewMachineExtensionsClientWithBaseURI(sdkApi sdkEnv.Api) (*MachineExtensionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "machineextensions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachineExtensionsClient: %+v", err) + } + + return &MachineExtensionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/constants.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/constants.go new file mode 100644 index 00000000000..13d3ae86a16 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/constants.go @@ -0,0 +1,54 @@ +package machineextensions + +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 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/hybridcompute/2025-01-13/machineextensions/id_extension.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension.go new file mode 100644 index 00000000000..854f23eb660 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension.go @@ -0,0 +1,139 @@ +package machineextensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExtensionId{}) +} + +var _ resourceids.ResourceId = &ExtensionId{} + +// ExtensionId is a struct representing the Resource ID for a Extension +type ExtensionId struct { + SubscriptionId string + ResourceGroupName string + MachineName string + ExtensionName string +} + +// NewExtensionID returns a new ExtensionId struct +func NewExtensionID(subscriptionId string, resourceGroupName string, machineName string, extensionName string) ExtensionId { + return ExtensionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", 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.HybridCompute/machines/%s/extensions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName, 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + resourceids.StaticSegment("staticExtensions", "extensions", "extensions"), + resourceids.UserSpecifiedSegment("extensionName", "extensionName"), + } +} + +// 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("Machine Name: %q", id.MachineName), + fmt.Sprintf("Extension Name: %q", id.ExtensionName), + } + return fmt.Sprintf("Extension (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension_test.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension_test.go new file mode 100644 index 00000000000..10db342c53e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_extension_test.go @@ -0,0 +1,327 @@ +package machineextensions + +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", "machineName", "extensionName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } + + if id.ExtensionName != "extensionName" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionName'", id.ExtensionName, "extensionName") + } +} + +func TestFormatExtensionID(t *testing.T) { + actual := NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "extensionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions/extensionName" + 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions/extensionName", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + ExtensionName: "extensionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions/extensionName/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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/eXtEnSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions/extensionName", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + ExtensionName: "extensionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extensions/extensionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/eXtEnSiOnS/eXtEnSiOnNaMe", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + ExtensionName: "eXtEnSiOnNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/eXtEnSiOnS/eXtEnSiOnNaMe/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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + 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/hybridcompute/2025-01-13/machineextensions/id_machine.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine.go new file mode 100644 index 00000000000..0023498d4a0 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine.go @@ -0,0 +1,130 @@ +package machineextensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine_test.go new file mode 100644 index 00000000000..3d4c801ca01 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/id_machine_test.go @@ -0,0 +1,282 @@ +package machineextensions + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/machineextensions/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_createorupdate.go new file mode 100644 index 00000000000..eb11e6f5104 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_createorupdate.go @@ -0,0 +1,75 @@ +package machineextensions + +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 *MachineExtension +} + +// CreateOrUpdate ... +func (c MachineExtensionsClient) CreateOrUpdate(ctx context.Context, id ExtensionId, input MachineExtension) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c MachineExtensionsClient) CreateOrUpdateThenPoll(ctx context.Context, id ExtensionId, input MachineExtension) 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/hybridcompute/2025-01-13/machineextensions/method_delete.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_delete.go new file mode 100644 index 00000000000..c816a230864 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_delete.go @@ -0,0 +1,71 @@ +package machineextensions + +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 MachineExtensionsClient) 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 MachineExtensionsClient) 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/hybridcompute/2025-01-13/machineextensions/method_get.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_get.go new file mode 100644 index 00000000000..de726cb7687 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_get.go @@ -0,0 +1,53 @@ +package machineextensions + +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 *MachineExtension +} + +// Get ... +func (c MachineExtensionsClient) 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 MachineExtension + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/method_list.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_list.go new file mode 100644 index 00000000000..508180edb27 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_list.go @@ -0,0 +1,134 @@ +package machineextensions + +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 *[]MachineExtension +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MachineExtension +} + +type ListOperationOptions struct { + Expand *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c MachineExtensionsClient) List(ctx context.Context, id MachineId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/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 *[]MachineExtension `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 MachineExtensionsClient) ListComplete(ctx context.Context, id MachineId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MachineExtensionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MachineExtensionsClient) ListCompleteMatchingPredicate(ctx context.Context, id MachineId, options ListOperationOptions, predicate MachineExtensionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MachineExtension, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/method_update.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_update.go new file mode 100644 index 00000000000..296ae0e28df --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/method_update.go @@ -0,0 +1,75 @@ +package machineextensions + +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 *MachineExtension +} + +// Update ... +func (c MachineExtensionsClient) Update(ctx context.Context, id ExtensionId, input MachineExtensionUpdate) (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 MachineExtensionsClient) UpdateThenPoll(ctx context.Context, id ExtensionId, input MachineExtensionUpdate) 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/hybridcompute/2025-01-13/machineextensions/model_machineextension.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextension.go new file mode 100644 index 00000000000..c763dea91ca --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextension.go @@ -0,0 +1,18 @@ +package machineextensions + +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 MachineExtension struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *MachineExtensionProperties `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/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceview.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceview.go new file mode 100644 index 00000000000..b97af53820a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceview.go @@ -0,0 +1,11 @@ +package machineextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionInstanceView struct { + Name *string `json:"name,omitempty"` + Status *MachineExtensionInstanceViewStatus `json:"status,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceviewstatus.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceviewstatus.go new file mode 100644 index 00000000000..74e73c50182 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensioninstanceviewstatus.go @@ -0,0 +1,30 @@ +package machineextensions + +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 MachineExtensionInstanceViewStatus 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 *MachineExtensionInstanceViewStatus) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineExtensionInstanceViewStatus) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionproperties.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionproperties.go new file mode 100644 index 00000000000..6a42b8991a1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionproperties.go @@ -0,0 +1,17 @@ +package machineextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionProperties struct { + AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,omitempty"` + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + InstanceView *MachineExtensionInstanceView `json:"instanceView,omitempty"` + ProtectedSettings *map[string]interface{} `json:"protectedSettings,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Settings *map[string]interface{} `json:"settings,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdate.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdate.go new file mode 100644 index 00000000000..a1a0b788156 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdate.go @@ -0,0 +1,9 @@ +package machineextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionUpdate struct { + Properties *MachineExtensionUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdateproperties.go new file mode 100644 index 00000000000..9d7d54fd6cc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/model_machineextensionupdateproperties.go @@ -0,0 +1,15 @@ +package machineextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionUpdateProperties struct { + AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,omitempty"` + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + ProtectedSettings *map[string]interface{} `json:"protectedSettings,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Settings *map[string]interface{} `json:"settings,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensions/predicates.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/predicates.go new file mode 100644 index 00000000000..2eae3b57239 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/predicates.go @@ -0,0 +1,32 @@ +package machineextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p MachineExtensionOperationPredicate) Matches(input MachineExtension) 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/hybridcompute/2025-01-13/machineextensions/version.go b/resource-manager/hybridcompute/2025-01-13/machineextensions/version.go new file mode 100644 index 00000000000..3ff43c567dc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensions/version.go @@ -0,0 +1,10 @@ +package machineextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/machineextensions/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/README.md b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/README.md new file mode 100644 index 00000000000..41711cc638f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineextensionssetup` Documentation + +The `machineextensionssetup` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/machineextensionssetup" +``` + + +### Client Initialization + +```go +client := machineextensionssetup.NewMachineExtensionsSetupClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachineExtensionsSetupClient.SetupExtensions` + +```go +ctx := context.TODO() +id := machineextensionssetup.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := machineextensionssetup.SetupExtensionRequest{ + // ... +} + + +if err := client.SetupExtensionsThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/client.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/client.go new file mode 100644 index 00000000000..882d0b25083 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/client.go @@ -0,0 +1,26 @@ +package machineextensionssetup + +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 MachineExtensionsSetupClient struct { + Client *resourcemanager.Client +} + +func NewMachineExtensionsSetupClientWithBaseURI(sdkApi sdkEnv.Api) (*MachineExtensionsSetupClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "machineextensionssetup", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachineExtensionsSetupClient: %+v", err) + } + + return &MachineExtensionsSetupClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/constants.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/constants.go new file mode 100644 index 00000000000..b7a755556c1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/constants.go @@ -0,0 +1,54 @@ +package machineextensionssetup + +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 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/hybridcompute/2025-01-13/machineextensionssetup/id_machine.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine.go new file mode 100644 index 00000000000..ae2c373f621 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine.go @@ -0,0 +1,130 @@ +package machineextensionssetup + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine_test.go new file mode 100644 index 00000000000..0dbc937c2d2 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/id_machine_test.go @@ -0,0 +1,282 @@ +package machineextensionssetup + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/machineextensionssetup/method_setupextensions.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/method_setupextensions.go new file mode 100644 index 00000000000..42426421c51 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/method_setupextensions.go @@ -0,0 +1,75 @@ +package machineextensionssetup + +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 SetupExtensionsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SetupExtensionRequest +} + +// SetupExtensions ... +func (c MachineExtensionsSetupClient) SetupExtensions(ctx context.Context, id MachineId, input SetupExtensionRequest) (result SetupExtensionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/addExtensions", 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 +} + +// SetupExtensionsThenPoll performs SetupExtensions then polls until it's completed +func (c MachineExtensionsSetupClient) SetupExtensionsThenPoll(ctx context.Context, id MachineId, input SetupExtensionRequest) error { + result, err := c.SetupExtensions(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SetupExtensions: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SetupExtensions: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceview.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceview.go new file mode 100644 index 00000000000..53a55ad74c4 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceview.go @@ -0,0 +1,11 @@ +package machineextensionssetup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionInstanceView struct { + Name *string `json:"name,omitempty"` + Status *MachineExtensionInstanceViewStatus `json:"status,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceviewstatus.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceviewstatus.go new file mode 100644 index 00000000000..3470fd62b9d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensioninstanceviewstatus.go @@ -0,0 +1,30 @@ +package machineextensionssetup + +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 MachineExtensionInstanceViewStatus 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 *MachineExtensionInstanceViewStatus) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineExtensionInstanceViewStatus) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensionproperties.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensionproperties.go new file mode 100644 index 00000000000..e5af5d92536 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_machineextensionproperties.go @@ -0,0 +1,17 @@ +package machineextensionssetup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionProperties struct { + AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,omitempty"` + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + InstanceView *MachineExtensionInstanceView `json:"instanceView,omitempty"` + ProtectedSettings *map[string]interface{} `json:"protectedSettings,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Settings *map[string]interface{} `json:"settings,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_setupextensionrequest.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_setupextensionrequest.go new file mode 100644 index 00000000000..d773b583754 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/model_setupextensionrequest.go @@ -0,0 +1,8 @@ +package machineextensionssetup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SetupExtensionRequest struct { + Extensions *[]MachineExtensionProperties `json:"extensions,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/version.go b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/version.go new file mode 100644 index 00000000000..7e19172a9d1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionssetup/version.go @@ -0,0 +1,10 @@ +package machineextensionssetup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/machineextensionssetup/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/README.md b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/README.md new file mode 100644 index 00000000000..322c6e7097d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade` Documentation + +The `machineextensionsupgrade` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/machineextensionsupgrade" +``` + + +### Client Initialization + +```go +client := machineextensionsupgrade.NewMachineExtensionsUpgradeClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachineExtensionsUpgradeClient.UpgradeExtensions` + +```go +ctx := context.TODO() +id := machineextensionsupgrade.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := machineextensionsupgrade.MachineExtensionUpgrade{ + // ... +} + + +if err := client.UpgradeExtensionsThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/client.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/client.go new file mode 100644 index 00000000000..861b4b3e65d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/client.go @@ -0,0 +1,26 @@ +package machineextensionsupgrade + +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 MachineExtensionsUpgradeClient struct { + Client *resourcemanager.Client +} + +func NewMachineExtensionsUpgradeClientWithBaseURI(sdkApi sdkEnv.Api) (*MachineExtensionsUpgradeClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "machineextensionsupgrade", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachineExtensionsUpgradeClient: %+v", err) + } + + return &MachineExtensionsUpgradeClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine.go new file mode 100644 index 00000000000..15566f25342 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine.go @@ -0,0 +1,130 @@ +package machineextensionsupgrade + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine_test.go new file mode 100644 index 00000000000..f4d798c3e8e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/id_machine_test.go @@ -0,0 +1,282 @@ +package machineextensionsupgrade + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/machineextensionsupgrade/method_upgradeextensions.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/method_upgradeextensions.go new file mode 100644 index 00000000000..4b6f42a914e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/method_upgradeextensions.go @@ -0,0 +1,74 @@ +package machineextensionsupgrade + +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 UpgradeExtensionsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// UpgradeExtensions ... +func (c MachineExtensionsUpgradeClient) UpgradeExtensions(ctx context.Context, id MachineId, input MachineExtensionUpgrade) (result UpgradeExtensionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgradeExtensions", 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 +} + +// UpgradeExtensionsThenPoll performs UpgradeExtensions then polls until it's completed +func (c MachineExtensionsUpgradeClient) UpgradeExtensionsThenPoll(ctx context.Context, id MachineId, input MachineExtensionUpgrade) error { + result, err := c.UpgradeExtensions(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpgradeExtensions: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpgradeExtensions: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_extensiontargetproperties.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_extensiontargetproperties.go new file mode 100644 index 00000000000..b5ea39e4f25 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_extensiontargetproperties.go @@ -0,0 +1,8 @@ +package machineextensionsupgrade + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtensionTargetProperties struct { + TargetVersion *string `json:"targetVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_machineextensionupgrade.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_machineextensionupgrade.go new file mode 100644 index 00000000000..1fe7a0c95cd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/model_machineextensionupgrade.go @@ -0,0 +1,8 @@ +package machineextensionsupgrade + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionUpgrade struct { + ExtensionTargets *map[string]ExtensionTargetProperties `json:"extensionTargets,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/version.go b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/version.go new file mode 100644 index 00000000000..ec065275cf7 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineextensionsupgrade/version.go @@ -0,0 +1,10 @@ +package machineextensionsupgrade + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/machineextensionsupgrade/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/README.md b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/README.md new file mode 100644 index 00000000000..4ca6c66db69 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile` Documentation + +The `machinenetworkprofile` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/machinenetworkprofile" +``` + + +### Client Initialization + +```go +client := machinenetworkprofile.NewMachineNetworkProfileClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachineNetworkProfileClient.NetworkProfileGet` + +```go +ctx := context.TODO() +id := machinenetworkprofile.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +read, err := client.NetworkProfileGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/client.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/client.go new file mode 100644 index 00000000000..0f388f5eceb --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/client.go @@ -0,0 +1,26 @@ +package machinenetworkprofile + +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 MachineNetworkProfileClient struct { + Client *resourcemanager.Client +} + +func NewMachineNetworkProfileClientWithBaseURI(sdkApi sdkEnv.Api) (*MachineNetworkProfileClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "machinenetworkprofile", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachineNetworkProfileClient: %+v", err) + } + + return &MachineNetworkProfileClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine.go new file mode 100644 index 00000000000..170e5b45680 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine.go @@ -0,0 +1,130 @@ +package machinenetworkprofile + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine_test.go new file mode 100644 index 00000000000..dc091276f70 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/id_machine_test.go @@ -0,0 +1,282 @@ +package machinenetworkprofile + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/machinenetworkprofile/method_networkprofileget.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/method_networkprofileget.go new file mode 100644 index 00000000000..f442788d530 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/method_networkprofileget.go @@ -0,0 +1,54 @@ +package machinenetworkprofile + +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 NetworkProfileGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NetworkProfile +} + +// NetworkProfileGet ... +func (c MachineNetworkProfileClient) NetworkProfileGet(ctx context.Context, id MachineId) (result NetworkProfileGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/networkProfile", 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 NetworkProfile + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_ipaddress.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_ipaddress.go new file mode 100644 index 00000000000..7167975f486 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_ipaddress.go @@ -0,0 +1,10 @@ +package machinenetworkprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPAddress struct { + Address *string `json:"address,omitempty"` + IPAddressVersion *string `json:"ipAddressVersion,omitempty"` + Subnet *Subnet `json:"subnet,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkinterface.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkinterface.go new file mode 100644 index 00000000000..3c27eea6cdf --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkinterface.go @@ -0,0 +1,11 @@ +package machinenetworkprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkInterface struct { + IPAddresses *[]IPAddress `json:"ipAddresses,omitempty"` + Id *string `json:"id,omitempty"` + MacAddress *string `json:"macAddress,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkprofile.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkprofile.go new file mode 100644 index 00000000000..d5932255632 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_networkprofile.go @@ -0,0 +1,8 @@ +package machinenetworkprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkProfile struct { + NetworkInterfaces *[]NetworkInterface `json:"networkInterfaces,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_subnet.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_subnet.go new file mode 100644 index 00000000000..4f76d903b98 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/model_subnet.go @@ -0,0 +1,8 @@ +package machinenetworkprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Subnet struct { + AddressPrefix *string `json:"addressPrefix,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/version.go b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/version.go new file mode 100644 index 00000000000..9703f4b82c1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machinenetworkprofile/version.go @@ -0,0 +1,10 @@ +package machinenetworkprofile + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/machinenetworkprofile/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/README.md b/resource-manager/hybridcompute/2025-01-13/machineruncommands/README.md new file mode 100644 index 00000000000..941cc852dff --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machineruncommands` Documentation + +The `machineruncommands` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/machineruncommands" +``` + + +### Client Initialization + +```go +client := machineruncommands.NewMachineRunCommandsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachineRunCommandsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := machineruncommands.NewRunCommandID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "runCommandName") + +payload := machineruncommands.MachineRunCommand{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachineRunCommandsClient.Delete` + +```go +ctx := context.TODO() +id := machineruncommands.NewRunCommandID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "runCommandName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachineRunCommandsClient.Get` + +```go +ctx := context.TODO() +id := machineruncommands.NewRunCommandID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "runCommandName") + +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: `MachineRunCommandsClient.List` + +```go +ctx := context.TODO() +id := machineruncommands.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +// alternatively `client.List(ctx, id, machineruncommands.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, machineruncommands.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MachineRunCommandsClient.Update` + +```go +ctx := context.TODO() +id := machineruncommands.NewRunCommandID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "runCommandName") + +payload := machineruncommands.ResourceUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/client.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/client.go new file mode 100644 index 00000000000..f1bca1ef53f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/client.go @@ -0,0 +1,26 @@ +package machineruncommands + +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 MachineRunCommandsClient struct { + Client *resourcemanager.Client +} + +func NewMachineRunCommandsClientWithBaseURI(sdkApi sdkEnv.Api) (*MachineRunCommandsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "machineruncommands", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachineRunCommandsClient: %+v", err) + } + + return &MachineRunCommandsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/constants.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/constants.go new file mode 100644 index 00000000000..cdd6fd2665b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/constants.go @@ -0,0 +1,110 @@ +package machineruncommands + +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 ExecutionState string + +const ( + ExecutionStateCanceled ExecutionState = "Canceled" + ExecutionStateFailed ExecutionState = "Failed" + ExecutionStatePending ExecutionState = "Pending" + ExecutionStateRunning ExecutionState = "Running" + ExecutionStateSucceeded ExecutionState = "Succeeded" + ExecutionStateTimedOut ExecutionState = "TimedOut" + ExecutionStateUnknown ExecutionState = "Unknown" +) + +func PossibleValuesForExecutionState() []string { + return []string{ + string(ExecutionStateCanceled), + string(ExecutionStateFailed), + string(ExecutionStatePending), + string(ExecutionStateRunning), + string(ExecutionStateSucceeded), + string(ExecutionStateTimedOut), + string(ExecutionStateUnknown), + } +} + +func (s *ExecutionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExecutionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExecutionState(input string) (*ExecutionState, error) { + vals := map[string]ExecutionState{ + "canceled": ExecutionStateCanceled, + "failed": ExecutionStateFailed, + "pending": ExecutionStatePending, + "running": ExecutionStateRunning, + "succeeded": ExecutionStateSucceeded, + "timedout": ExecutionStateTimedOut, + "unknown": ExecutionStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExecutionState(input) + return &out, nil +} + +type ExtensionsStatusLevelTypes string + +const ( + ExtensionsStatusLevelTypesError ExtensionsStatusLevelTypes = "Error" + ExtensionsStatusLevelTypesInfo ExtensionsStatusLevelTypes = "Info" + ExtensionsStatusLevelTypesWarning ExtensionsStatusLevelTypes = "Warning" +) + +func PossibleValuesForExtensionsStatusLevelTypes() []string { + return []string{ + string(ExtensionsStatusLevelTypesError), + string(ExtensionsStatusLevelTypesInfo), + string(ExtensionsStatusLevelTypesWarning), + } +} + +func (s *ExtensionsStatusLevelTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtensionsStatusLevelTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtensionsStatusLevelTypes(input string) (*ExtensionsStatusLevelTypes, error) { + vals := map[string]ExtensionsStatusLevelTypes{ + "error": ExtensionsStatusLevelTypesError, + "info": ExtensionsStatusLevelTypesInfo, + "warning": ExtensionsStatusLevelTypesWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtensionsStatusLevelTypes(input) + return &out, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine.go new file mode 100644 index 00000000000..ce3ee24513c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine.go @@ -0,0 +1,130 @@ +package machineruncommands + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine_test.go new file mode 100644 index 00000000000..8cf75885a3c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_machine_test.go @@ -0,0 +1,282 @@ +package machineruncommands + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/machineruncommands/id_runcommand.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand.go new file mode 100644 index 00000000000..8cea0fa0ad9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand.go @@ -0,0 +1,139 @@ +package machineruncommands + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RunCommandId{}) +} + +var _ resourceids.ResourceId = &RunCommandId{} + +// RunCommandId is a struct representing the Resource ID for a Run Command +type RunCommandId struct { + SubscriptionId string + ResourceGroupName string + MachineName string + RunCommandName string +} + +// NewRunCommandID returns a new RunCommandId struct +func NewRunCommandID(subscriptionId string, resourceGroupName string, machineName string, runCommandName string) RunCommandId { + return RunCommandId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + RunCommandName: runCommandName, + } +} + +// ParseRunCommandID parses 'input' into a RunCommandId +func ParseRunCommandID(input string) (*RunCommandId, error) { + parser := resourceids.NewParserFromResourceIdType(&RunCommandId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RunCommandId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRunCommandIDInsensitively parses 'input' case-insensitively into a RunCommandId +// note: this method should only be used for API response data and not user input +func ParseRunCommandIDInsensitively(input string) (*RunCommandId, error) { + parser := resourceids.NewParserFromResourceIdType(&RunCommandId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RunCommandId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RunCommandId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + if id.RunCommandName, ok = input.Parsed["runCommandName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "runCommandName", input) + } + + return nil +} + +// ValidateRunCommandID checks that 'input' can be parsed as a Run Command ID +func ValidateRunCommandID(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 := ParseRunCommandID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Run Command ID +func (id RunCommandId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s/runCommands/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName, id.RunCommandName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Run Command ID +func (id RunCommandId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + resourceids.StaticSegment("staticRunCommands", "runCommands", "runCommands"), + resourceids.UserSpecifiedSegment("runCommandName", "runCommandName"), + } +} + +// String returns a human-readable description of this Run Command ID +func (id RunCommandId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + fmt.Sprintf("Run Command Name: %q", id.RunCommandName), + } + return fmt.Sprintf("Run Command (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand_test.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand_test.go new file mode 100644 index 00000000000..3421b9736b5 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/id_runcommand_test.go @@ -0,0 +1,327 @@ +package machineruncommands + +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 = &RunCommandId{} + +func TestNewRunCommandID(t *testing.T) { + id := NewRunCommandID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "runCommandName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } + + if id.RunCommandName != "runCommandName" { + t.Fatalf("Expected %q but got %q for Segment 'RunCommandName'", id.RunCommandName, "runCommandName") + } +} + +func TestFormatRunCommandID(t *testing.T) { + actual := NewRunCommandID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName", "runCommandName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands/runCommandName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRunCommandID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RunCommandId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands/runCommandName", + Expected: &RunCommandId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + RunCommandName: "runCommandName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands/runCommandName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRunCommandID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + if actual.RunCommandName != v.Expected.RunCommandName { + t.Fatalf("Expected %q but got %q for RunCommandName", v.Expected.RunCommandName, actual.RunCommandName) + } + + } +} + +func TestParseRunCommandIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RunCommandId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/rUnCoMmAnDs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands/runCommandName", + Expected: &RunCommandId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + RunCommandName: "runCommandName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/runCommands/runCommandName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/rUnCoMmAnDs/rUnCoMmAnDnAmE", + Expected: &RunCommandId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + RunCommandName: "rUnCoMmAnDnAmE", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/rUnCoMmAnDs/rUnCoMmAnDnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRunCommandIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + if actual.RunCommandName != v.Expected.RunCommandName { + t.Fatalf("Expected %q but got %q for RunCommandName", v.Expected.RunCommandName, actual.RunCommandName) + } + + } +} + +func TestSegmentsForRunCommandId(t *testing.T) { + segments := RunCommandId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RunCommandId 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/hybridcompute/2025-01-13/machineruncommands/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_createorupdate.go new file mode 100644 index 00000000000..632fa807335 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_createorupdate.go @@ -0,0 +1,75 @@ +package machineruncommands + +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 *MachineRunCommand +} + +// CreateOrUpdate ... +func (c MachineRunCommandsClient) CreateOrUpdate(ctx context.Context, id RunCommandId, input MachineRunCommand) (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 MachineRunCommandsClient) CreateOrUpdateThenPoll(ctx context.Context, id RunCommandId, input MachineRunCommand) 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/hybridcompute/2025-01-13/machineruncommands/method_delete.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_delete.go new file mode 100644 index 00000000000..33f0c706489 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_delete.go @@ -0,0 +1,70 @@ +package machineruncommands + +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 MachineRunCommandsClient) Delete(ctx context.Context, id RunCommandId) (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 MachineRunCommandsClient) DeleteThenPoll(ctx context.Context, id RunCommandId) 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/hybridcompute/2025-01-13/machineruncommands/method_get.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_get.go new file mode 100644 index 00000000000..5e4446d620e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_get.go @@ -0,0 +1,53 @@ +package machineruncommands + +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 *MachineRunCommand +} + +// Get ... +func (c MachineRunCommandsClient) Get(ctx context.Context, id RunCommandId) (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 MachineRunCommand + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_list.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_list.go new file mode 100644 index 00000000000..98097fdb481 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_list.go @@ -0,0 +1,134 @@ +package machineruncommands + +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 *[]MachineRunCommand +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MachineRunCommand +} + +type ListOperationOptions struct { + Expand *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c MachineRunCommandsClient) List(ctx context.Context, id MachineId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/runCommands", 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 *[]MachineRunCommand `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 MachineRunCommandsClient) ListComplete(ctx context.Context, id MachineId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MachineRunCommandOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MachineRunCommandsClient) ListCompleteMatchingPredicate(ctx context.Context, id MachineId, options ListOperationOptions, predicate MachineRunCommandOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MachineRunCommand, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_update.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_update.go new file mode 100644 index 00000000000..877b1944718 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/method_update.go @@ -0,0 +1,75 @@ +package machineruncommands + +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 *MachineRunCommand +} + +// Update ... +func (c MachineRunCommandsClient) Update(ctx context.Context, id RunCommandId, input ResourceUpdate) (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 MachineRunCommandsClient) UpdateThenPoll(ctx context.Context, id RunCommandId, input ResourceUpdate) 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/hybridcompute/2025-01-13/machineruncommands/model_extensionsresourcestatus.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_extensionsresourcestatus.go new file mode 100644 index 00000000000..c0714bcf247 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_extensionsresourcestatus.go @@ -0,0 +1,30 @@ +package machineruncommands + +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 ExtensionsResourceStatus struct { + Code *string `json:"code,omitempty"` + DisplayStatus *string `json:"displayStatus,omitempty"` + Level *ExtensionsStatusLevelTypes `json:"level,omitempty"` + Message *string `json:"message,omitempty"` + Time *string `json:"time,omitempty"` +} + +func (o *ExtensionsResourceStatus) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExtensionsResourceStatus) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommand.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommand.go new file mode 100644 index 00000000000..e876c805eb5 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommand.go @@ -0,0 +1,18 @@ +package machineruncommands + +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 MachineRunCommand struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *MachineRunCommandProperties `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/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandinstanceview.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandinstanceview.go new file mode 100644 index 00000000000..3411dc56ad6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandinstanceview.go @@ -0,0 +1,45 @@ +package machineruncommands + +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 MachineRunCommandInstanceView struct { + EndTime *string `json:"endTime,omitempty"` + Error *string `json:"error,omitempty"` + ExecutionMessage *string `json:"executionMessage,omitempty"` + ExecutionState *ExecutionState `json:"executionState,omitempty"` + ExitCode *int64 `json:"exitCode,omitempty"` + Output *string `json:"output,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Statuses *[]ExtensionsResourceStatus `json:"statuses,omitempty"` +} + +func (o *MachineRunCommandInstanceView) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineRunCommandInstanceView) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *MachineRunCommandInstanceView) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineRunCommandInstanceView) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandproperties.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandproperties.go new file mode 100644 index 00000000000..b1a989e567b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandproperties.go @@ -0,0 +1,20 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineRunCommandProperties struct { + AsyncExecution *bool `json:"asyncExecution,omitempty"` + ErrorBlobManagedIdentity *RunCommandManagedIdentity `json:"errorBlobManagedIdentity,omitempty"` + ErrorBlobUri *string `json:"errorBlobUri,omitempty"` + InstanceView *MachineRunCommandInstanceView `json:"instanceView,omitempty"` + OutputBlobManagedIdentity *RunCommandManagedIdentity `json:"outputBlobManagedIdentity,omitempty"` + OutputBlobUri *string `json:"outputBlobUri,omitempty"` + Parameters *[]RunCommandInputParameter `json:"parameters,omitempty"` + ProtectedParameters *[]RunCommandInputParameter `json:"protectedParameters,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + RunAsPassword *string `json:"runAsPassword,omitempty"` + RunAsUser *string `json:"runAsUser,omitempty"` + Source *MachineRunCommandScriptSource `json:"source,omitempty"` + TimeoutInSeconds *int64 `json:"timeoutInSeconds,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandscriptsource.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandscriptsource.go new file mode 100644 index 00000000000..b6b04596abe --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_machineruncommandscriptsource.go @@ -0,0 +1,11 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineRunCommandScriptSource struct { + CommandId *string `json:"commandId,omitempty"` + Script *string `json:"script,omitempty"` + ScriptUri *string `json:"scriptUri,omitempty"` + ScriptUriManagedIdentity *RunCommandManagedIdentity `json:"scriptUriManagedIdentity,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_resourceupdate.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_resourceupdate.go new file mode 100644 index 00000000000..c2f13d8b31e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_resourceupdate.go @@ -0,0 +1,8 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceUpdate struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandinputparameter.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandinputparameter.go new file mode 100644 index 00000000000..b44b9f94f36 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandinputparameter.go @@ -0,0 +1,9 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunCommandInputParameter struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandmanagedidentity.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandmanagedidentity.go new file mode 100644 index 00000000000..27ecd5f9216 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/model_runcommandmanagedidentity.go @@ -0,0 +1,9 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunCommandManagedIdentity struct { + ClientId *string `json:"clientId,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machineruncommands/predicates.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/predicates.go new file mode 100644 index 00000000000..7af4c116e94 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/predicates.go @@ -0,0 +1,32 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineRunCommandOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p MachineRunCommandOperationPredicate) Matches(input MachineRunCommand) 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/hybridcompute/2025-01-13/machineruncommands/version.go b/resource-manager/hybridcompute/2025-01-13/machineruncommands/version.go new file mode 100644 index 00000000000..1ed5c9497fa --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machineruncommands/version.go @@ -0,0 +1,10 @@ +package machineruncommands + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/machineruncommands/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/README.md b/resource-manager/hybridcompute/2025-01-13/machines/README.md new file mode 100644 index 00000000000..a30a36e76a6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/README.md @@ -0,0 +1,154 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/machines` Documentation + +The `machines` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/machines" +``` + + +### Client Initialization + +```go +client := machines.NewMachinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MachinesClient.AssessPatches` + +```go +ctx := context.TODO() +id := machines.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +if err := client.AssessPatchesThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachinesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := machines.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := machines.Machine{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, machines.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MachinesClient.Delete` + +```go +ctx := context.TODO() +id := machines.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachinesClient.Get` + +```go +ctx := context.TODO() +id := machines.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +read, err := client.Get(ctx, id, machines.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MachinesClient.InstallPatches` + +```go +ctx := context.TODO() +id := machines.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := machines.MachineInstallPatchesParameters{ + // ... +} + + +if err := client.InstallPatchesThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MachinesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, machines.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, machines.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MachinesClient.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: `MachinesClient.Update` + +```go +ctx := context.TODO() +id := machines.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := machines.MachineUpdate{ + // ... +} + + +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/hybridcompute/2025-01-13/machines/client.go b/resource-manager/hybridcompute/2025-01-13/machines/client.go new file mode 100644 index 00000000000..fcd8a61002f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/client.go @@ -0,0 +1,26 @@ +package machines + +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 MachinesClient struct { + Client *resourcemanager.Client +} + +func NewMachinesClientWithBaseURI(sdkApi sdkEnv.Api) (*MachinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "machines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MachinesClient: %+v", err) + } + + return &MachinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/constants.go b/resource-manager/hybridcompute/2025-01-13/machines/constants.go new file mode 100644 index 00000000000..0d295983ef4 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/constants.go @@ -0,0 +1,1460 @@ +package machines + +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 AgentConfigurationMode string + +const ( + AgentConfigurationModeFull AgentConfigurationMode = "full" + AgentConfigurationModeMonitor AgentConfigurationMode = "monitor" +) + +func PossibleValuesForAgentConfigurationMode() []string { + return []string{ + string(AgentConfigurationModeFull), + string(AgentConfigurationModeMonitor), + } +} + +func (s *AgentConfigurationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAgentConfigurationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAgentConfigurationMode(input string) (*AgentConfigurationMode, error) { + vals := map[string]AgentConfigurationMode{ + "full": AgentConfigurationModeFull, + "monitor": AgentConfigurationModeMonitor, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AgentConfigurationMode(input) + return &out, nil +} + +type ArcKindEnum string + +const ( + ArcKindEnumAVS ArcKindEnum = "AVS" + ArcKindEnumAWS ArcKindEnum = "AWS" + ArcKindEnumEPS ArcKindEnum = "EPS" + ArcKindEnumGCP ArcKindEnum = "GCP" + ArcKindEnumHCI ArcKindEnum = "HCI" + ArcKindEnumSCVMM ArcKindEnum = "SCVMM" + ArcKindEnumVMware ArcKindEnum = "VMware" +) + +func PossibleValuesForArcKindEnum() []string { + return []string{ + string(ArcKindEnumAVS), + string(ArcKindEnumAWS), + string(ArcKindEnumEPS), + string(ArcKindEnumGCP), + string(ArcKindEnumHCI), + string(ArcKindEnumSCVMM), + string(ArcKindEnumVMware), + } +} + +func (s *ArcKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseArcKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseArcKindEnum(input string) (*ArcKindEnum, error) { + vals := map[string]ArcKindEnum{ + "avs": ArcKindEnumAVS, + "aws": ArcKindEnumAWS, + "eps": ArcKindEnumEPS, + "gcp": ArcKindEnumGCP, + "hci": ArcKindEnumHCI, + "scvmm": ArcKindEnumSCVMM, + "vmware": ArcKindEnumVMware, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ArcKindEnum(input) + return &out, nil +} + +type AssessmentModeTypes string + +const ( + AssessmentModeTypesAutomaticByPlatform AssessmentModeTypes = "AutomaticByPlatform" + AssessmentModeTypesImageDefault AssessmentModeTypes = "ImageDefault" +) + +func PossibleValuesForAssessmentModeTypes() []string { + return []string{ + string(AssessmentModeTypesAutomaticByPlatform), + string(AssessmentModeTypesImageDefault), + } +} + +func (s *AssessmentModeTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAssessmentModeTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAssessmentModeTypes(input string) (*AssessmentModeTypes, error) { + vals := map[string]AssessmentModeTypes{ + "automaticbyplatform": AssessmentModeTypesAutomaticByPlatform, + "imagedefault": AssessmentModeTypesImageDefault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AssessmentModeTypes(input) + return &out, nil +} + +type EsuEligibility string + +const ( + EsuEligibilityEligible EsuEligibility = "Eligible" + EsuEligibilityIneligible EsuEligibility = "Ineligible" + EsuEligibilityUnknown EsuEligibility = "Unknown" +) + +func PossibleValuesForEsuEligibility() []string { + return []string{ + string(EsuEligibilityEligible), + string(EsuEligibilityIneligible), + string(EsuEligibilityUnknown), + } +} + +func (s *EsuEligibility) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEsuEligibility(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEsuEligibility(input string) (*EsuEligibility, error) { + vals := map[string]EsuEligibility{ + "eligible": EsuEligibilityEligible, + "ineligible": EsuEligibilityIneligible, + "unknown": EsuEligibilityUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EsuEligibility(input) + return &out, nil +} + +type EsuKeyState string + +const ( + EsuKeyStateActive EsuKeyState = "Active" + EsuKeyStateInactive EsuKeyState = "Inactive" +) + +func PossibleValuesForEsuKeyState() []string { + return []string{ + string(EsuKeyStateActive), + string(EsuKeyStateInactive), + } +} + +func (s *EsuKeyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEsuKeyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEsuKeyState(input string) (*EsuKeyState, error) { + vals := map[string]EsuKeyState{ + "active": EsuKeyStateActive, + "inactive": EsuKeyStateInactive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EsuKeyState(input) + return &out, nil +} + +type EsuServerType string + +const ( + EsuServerTypeDatacenter EsuServerType = "Datacenter" + EsuServerTypeStandard EsuServerType = "Standard" +) + +func PossibleValuesForEsuServerType() []string { + return []string{ + string(EsuServerTypeDatacenter), + string(EsuServerTypeStandard), + } +} + +func (s *EsuServerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEsuServerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEsuServerType(input string) (*EsuServerType, error) { + vals := map[string]EsuServerType{ + "datacenter": EsuServerTypeDatacenter, + "standard": EsuServerTypeStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EsuServerType(input) + return &out, nil +} + +type HotpatchEnablementStatus string + +const ( + HotpatchEnablementStatusActionRequired HotpatchEnablementStatus = "ActionRequired" + HotpatchEnablementStatusDisabled HotpatchEnablementStatus = "Disabled" + HotpatchEnablementStatusEnabled HotpatchEnablementStatus = "Enabled" + HotpatchEnablementStatusPendingEvaluation HotpatchEnablementStatus = "PendingEvaluation" + HotpatchEnablementStatusUnknown HotpatchEnablementStatus = "Unknown" +) + +func PossibleValuesForHotpatchEnablementStatus() []string { + return []string{ + string(HotpatchEnablementStatusActionRequired), + string(HotpatchEnablementStatusDisabled), + string(HotpatchEnablementStatusEnabled), + string(HotpatchEnablementStatusPendingEvaluation), + string(HotpatchEnablementStatusUnknown), + } +} + +func (s *HotpatchEnablementStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHotpatchEnablementStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHotpatchEnablementStatus(input string) (*HotpatchEnablementStatus, error) { + vals := map[string]HotpatchEnablementStatus{ + "actionrequired": HotpatchEnablementStatusActionRequired, + "disabled": HotpatchEnablementStatusDisabled, + "enabled": HotpatchEnablementStatusEnabled, + "pendingevaluation": HotpatchEnablementStatusPendingEvaluation, + "unknown": HotpatchEnablementStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HotpatchEnablementStatus(input) + return &out, nil +} + +type IdentityKeyStore string + +const ( + IdentityKeyStoreDefault IdentityKeyStore = "Default" + IdentityKeyStoreTPM IdentityKeyStore = "TPM" +) + +func PossibleValuesForIdentityKeyStore() []string { + return []string{ + string(IdentityKeyStoreDefault), + string(IdentityKeyStoreTPM), + } +} + +func (s *IdentityKeyStore) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentityKeyStore(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentityKeyStore(input string) (*IdentityKeyStore, error) { + vals := map[string]IdentityKeyStore{ + "default": IdentityKeyStoreDefault, + "tpm": IdentityKeyStoreTPM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityKeyStore(input) + return &out, nil +} + +type InstanceViewTypes string + +const ( + InstanceViewTypesInstanceView InstanceViewTypes = "instanceView" +) + +func PossibleValuesForInstanceViewTypes() []string { + return []string{ + string(InstanceViewTypesInstanceView), + } +} + +func (s *InstanceViewTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInstanceViewTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInstanceViewTypes(input string) (*InstanceViewTypes, error) { + vals := map[string]InstanceViewTypes{ + "instanceview": InstanceViewTypesInstanceView, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InstanceViewTypes(input) + return &out, nil +} + +type LastAttemptStatusEnum string + +const ( + LastAttemptStatusEnumFailed LastAttemptStatusEnum = "Failed" + LastAttemptStatusEnumSuccess LastAttemptStatusEnum = "Success" +) + +func PossibleValuesForLastAttemptStatusEnum() []string { + return []string{ + string(LastAttemptStatusEnumFailed), + string(LastAttemptStatusEnumSuccess), + } +} + +func (s *LastAttemptStatusEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLastAttemptStatusEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLastAttemptStatusEnum(input string) (*LastAttemptStatusEnum, error) { + vals := map[string]LastAttemptStatusEnum{ + "failed": LastAttemptStatusEnumFailed, + "success": LastAttemptStatusEnumSuccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LastAttemptStatusEnum(input) + return &out, nil +} + +type LicenseAssignmentState string + +const ( + LicenseAssignmentStateAssigned LicenseAssignmentState = "Assigned" + LicenseAssignmentStateNotAssigned LicenseAssignmentState = "NotAssigned" +) + +func PossibleValuesForLicenseAssignmentState() []string { + return []string{ + string(LicenseAssignmentStateAssigned), + string(LicenseAssignmentStateNotAssigned), + } +} + +func (s *LicenseAssignmentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseAssignmentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseAssignmentState(input string) (*LicenseAssignmentState, error) { + vals := map[string]LicenseAssignmentState{ + "assigned": LicenseAssignmentStateAssigned, + "notassigned": LicenseAssignmentStateNotAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseAssignmentState(input) + return &out, nil +} + +type LicenseCoreType string + +const ( + LicenseCoreTypePCore LicenseCoreType = "pCore" + LicenseCoreTypeVCore LicenseCoreType = "vCore" +) + +func PossibleValuesForLicenseCoreType() []string { + return []string{ + string(LicenseCoreTypePCore), + string(LicenseCoreTypeVCore), + } +} + +func (s *LicenseCoreType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseCoreType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseCoreType(input string) (*LicenseCoreType, error) { + vals := map[string]LicenseCoreType{ + "pcore": LicenseCoreTypePCore, + "vcore": LicenseCoreTypeVCore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseCoreType(input) + return &out, nil +} + +type LicenseEdition string + +const ( + LicenseEditionDatacenter LicenseEdition = "Datacenter" + LicenseEditionStandard LicenseEdition = "Standard" +) + +func PossibleValuesForLicenseEdition() []string { + return []string{ + string(LicenseEditionDatacenter), + string(LicenseEditionStandard), + } +} + +func (s *LicenseEdition) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseEdition(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseEdition(input string) (*LicenseEdition, error) { + vals := map[string]LicenseEdition{ + "datacenter": LicenseEditionDatacenter, + "standard": LicenseEditionStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseEdition(input) + return &out, nil +} + +type LicenseProfileProductType string + +const ( + LicenseProfileProductTypeWindowsIoTEnterprise LicenseProfileProductType = "WindowsIoTEnterprise" + LicenseProfileProductTypeWindowsServer LicenseProfileProductType = "WindowsServer" +) + +func PossibleValuesForLicenseProfileProductType() []string { + return []string{ + string(LicenseProfileProductTypeWindowsIoTEnterprise), + string(LicenseProfileProductTypeWindowsServer), + } +} + +func (s *LicenseProfileProductType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseProfileProductType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseProfileProductType(input string) (*LicenseProfileProductType, error) { + vals := map[string]LicenseProfileProductType{ + "windowsiotenterprise": LicenseProfileProductTypeWindowsIoTEnterprise, + "windowsserver": LicenseProfileProductTypeWindowsServer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseProfileProductType(input) + return &out, nil +} + +type LicenseProfileSubscriptionStatus string + +const ( + LicenseProfileSubscriptionStatusDisabled LicenseProfileSubscriptionStatus = "Disabled" + LicenseProfileSubscriptionStatusDisabling LicenseProfileSubscriptionStatus = "Disabling" + LicenseProfileSubscriptionStatusEnabled LicenseProfileSubscriptionStatus = "Enabled" + LicenseProfileSubscriptionStatusEnabling LicenseProfileSubscriptionStatus = "Enabling" + LicenseProfileSubscriptionStatusFailed LicenseProfileSubscriptionStatus = "Failed" + LicenseProfileSubscriptionStatusUnknown LicenseProfileSubscriptionStatus = "Unknown" +) + +func PossibleValuesForLicenseProfileSubscriptionStatus() []string { + return []string{ + string(LicenseProfileSubscriptionStatusDisabled), + string(LicenseProfileSubscriptionStatusDisabling), + string(LicenseProfileSubscriptionStatusEnabled), + string(LicenseProfileSubscriptionStatusEnabling), + string(LicenseProfileSubscriptionStatusFailed), + string(LicenseProfileSubscriptionStatusUnknown), + } +} + +func (s *LicenseProfileSubscriptionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseProfileSubscriptionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseProfileSubscriptionStatus(input string) (*LicenseProfileSubscriptionStatus, error) { + vals := map[string]LicenseProfileSubscriptionStatus{ + "disabled": LicenseProfileSubscriptionStatusDisabled, + "disabling": LicenseProfileSubscriptionStatusDisabling, + "enabled": LicenseProfileSubscriptionStatusEnabled, + "enabling": LicenseProfileSubscriptionStatusEnabling, + "failed": LicenseProfileSubscriptionStatusFailed, + "unknown": LicenseProfileSubscriptionStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseProfileSubscriptionStatus(input) + return &out, nil +} + +type LicenseState string + +const ( + LicenseStateActivated LicenseState = "Activated" + LicenseStateDeactivated LicenseState = "Deactivated" +) + +func PossibleValuesForLicenseState() []string { + return []string{ + string(LicenseStateActivated), + string(LicenseStateDeactivated), + } +} + +func (s *LicenseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseState(input string) (*LicenseState, error) { + vals := map[string]LicenseState{ + "activated": LicenseStateActivated, + "deactivated": LicenseStateDeactivated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseState(input) + return &out, nil +} + +type LicenseStatus string + +const ( + LicenseStatusExtendedGrace LicenseStatus = "ExtendedGrace" + LicenseStatusLicensed LicenseStatus = "Licensed" + LicenseStatusNonGenuineGrace LicenseStatus = "NonGenuineGrace" + LicenseStatusNotification LicenseStatus = "Notification" + LicenseStatusOOBGrace LicenseStatus = "OOBGrace" + LicenseStatusOOTGrace LicenseStatus = "OOTGrace" + LicenseStatusUnlicensed LicenseStatus = "Unlicensed" +) + +func PossibleValuesForLicenseStatus() []string { + return []string{ + string(LicenseStatusExtendedGrace), + string(LicenseStatusLicensed), + string(LicenseStatusNonGenuineGrace), + string(LicenseStatusNotification), + string(LicenseStatusOOBGrace), + string(LicenseStatusOOTGrace), + string(LicenseStatusUnlicensed), + } +} + +func (s *LicenseStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseStatus(input string) (*LicenseStatus, error) { + vals := map[string]LicenseStatus{ + "extendedgrace": LicenseStatusExtendedGrace, + "licensed": LicenseStatusLicensed, + "nongenuinegrace": LicenseStatusNonGenuineGrace, + "notification": LicenseStatusNotification, + "oobgrace": LicenseStatusOOBGrace, + "ootgrace": LicenseStatusOOTGrace, + "unlicensed": LicenseStatusUnlicensed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseStatus(input) + return &out, nil +} + +type LicenseTarget string + +const ( + LicenseTargetWindowsServerTwoZeroOneTwo LicenseTarget = "Windows Server 2012" + LicenseTargetWindowsServerTwoZeroOneTwoRTwo LicenseTarget = "Windows Server 2012 R2" +) + +func PossibleValuesForLicenseTarget() []string { + return []string{ + string(LicenseTargetWindowsServerTwoZeroOneTwo), + string(LicenseTargetWindowsServerTwoZeroOneTwoRTwo), + } +} + +func (s *LicenseTarget) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseTarget(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseTarget(input string) (*LicenseTarget, error) { + vals := map[string]LicenseTarget{ + "windows server 2012": LicenseTargetWindowsServerTwoZeroOneTwo, + "windows server 2012 r2": LicenseTargetWindowsServerTwoZeroOneTwoRTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseTarget(input) + return &out, nil +} + +type LicenseType string + +const ( + LicenseTypeESU LicenseType = "ESU" +) + +func PossibleValuesForLicenseType() []string { + return []string{ + string(LicenseTypeESU), + } +} + +func (s *LicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseType(input string) (*LicenseType, error) { + vals := map[string]LicenseType{ + "esu": LicenseTypeESU, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseType(input) + return &out, nil +} + +type OsType string + +const ( + OsTypeLinux OsType = "Linux" + OsTypeWindows OsType = "Windows" +) + +func PossibleValuesForOsType() []string { + return []string{ + string(OsTypeLinux), + string(OsTypeWindows), + } +} + +func (s *OsType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOsType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOsType(input string) (*OsType, error) { + vals := map[string]OsType{ + "linux": OsTypeLinux, + "windows": OsTypeWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OsType(input) + return &out, nil +} + +type PatchModeTypes string + +const ( + PatchModeTypesAutomaticByOS PatchModeTypes = "AutomaticByOS" + PatchModeTypesAutomaticByPlatform PatchModeTypes = "AutomaticByPlatform" + PatchModeTypesImageDefault PatchModeTypes = "ImageDefault" + PatchModeTypesManual PatchModeTypes = "Manual" +) + +func PossibleValuesForPatchModeTypes() []string { + return []string{ + string(PatchModeTypesAutomaticByOS), + string(PatchModeTypesAutomaticByPlatform), + string(PatchModeTypesImageDefault), + string(PatchModeTypesManual), + } +} + +func (s *PatchModeTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePatchModeTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePatchModeTypes(input string) (*PatchModeTypes, error) { + vals := map[string]PatchModeTypes{ + "automaticbyos": PatchModeTypesAutomaticByOS, + "automaticbyplatform": PatchModeTypesAutomaticByPlatform, + "imagedefault": PatchModeTypesImageDefault, + "manual": PatchModeTypesManual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PatchModeTypes(input) + return &out, nil +} + +type PatchOperationStartedBy string + +const ( + PatchOperationStartedByPlatform PatchOperationStartedBy = "Platform" + PatchOperationStartedByUser PatchOperationStartedBy = "User" +) + +func PossibleValuesForPatchOperationStartedBy() []string { + return []string{ + string(PatchOperationStartedByPlatform), + string(PatchOperationStartedByUser), + } +} + +func (s *PatchOperationStartedBy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePatchOperationStartedBy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePatchOperationStartedBy(input string) (*PatchOperationStartedBy, error) { + vals := map[string]PatchOperationStartedBy{ + "platform": PatchOperationStartedByPlatform, + "user": PatchOperationStartedByUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PatchOperationStartedBy(input) + return &out, nil +} + +type PatchOperationStatus string + +const ( + PatchOperationStatusCompletedWithWarnings PatchOperationStatus = "CompletedWithWarnings" + PatchOperationStatusFailed PatchOperationStatus = "Failed" + PatchOperationStatusInProgress PatchOperationStatus = "InProgress" + PatchOperationStatusSucceeded PatchOperationStatus = "Succeeded" + PatchOperationStatusUnknown PatchOperationStatus = "Unknown" +) + +func PossibleValuesForPatchOperationStatus() []string { + return []string{ + string(PatchOperationStatusCompletedWithWarnings), + string(PatchOperationStatusFailed), + string(PatchOperationStatusInProgress), + string(PatchOperationStatusSucceeded), + string(PatchOperationStatusUnknown), + } +} + +func (s *PatchOperationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePatchOperationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePatchOperationStatus(input string) (*PatchOperationStatus, error) { + vals := map[string]PatchOperationStatus{ + "completedwithwarnings": PatchOperationStatusCompletedWithWarnings, + "failed": PatchOperationStatusFailed, + "inprogress": PatchOperationStatusInProgress, + "succeeded": PatchOperationStatusSucceeded, + "unknown": PatchOperationStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PatchOperationStatus(input) + return &out, nil +} + +type PatchServiceUsed string + +const ( + PatchServiceUsedAPT PatchServiceUsed = "APT" + PatchServiceUsedUnknown PatchServiceUsed = "Unknown" + PatchServiceUsedWU PatchServiceUsed = "WU" + PatchServiceUsedWUWSUS PatchServiceUsed = "WU_WSUS" + PatchServiceUsedYUM PatchServiceUsed = "YUM" + PatchServiceUsedZypper PatchServiceUsed = "Zypper" +) + +func PossibleValuesForPatchServiceUsed() []string { + return []string{ + string(PatchServiceUsedAPT), + string(PatchServiceUsedUnknown), + string(PatchServiceUsedWU), + string(PatchServiceUsedWUWSUS), + string(PatchServiceUsedYUM), + string(PatchServiceUsedZypper), + } +} + +func (s *PatchServiceUsed) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePatchServiceUsed(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePatchServiceUsed(input string) (*PatchServiceUsed, error) { + vals := map[string]PatchServiceUsed{ + "apt": PatchServiceUsedAPT, + "unknown": PatchServiceUsedUnknown, + "wu": PatchServiceUsedWU, + "wu_wsus": PatchServiceUsedWUWSUS, + "yum": PatchServiceUsedYUM, + "zypper": PatchServiceUsedZypper, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PatchServiceUsed(input) + return &out, nil +} + +type ProgramYear string + +const ( + ProgramYearYearOne ProgramYear = "Year 1" + ProgramYearYearThree ProgramYear = "Year 3" + ProgramYearYearTwo ProgramYear = "Year 2" +) + +func PossibleValuesForProgramYear() []string { + return []string{ + string(ProgramYearYearOne), + string(ProgramYearYearThree), + string(ProgramYearYearTwo), + } +} + +func (s *ProgramYear) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProgramYear(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProgramYear(input string) (*ProgramYear, error) { + vals := map[string]ProgramYear{ + "year 1": ProgramYearYearOne, + "year 3": ProgramYearYearThree, + "year 2": ProgramYearYearTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProgramYear(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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 +} + +type StatusTypes string + +const ( + StatusTypesConnected StatusTypes = "Connected" + StatusTypesDisconnected StatusTypes = "Disconnected" + StatusTypesError StatusTypes = "Error" +) + +func PossibleValuesForStatusTypes() []string { + return []string{ + string(StatusTypesConnected), + string(StatusTypesDisconnected), + string(StatusTypesError), + } +} + +func (s *StatusTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatusTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatusTypes(input string) (*StatusTypes, error) { + vals := map[string]StatusTypes{ + "connected": StatusTypesConnected, + "disconnected": StatusTypesDisconnected, + "error": StatusTypesError, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StatusTypes(input) + return &out, nil +} + +type VMGuestPatchClassificationLinux string + +const ( + VMGuestPatchClassificationLinuxCritical VMGuestPatchClassificationLinux = "Critical" + VMGuestPatchClassificationLinuxOther VMGuestPatchClassificationLinux = "Other" + VMGuestPatchClassificationLinuxSecurity VMGuestPatchClassificationLinux = "Security" +) + +func PossibleValuesForVMGuestPatchClassificationLinux() []string { + return []string{ + string(VMGuestPatchClassificationLinuxCritical), + string(VMGuestPatchClassificationLinuxOther), + string(VMGuestPatchClassificationLinuxSecurity), + } +} + +func (s *VMGuestPatchClassificationLinux) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVMGuestPatchClassificationLinux(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVMGuestPatchClassificationLinux(input string) (*VMGuestPatchClassificationLinux, error) { + vals := map[string]VMGuestPatchClassificationLinux{ + "critical": VMGuestPatchClassificationLinuxCritical, + "other": VMGuestPatchClassificationLinuxOther, + "security": VMGuestPatchClassificationLinuxSecurity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VMGuestPatchClassificationLinux(input) + return &out, nil +} + +type VMGuestPatchClassificationWindows string + +const ( + VMGuestPatchClassificationWindowsCritical VMGuestPatchClassificationWindows = "Critical" + VMGuestPatchClassificationWindowsDefinition VMGuestPatchClassificationWindows = "Definition" + VMGuestPatchClassificationWindowsFeaturePack VMGuestPatchClassificationWindows = "FeaturePack" + VMGuestPatchClassificationWindowsSecurity VMGuestPatchClassificationWindows = "Security" + VMGuestPatchClassificationWindowsServicePack VMGuestPatchClassificationWindows = "ServicePack" + VMGuestPatchClassificationWindowsTools VMGuestPatchClassificationWindows = "Tools" + VMGuestPatchClassificationWindowsUpdateRollUp VMGuestPatchClassificationWindows = "UpdateRollUp" + VMGuestPatchClassificationWindowsUpdates VMGuestPatchClassificationWindows = "Updates" +) + +func PossibleValuesForVMGuestPatchClassificationWindows() []string { + return []string{ + string(VMGuestPatchClassificationWindowsCritical), + string(VMGuestPatchClassificationWindowsDefinition), + string(VMGuestPatchClassificationWindowsFeaturePack), + string(VMGuestPatchClassificationWindowsSecurity), + string(VMGuestPatchClassificationWindowsServicePack), + string(VMGuestPatchClassificationWindowsTools), + string(VMGuestPatchClassificationWindowsUpdateRollUp), + string(VMGuestPatchClassificationWindowsUpdates), + } +} + +func (s *VMGuestPatchClassificationWindows) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVMGuestPatchClassificationWindows(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVMGuestPatchClassificationWindows(input string) (*VMGuestPatchClassificationWindows, error) { + vals := map[string]VMGuestPatchClassificationWindows{ + "critical": VMGuestPatchClassificationWindowsCritical, + "definition": VMGuestPatchClassificationWindowsDefinition, + "featurepack": VMGuestPatchClassificationWindowsFeaturePack, + "security": VMGuestPatchClassificationWindowsSecurity, + "servicepack": VMGuestPatchClassificationWindowsServicePack, + "tools": VMGuestPatchClassificationWindowsTools, + "updaterollup": VMGuestPatchClassificationWindowsUpdateRollUp, + "updates": VMGuestPatchClassificationWindowsUpdates, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VMGuestPatchClassificationWindows(input) + return &out, nil +} + +type VMGuestPatchRebootSetting string + +const ( + VMGuestPatchRebootSettingAlways VMGuestPatchRebootSetting = "Always" + VMGuestPatchRebootSettingIfRequired VMGuestPatchRebootSetting = "IfRequired" + VMGuestPatchRebootSettingNever VMGuestPatchRebootSetting = "Never" +) + +func PossibleValuesForVMGuestPatchRebootSetting() []string { + return []string{ + string(VMGuestPatchRebootSettingAlways), + string(VMGuestPatchRebootSettingIfRequired), + string(VMGuestPatchRebootSettingNever), + } +} + +func (s *VMGuestPatchRebootSetting) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVMGuestPatchRebootSetting(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVMGuestPatchRebootSetting(input string) (*VMGuestPatchRebootSetting, error) { + vals := map[string]VMGuestPatchRebootSetting{ + "always": VMGuestPatchRebootSettingAlways, + "ifrequired": VMGuestPatchRebootSettingIfRequired, + "never": VMGuestPatchRebootSettingNever, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VMGuestPatchRebootSetting(input) + return &out, nil +} + +type VMGuestPatchRebootStatus string + +const ( + VMGuestPatchRebootStatusCompleted VMGuestPatchRebootStatus = "Completed" + VMGuestPatchRebootStatusFailed VMGuestPatchRebootStatus = "Failed" + VMGuestPatchRebootStatusNotNeeded VMGuestPatchRebootStatus = "NotNeeded" + VMGuestPatchRebootStatusRequired VMGuestPatchRebootStatus = "Required" + VMGuestPatchRebootStatusStarted VMGuestPatchRebootStatus = "Started" + VMGuestPatchRebootStatusUnknown VMGuestPatchRebootStatus = "Unknown" +) + +func PossibleValuesForVMGuestPatchRebootStatus() []string { + return []string{ + string(VMGuestPatchRebootStatusCompleted), + string(VMGuestPatchRebootStatusFailed), + string(VMGuestPatchRebootStatusNotNeeded), + string(VMGuestPatchRebootStatusRequired), + string(VMGuestPatchRebootStatusStarted), + string(VMGuestPatchRebootStatusUnknown), + } +} + +func (s *VMGuestPatchRebootStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVMGuestPatchRebootStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVMGuestPatchRebootStatus(input string) (*VMGuestPatchRebootStatus, error) { + vals := map[string]VMGuestPatchRebootStatus{ + "completed": VMGuestPatchRebootStatusCompleted, + "failed": VMGuestPatchRebootStatusFailed, + "notneeded": VMGuestPatchRebootStatusNotNeeded, + "required": VMGuestPatchRebootStatusRequired, + "started": VMGuestPatchRebootStatusStarted, + "unknown": VMGuestPatchRebootStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VMGuestPatchRebootStatus(input) + return &out, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/id_machine.go b/resource-manager/hybridcompute/2025-01-13/machines/id_machine.go new file mode 100644 index 00000000000..fef3ed16223 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/id_machine.go @@ -0,0 +1,130 @@ +package machines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/machines/id_machine_test.go new file mode 100644 index 00000000000..beedf5b764a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/id_machine_test.go @@ -0,0 +1,282 @@ +package machines + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/machines/method_assesspatches.go b/resource-manager/hybridcompute/2025-01-13/machines/method_assesspatches.go new file mode 100644 index 00000000000..32f5337ff36 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_assesspatches.go @@ -0,0 +1,71 @@ +package machines + +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 AssessPatchesOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MachineAssessPatchesResult +} + +// AssessPatches ... +func (c MachinesClient) AssessPatches(ctx context.Context, id MachineId) (result AssessPatchesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/assessPatches", 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 +} + +// AssessPatchesThenPoll performs AssessPatches then polls until it's completed +func (c MachinesClient) AssessPatchesThenPoll(ctx context.Context, id MachineId) error { + result, err := c.AssessPatches(ctx, id) + if err != nil { + return fmt.Errorf("performing AssessPatches: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AssessPatches: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/machines/method_createorupdate.go new file mode 100644 index 00000000000..ae5be2f80e0 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_createorupdate.go @@ -0,0 +1,87 @@ +package machines + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Machine +} + +type CreateOrUpdateOperationOptions struct { + Expand *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// CreateOrUpdate ... +func (c MachinesClient) CreateOrUpdate(ctx context.Context, id MachineId, input Machine, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 Machine + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/method_delete.go b/resource-manager/hybridcompute/2025-01-13/machines/method_delete.go new file mode 100644 index 00000000000..7cf0fe925af --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_delete.go @@ -0,0 +1,70 @@ +package machines + +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 MachinesClient) Delete(ctx context.Context, id MachineId) (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 MachinesClient) DeleteThenPoll(ctx context.Context, id MachineId) 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/hybridcompute/2025-01-13/machines/method_get.go b/resource-manager/hybridcompute/2025-01-13/machines/method_get.go new file mode 100644 index 00000000000..dbba4fc2851 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_get.go @@ -0,0 +1,83 @@ +package machines + +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 *Machine +} + +type GetOperationOptions struct { + Expand *InstanceViewTypes +} + +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 MachinesClient) Get(ctx context.Context, id MachineId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 Machine + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/method_installpatches.go b/resource-manager/hybridcompute/2025-01-13/machines/method_installpatches.go new file mode 100644 index 00000000000..3067cf403a6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_installpatches.go @@ -0,0 +1,75 @@ +package machines + +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 InstallPatchesOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MachineInstallPatchesResult +} + +// InstallPatches ... +func (c MachinesClient) InstallPatches(ctx context.Context, id MachineId, input MachineInstallPatchesParameters) (result InstallPatchesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/installPatches", 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 +} + +// InstallPatchesThenPoll performs InstallPatches then polls until it's completed +func (c MachinesClient) InstallPatchesThenPoll(ctx context.Context, id MachineId, input MachineInstallPatchesParameters) error { + result, err := c.InstallPatches(ctx, id, input) + if err != nil { + return fmt.Errorf("performing InstallPatches: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after InstallPatches: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/method_listbyresourcegroup.go b/resource-manager/hybridcompute/2025-01-13/machines/method_listbyresourcegroup.go new file mode 100644 index 00000000000..e9302aa8875 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_listbyresourcegroup.go @@ -0,0 +1,135 @@ +package machines + +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 *[]Machine +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Machine +} + +type ListByResourceGroupOperationOptions struct { + Expand *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c MachinesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/machines", 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 *[]Machine `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 MachinesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, MachineOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MachinesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate MachineOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Machine, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/method_listbysubscription.go b/resource-manager/hybridcompute/2025-01-13/machines/method_listbysubscription.go new file mode 100644 index 00000000000..ea000d8d739 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_listbysubscription.go @@ -0,0 +1,106 @@ +package machines + +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 *[]Machine +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Machine +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c MachinesClient) 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, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/machines", 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 *[]Machine `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 MachinesClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, MachineOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MachinesClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate MachineOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Machine, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/method_update.go b/resource-manager/hybridcompute/2025-01-13/machines/method_update.go new file mode 100644 index 00000000000..2fe776738bf --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/method_update.go @@ -0,0 +1,57 @@ +package machines + +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 *Machine +} + +// Update ... +func (c MachinesClient) Update(ctx context.Context, id MachineId, input MachineUpdate) (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 Machine + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_agentconfiguration.go b/resource-manager/hybridcompute/2025-01-13/machines/model_agentconfiguration.go new file mode 100644 index 00000000000..78597915af9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_agentconfiguration.go @@ -0,0 +1,15 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentConfiguration struct { + ConfigMode *AgentConfigurationMode `json:"configMode,omitempty"` + ExtensionsAllowList *[]ConfigurationExtension `json:"extensionsAllowList,omitempty"` + ExtensionsBlockList *[]ConfigurationExtension `json:"extensionsBlockList,omitempty"` + ExtensionsEnabled *string `json:"extensionsEnabled,omitempty"` + GuestConfigurationEnabled *string `json:"guestConfigurationEnabled,omitempty"` + IncomingConnectionsPorts *[]string `json:"incomingConnectionsPorts,omitempty"` + ProxyBypass *[]string `json:"proxyBypass,omitempty"` + ProxyURL *string `json:"proxyUrl,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_agentupgrade.go b/resource-manager/hybridcompute/2025-01-13/machines/model_agentupgrade.go new file mode 100644 index 00000000000..a1bfbfc0472 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_agentupgrade.go @@ -0,0 +1,14 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgentUpgrade struct { + CorrelationId *string `json:"correlationId,omitempty"` + DesiredVersion *string `json:"desiredVersion,omitempty"` + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + LastAttemptDesiredVersion *string `json:"lastAttemptDesiredVersion,omitempty"` + LastAttemptMessage *string `json:"lastAttemptMessage,omitempty"` + LastAttemptStatus *LastAttemptStatusEnum `json:"lastAttemptStatus,omitempty"` + LastAttemptTimestamp *string `json:"lastAttemptTimestamp,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_availablepatchcountbyclassification.go b/resource-manager/hybridcompute/2025-01-13/machines/model_availablepatchcountbyclassification.go new file mode 100644 index 00000000000..1fd8afb4296 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_availablepatchcountbyclassification.go @@ -0,0 +1,16 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailablePatchCountByClassification struct { + Critical *int64 `json:"critical,omitempty"` + Definition *int64 `json:"definition,omitempty"` + FeaturePack *int64 `json:"featurePack,omitempty"` + Other *int64 `json:"other,omitempty"` + Security *int64 `json:"security,omitempty"` + ServicePack *int64 `json:"servicePack,omitempty"` + Tools *int64 `json:"tools,omitempty"` + UpdateRollup *int64 `json:"updateRollup,omitempty"` + Updates *int64 `json:"updates,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_cloudmetadata.go b/resource-manager/hybridcompute/2025-01-13/machines/model_cloudmetadata.go new file mode 100644 index 00000000000..292947aca13 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_cloudmetadata.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CloudMetadata struct { + Provider *string `json:"provider,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_configurationextension.go b/resource-manager/hybridcompute/2025-01-13/machines/model_configurationextension.go new file mode 100644 index 00000000000..a15e10a01a8 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_configurationextension.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationExtension struct { + Publisher *string `json:"publisher,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_disk.go b/resource-manager/hybridcompute/2025-01-13/machines/model_disk.go new file mode 100644 index 00000000000..ff14e854e39 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_disk.go @@ -0,0 +1,14 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Disk struct { + DiskType *string `json:"diskType,omitempty"` + GeneratedId *string `json:"generatedId,omitempty"` + Id *string `json:"id,omitempty"` + MaxSizeInBytes *int64 `json:"maxSizeInBytes,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + UsedSpaceInBytes *int64 `json:"usedSpaceInBytes,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_erroradditionalinfo.go b/resource-manager/hybridcompute/2025-01-13/machines/model_erroradditionalinfo.go new file mode 100644 index 00000000000..b43823d85d2 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_errordetail.go b/resource-manager/hybridcompute/2025-01-13/machines/model_errordetail.go new file mode 100644 index 00000000000..a76af384f03 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_errordetail.go @@ -0,0 +1,12 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorDetail `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_esukey.go b/resource-manager/hybridcompute/2025-01-13/machines/model_esukey.go new file mode 100644 index 00000000000..3d63017b02e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_esukey.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EsuKey struct { + LicenseStatus *int64 `json:"licenseStatus,omitempty"` + Sku *string `json:"sku,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_firmwareprofile.go b/resource-manager/hybridcompute/2025-01-13/machines/model_firmwareprofile.go new file mode 100644 index 00000000000..79dba5bcdc8 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_firmwareprofile.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirmwareProfile struct { + SerialNumber *string `json:"serialNumber,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_hardwareprofile.go b/resource-manager/hybridcompute/2025-01-13/machines/model_hardwareprofile.go new file mode 100644 index 00000000000..15a8c1acc79 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_hardwareprofile.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HardwareProfile struct { + NumberOfCPUSockets *int64 `json:"numberOfCpuSockets,omitempty"` + Processors *[]Processor `json:"processors,omitempty"` + TotalPhysicalMemoryInBytes *int64 `json:"totalPhysicalMemoryInBytes,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_ipaddress.go b/resource-manager/hybridcompute/2025-01-13/machines/model_ipaddress.go new file mode 100644 index 00000000000..db2622c5f01 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_ipaddress.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPAddress struct { + Address *string `json:"address,omitempty"` + IPAddressVersion *string `json:"ipAddressVersion,omitempty"` + Subnet *Subnet `json:"subnet,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_license.go b/resource-manager/hybridcompute/2025-01-13/machines/model_license.go new file mode 100644 index 00000000000..cbfd8cf6a09 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_license.go @@ -0,0 +1,18 @@ +package machines + +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 License struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *LicenseProperties `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/hybridcompute/2025-01-13/machines/model_licensedetails.go b/resource-manager/hybridcompute/2025-01-13/machines/model_licensedetails.go new file mode 100644 index 00000000000..7cb71673ece --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_licensedetails.go @@ -0,0 +1,15 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseDetails struct { + AssignedLicenses *int64 `json:"assignedLicenses,omitempty"` + Edition *LicenseEdition `json:"edition,omitempty"` + ImmutableId *string `json:"immutableId,omitempty"` + Processors *int64 `json:"processors,omitempty"` + State *LicenseState `json:"state,omitempty"` + Target *LicenseTarget `json:"target,omitempty"` + Type *LicenseCoreType `json:"type,omitempty"` + VolumeLicenseDetails *[]VolumeLicenseDetails `json:"volumeLicenseDetails,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilearmproductprofileproperties.go b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilearmproductprofileproperties.go new file mode 100644 index 00000000000..8aff278a4dd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilearmproductprofileproperties.go @@ -0,0 +1,69 @@ +package machines + +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 LicenseProfileArmProductProfileProperties struct { + BillingEndDate *string `json:"billingEndDate,omitempty"` + BillingStartDate *string `json:"billingStartDate,omitempty"` + DisenrollmentDate *string `json:"disenrollmentDate,omitempty"` + EnrollmentDate *string `json:"enrollmentDate,omitempty"` + Error *ErrorDetail `json:"error,omitempty"` + ProductFeatures *[]ProductFeature `json:"productFeatures,omitempty"` + ProductType *LicenseProfileProductType `json:"productType,omitempty"` + SubscriptionStatus *LicenseProfileSubscriptionStatus `json:"subscriptionStatus,omitempty"` +} + +func (o *LicenseProfileArmProductProfileProperties) GetBillingEndDateAsTime() (*time.Time, error) { + if o.BillingEndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingEndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetBillingEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingEndDate = &formatted +} + +func (o *LicenseProfileArmProductProfileProperties) GetBillingStartDateAsTime() (*time.Time, error) { + if o.BillingStartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingStartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetBillingStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingStartDate = &formatted +} + +func (o *LicenseProfileArmProductProfileProperties) GetDisenrollmentDateAsTime() (*time.Time, error) { + if o.DisenrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DisenrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetDisenrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DisenrollmentDate = &formatted +} + +func (o *LicenseProfileArmProductProfileProperties) GetEnrollmentDateAsTime() (*time.Time, error) { + if o.EnrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EnrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *LicenseProfileArmProductProfileProperties) SetEnrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EnrollmentDate = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceview.go b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceview.go new file mode 100644 index 00000000000..6f0e3dd86b6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceview.go @@ -0,0 +1,12 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileMachineInstanceView struct { + EsuProfile *LicenseProfileMachineInstanceViewEsuProperties `json:"esuProfile,omitempty"` + LicenseChannel *string `json:"licenseChannel,omitempty"` + LicenseStatus *LicenseStatus `json:"licenseStatus,omitempty"` + ProductProfile *LicenseProfileArmProductProfileProperties `json:"productProfile,omitempty"` + SoftwareAssurance *LicenseProfileMachineInstanceViewSoftwareAssurance `json:"softwareAssurance,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewesuproperties.go b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewesuproperties.go new file mode 100644 index 00000000000..0e72c18a65f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewesuproperties.go @@ -0,0 +1,14 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileMachineInstanceViewEsuProperties struct { + AssignedLicense *License `json:"assignedLicense,omitempty"` + AssignedLicenseImmutableId *string `json:"assignedLicenseImmutableId,omitempty"` + EsuEligibility *EsuEligibility `json:"esuEligibility,omitempty"` + EsuKeyState *EsuKeyState `json:"esuKeyState,omitempty"` + EsuKeys *[]EsuKey `json:"esuKeys,omitempty"` + LicenseAssignmentState *LicenseAssignmentState `json:"licenseAssignmentState,omitempty"` + ServerType *EsuServerType `json:"serverType,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewsoftwareassurance.go b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewsoftwareassurance.go new file mode 100644 index 00000000000..d3731e27270 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseprofilemachineinstanceviewsoftwareassurance.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProfileMachineInstanceViewSoftwareAssurance struct { + SoftwareAssuranceCustomer *bool `json:"softwareAssuranceCustomer,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_licenseproperties.go b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseproperties.go new file mode 100644 index 00000000000..b1435616000 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_licenseproperties.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseProperties struct { + LicenseDetails *LicenseDetails `json:"licenseDetails,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_linuxparameters.go b/resource-manager/hybridcompute/2025-01-13/machines/model_linuxparameters.go new file mode 100644 index 00000000000..c7157a3520a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_linuxparameters.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinuxParameters struct { + ClassificationsToInclude *[]VMGuestPatchClassificationLinux `json:"classificationsToInclude,omitempty"` + PackageNameMasksToExclude *[]string `json:"packageNameMasksToExclude,omitempty"` + PackageNameMasksToInclude *[]string `json:"packageNameMasksToInclude,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_locationdata.go b/resource-manager/hybridcompute/2025-01-13/machines/model_locationdata.go new file mode 100644 index 00000000000..5d8341e5cca --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_locationdata.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LocationData struct { + City *string `json:"city,omitempty"` + CountryOrRegion *string `json:"countryOrRegion,omitempty"` + District *string `json:"district,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machine.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machine.go new file mode 100644 index 00000000000..75aefb1394d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machine.go @@ -0,0 +1,22 @@ +package machines + +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 Machine struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *ArcKindEnum `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *MachineProperties `json:"properties,omitempty"` + Resources *[]MachineExtension `json:"resources,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineassesspatchesresult.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineassesspatchesresult.go new file mode 100644 index 00000000000..bb14fd812f7 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineassesspatchesresult.go @@ -0,0 +1,47 @@ +package machines + +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 MachineAssessPatchesResult struct { + AssessmentActivityId *string `json:"assessmentActivityId,omitempty"` + AvailablePatchCountByClassification *AvailablePatchCountByClassification `json:"availablePatchCountByClassification,omitempty"` + ErrorDetails *ErrorDetail `json:"errorDetails,omitempty"` + LastModifiedDateTime *string `json:"lastModifiedDateTime,omitempty"` + OsType *OsType `json:"osType,omitempty"` + PatchServiceUsed *PatchServiceUsed `json:"patchServiceUsed,omitempty"` + RebootPending *bool `json:"rebootPending,omitempty"` + StartDateTime *string `json:"startDateTime,omitempty"` + StartedBy *PatchOperationStartedBy `json:"startedBy,omitempty"` + Status *PatchOperationStatus `json:"status,omitempty"` +} + +func (o *MachineAssessPatchesResult) GetLastModifiedDateTimeAsTime() (*time.Time, error) { + if o.LastModifiedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineAssessPatchesResult) SetLastModifiedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDateTime = &formatted +} + +func (o *MachineAssessPatchesResult) GetStartDateTimeAsTime() (*time.Time, error) { + if o.StartDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineAssessPatchesResult) SetStartDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDateTime = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineextension.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextension.go new file mode 100644 index 00000000000..f611d3226db --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextension.go @@ -0,0 +1,18 @@ +package machines + +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 MachineExtension struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *MachineExtensionProperties `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/hybridcompute/2025-01-13/machines/model_machineextensioninstanceview.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceview.go new file mode 100644 index 00000000000..a1154818910 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceview.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionInstanceView struct { + Name *string `json:"name,omitempty"` + Status *MachineExtensionInstanceViewStatus `json:"status,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceviewstatus.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceviewstatus.go new file mode 100644 index 00000000000..42ea89ad402 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensioninstanceviewstatus.go @@ -0,0 +1,30 @@ +package machines + +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 MachineExtensionInstanceViewStatus 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 *MachineExtensionInstanceViewStatus) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineExtensionInstanceViewStatus) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensionproperties.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensionproperties.go new file mode 100644 index 00000000000..afad01914ce --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineextensionproperties.go @@ -0,0 +1,17 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineExtensionProperties struct { + AutoUpgradeMinorVersion *bool `json:"autoUpgradeMinorVersion,omitempty"` + EnableAutomaticUpgrade *bool `json:"enableAutomaticUpgrade,omitempty"` + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + InstanceView *MachineExtensionInstanceView `json:"instanceView,omitempty"` + ProtectedSettings *map[string]interface{} `json:"protectedSettings,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Settings *map[string]interface{} `json:"settings,omitempty"` + Type *string `json:"type,omitempty"` + TypeHandlerVersion *string `json:"typeHandlerVersion,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesparameters.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesparameters.go new file mode 100644 index 00000000000..6a62cd02c42 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesparameters.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineInstallPatchesParameters struct { + LinuxParameters *LinuxParameters `json:"linuxParameters,omitempty"` + MaximumDuration string `json:"maximumDuration"` + RebootSetting VMGuestPatchRebootSetting `json:"rebootSetting"` + WindowsParameters *WindowsParameters `json:"windowsParameters,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesresult.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesresult.go new file mode 100644 index 00000000000..42cddc9b234 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineinstallpatchesresult.go @@ -0,0 +1,52 @@ +package machines + +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 MachineInstallPatchesResult struct { + ErrorDetails *ErrorDetail `json:"errorDetails,omitempty"` + ExcludedPatchCount *int64 `json:"excludedPatchCount,omitempty"` + FailedPatchCount *int64 `json:"failedPatchCount,omitempty"` + InstallationActivityId *string `json:"installationActivityId,omitempty"` + InstalledPatchCount *int64 `json:"installedPatchCount,omitempty"` + LastModifiedDateTime *string `json:"lastModifiedDateTime,omitempty"` + MaintenanceWindowExceeded *bool `json:"maintenanceWindowExceeded,omitempty"` + NotSelectedPatchCount *int64 `json:"notSelectedPatchCount,omitempty"` + OsType *OsType `json:"osType,omitempty"` + PatchServiceUsed *PatchServiceUsed `json:"patchServiceUsed,omitempty"` + PendingPatchCount *int64 `json:"pendingPatchCount,omitempty"` + RebootStatus *VMGuestPatchRebootStatus `json:"rebootStatus,omitempty"` + StartDateTime *string `json:"startDateTime,omitempty"` + StartedBy *PatchOperationStartedBy `json:"startedBy,omitempty"` + Status *PatchOperationStatus `json:"status,omitempty"` +} + +func (o *MachineInstallPatchesResult) GetLastModifiedDateTimeAsTime() (*time.Time, error) { + if o.LastModifiedDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineInstallPatchesResult) SetLastModifiedDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDateTime = &formatted +} + +func (o *MachineInstallPatchesResult) GetStartDateTimeAsTime() (*time.Time, error) { + if o.StartDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineInstallPatchesResult) SetStartDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDateTime = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineproperties.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineproperties.go new file mode 100644 index 00000000000..1c970f86fb5 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineproperties.go @@ -0,0 +1,61 @@ +package machines + +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 MachineProperties struct { + AdFqdn *string `json:"adFqdn,omitempty"` + AgentConfiguration *AgentConfiguration `json:"agentConfiguration,omitempty"` + AgentUpgrade *AgentUpgrade `json:"agentUpgrade,omitempty"` + AgentVersion *string `json:"agentVersion,omitempty"` + ClientPublicKey *string `json:"clientPublicKey,omitempty"` + CloudMetadata *CloudMetadata `json:"cloudMetadata,omitempty"` + DetectedProperties *map[string]string `json:"detectedProperties,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DnsFqdn *string `json:"dnsFqdn,omitempty"` + DomainName *string `json:"domainName,omitempty"` + ErrorDetails *[]ErrorDetail `json:"errorDetails,omitempty"` + Extensions *[]MachineExtensionInstanceView `json:"extensions,omitempty"` + FirmwareProfile *FirmwareProfile `json:"firmwareProfile,omitempty"` + HardwareProfile *HardwareProfile `json:"hardwareProfile,omitempty"` + IdentityKeyStore *IdentityKeyStore `json:"identityKeyStore,omitempty"` + LastStatusChange *string `json:"lastStatusChange,omitempty"` + LicenseProfile *LicenseProfileMachineInstanceView `json:"licenseProfile,omitempty"` + LocationData *LocationData `json:"locationData,omitempty"` + MachineFqdn *string `json:"machineFqdn,omitempty"` + MssqlDiscovered *string `json:"mssqlDiscovered,omitempty"` + NetworkProfile *NetworkProfile `json:"networkProfile,omitempty"` + OsEdition *string `json:"osEdition,omitempty"` + OsName *string `json:"osName,omitempty"` + OsProfile *OSProfile `json:"osProfile,omitempty"` + OsSku *string `json:"osSku,omitempty"` + OsType *string `json:"osType,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` + ParentClusterResourceId *string `json:"parentClusterResourceId,omitempty"` + PrivateLinkScopeResourceId *string `json:"privateLinkScopeResourceId,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ServiceStatuses *ServiceStatuses `json:"serviceStatuses,omitempty"` + Status *StatusTypes `json:"status,omitempty"` + StorageProfile *StorageProfile `json:"storageProfile,omitempty"` + TpmEkCertificate *string `json:"tpmEkCertificate,omitempty"` + VMId *string `json:"vmId,omitempty"` + VMUuid *string `json:"vmUuid,omitempty"` +} + +func (o *MachineProperties) GetLastStatusChangeAsTime() (*time.Time, error) { + if o.LastStatusChange == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastStatusChange, "2006-01-02T15:04:05Z07:00") +} + +func (o *MachineProperties) SetLastStatusChangeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastStatusChange = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineupdate.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineupdate.go new file mode 100644 index 00000000000..52c94efdb46 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineupdate.go @@ -0,0 +1,15 @@ +package machines + +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 MachineUpdate struct { + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Kind *ArcKindEnum `json:"kind,omitempty"` + Properties *MachineUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_machineupdateproperties.go b/resource-manager/hybridcompute/2025-01-13/machines/model_machineupdateproperties.go new file mode 100644 index 00000000000..05f5fcf6188 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_machineupdateproperties.go @@ -0,0 +1,15 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineUpdateProperties struct { + AgentUpgrade *AgentUpgrade `json:"agentUpgrade,omitempty"` + CloudMetadata *CloudMetadata `json:"cloudMetadata,omitempty"` + IdentityKeyStore *string `json:"identityKeyStore,omitempty"` + LocationData *LocationData `json:"locationData,omitempty"` + OsProfile *OSProfile `json:"osProfile,omitempty"` + ParentClusterResourceId *string `json:"parentClusterResourceId,omitempty"` + PrivateLinkScopeResourceId *string `json:"privateLinkScopeResourceId,omitempty"` + TpmEkCertificate *string `json:"tpmEkCertificate,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_networkinterface.go b/resource-manager/hybridcompute/2025-01-13/machines/model_networkinterface.go new file mode 100644 index 00000000000..b29bb2c45ff --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_networkinterface.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkInterface struct { + IPAddresses *[]IPAddress `json:"ipAddresses,omitempty"` + Id *string `json:"id,omitempty"` + MacAddress *string `json:"macAddress,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_networkprofile.go b/resource-manager/hybridcompute/2025-01-13/machines/model_networkprofile.go new file mode 100644 index 00000000000..4f148708f71 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_networkprofile.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkProfile struct { + NetworkInterfaces *[]NetworkInterface `json:"networkInterfaces,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_osprofile.go b/resource-manager/hybridcompute/2025-01-13/machines/model_osprofile.go new file mode 100644 index 00000000000..997d70b8aec --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_osprofile.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSProfile struct { + ComputerName *string `json:"computerName,omitempty"` + LinuxConfiguration *OSProfileLinuxConfiguration `json:"linuxConfiguration,omitempty"` + WindowsConfiguration *OSProfileWindowsConfiguration `json:"windowsConfiguration,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_osprofilelinuxconfiguration.go b/resource-manager/hybridcompute/2025-01-13/machines/model_osprofilelinuxconfiguration.go new file mode 100644 index 00000000000..560fd9133db --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_osprofilelinuxconfiguration.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSProfileLinuxConfiguration struct { + PatchSettings *PatchSettings `json:"patchSettings,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_osprofilewindowsconfiguration.go b/resource-manager/hybridcompute/2025-01-13/machines/model_osprofilewindowsconfiguration.go new file mode 100644 index 00000000000..309f073367a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_osprofilewindowsconfiguration.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OSProfileWindowsConfiguration struct { + PatchSettings *PatchSettings `json:"patchSettings,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_patchsettings.go b/resource-manager/hybridcompute/2025-01-13/machines/model_patchsettings.go new file mode 100644 index 00000000000..f478cb4568c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_patchsettings.go @@ -0,0 +1,11 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSettings struct { + AssessmentMode *AssessmentModeTypes `json:"assessmentMode,omitempty"` + EnableHotpatching *bool `json:"enableHotpatching,omitempty"` + PatchMode *PatchModeTypes `json:"patchMode,omitempty"` + Status *PatchSettingsStatus `json:"status,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_patchsettingsstatus.go b/resource-manager/hybridcompute/2025-01-13/machines/model_patchsettingsstatus.go new file mode 100644 index 00000000000..08da481b526 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_patchsettingsstatus.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSettingsStatus struct { + Error *ErrorDetail `json:"error,omitempty"` + HotpatchEnablementStatus *HotpatchEnablementStatus `json:"hotpatchEnablementStatus,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_processor.go b/resource-manager/hybridcompute/2025-01-13/machines/model_processor.go new file mode 100644 index 00000000000..7f3561864df --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_processor.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Processor struct { + Name *string `json:"name,omitempty"` + NumberOfCores *int64 `json:"numberOfCores,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_productfeature.go b/resource-manager/hybridcompute/2025-01-13/machines/model_productfeature.go new file mode 100644 index 00000000000..9649881a6c8 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_productfeature.go @@ -0,0 +1,68 @@ +package machines + +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 ProductFeature struct { + BillingEndDate *string `json:"billingEndDate,omitempty"` + BillingStartDate *string `json:"billingStartDate,omitempty"` + DisenrollmentDate *string `json:"disenrollmentDate,omitempty"` + EnrollmentDate *string `json:"enrollmentDate,omitempty"` + Error *ErrorDetail `json:"error,omitempty"` + Name *string `json:"name,omitempty"` + SubscriptionStatus *LicenseProfileSubscriptionStatus `json:"subscriptionStatus,omitempty"` +} + +func (o *ProductFeature) GetBillingEndDateAsTime() (*time.Time, error) { + if o.BillingEndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingEndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetBillingEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingEndDate = &formatted +} + +func (o *ProductFeature) GetBillingStartDateAsTime() (*time.Time, error) { + if o.BillingStartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BillingStartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetBillingStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BillingStartDate = &formatted +} + +func (o *ProductFeature) GetDisenrollmentDateAsTime() (*time.Time, error) { + if o.DisenrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DisenrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetDisenrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DisenrollmentDate = &formatted +} + +func (o *ProductFeature) GetEnrollmentDateAsTime() (*time.Time, error) { + if o.EnrollmentDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EnrollmentDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProductFeature) SetEnrollmentDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EnrollmentDate = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_servicestatus.go b/resource-manager/hybridcompute/2025-01-13/machines/model_servicestatus.go new file mode 100644 index 00000000000..8cde424d92a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_servicestatus.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceStatus struct { + StartupType *string `json:"startupType,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_servicestatuses.go b/resource-manager/hybridcompute/2025-01-13/machines/model_servicestatuses.go new file mode 100644 index 00000000000..aff2a8351b0 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_servicestatuses.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceStatuses struct { + ExtensionService *ServiceStatus `json:"extensionService,omitempty"` + GuestConfigurationService *ServiceStatus `json:"guestConfigurationService,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_storageprofile.go b/resource-manager/hybridcompute/2025-01-13/machines/model_storageprofile.go new file mode 100644 index 00000000000..74af478374f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_storageprofile.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageProfile struct { + Disks *[]Disk `json:"disks,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_subnet.go b/resource-manager/hybridcompute/2025-01-13/machines/model_subnet.go new file mode 100644 index 00000000000..2ea3502fb34 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_subnet.go @@ -0,0 +1,8 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Subnet struct { + AddressPrefix *string `json:"addressPrefix,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_volumelicensedetails.go b/resource-manager/hybridcompute/2025-01-13/machines/model_volumelicensedetails.go new file mode 100644 index 00000000000..fc7ef541a07 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_volumelicensedetails.go @@ -0,0 +1,9 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VolumeLicenseDetails struct { + InvoiceId *string `json:"invoiceId,omitempty"` + ProgramYear *ProgramYear `json:"programYear,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/model_windowsparameters.go b/resource-manager/hybridcompute/2025-01-13/machines/model_windowsparameters.go new file mode 100644 index 00000000000..9ea4a31f314 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/model_windowsparameters.go @@ -0,0 +1,30 @@ +package machines + +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 WindowsParameters struct { + ClassificationsToInclude *[]VMGuestPatchClassificationWindows `json:"classificationsToInclude,omitempty"` + ExcludeKbsRequiringReboot *bool `json:"excludeKbsRequiringReboot,omitempty"` + KbNumbersToExclude *[]string `json:"kbNumbersToExclude,omitempty"` + KbNumbersToInclude *[]string `json:"kbNumbersToInclude,omitempty"` + MaxPatchPublishDate *string `json:"maxPatchPublishDate,omitempty"` +} + +func (o *WindowsParameters) GetMaxPatchPublishDateAsTime() (*time.Time, error) { + if o.MaxPatchPublishDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.MaxPatchPublishDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WindowsParameters) SetMaxPatchPublishDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.MaxPatchPublishDate = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/machines/predicates.go b/resource-manager/hybridcompute/2025-01-13/machines/predicates.go new file mode 100644 index 00000000000..0f0fa8b2454 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/predicates.go @@ -0,0 +1,32 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MachineOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p MachineOperationPredicate) Matches(input Machine) 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/hybridcompute/2025-01-13/machines/version.go b/resource-manager/hybridcompute/2025-01-13/machines/version.go new file mode 100644 index 00000000000..3334e798715 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/machines/version.go @@ -0,0 +1,10 @@ +package machines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/machines/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/README.md b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/README.md new file mode 100644 index 00000000000..dc0a2401443 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/README.md @@ -0,0 +1,78 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/networkconfigurations` Documentation + +The `networkconfigurations` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/networkconfigurations" +``` + + +### Client Initialization + +```go +client := networkconfigurations.NewNetworkConfigurationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NetworkConfigurationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := networkconfigurations.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := networkconfigurations.NetworkConfiguration{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NetworkConfigurationsClient.Get` + +```go +ctx := context.TODO() +id := networkconfigurations.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +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: `NetworkConfigurationsClient.Update` + +```go +ctx := context.TODO() +id := networkconfigurations.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +payload := networkconfigurations.NetworkConfiguration{ + // ... +} + + +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/hybridcompute/2025-01-13/networkconfigurations/client.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/client.go new file mode 100644 index 00000000000..0d5bd51d9e1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/client.go @@ -0,0 +1,26 @@ +package networkconfigurations + +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 NetworkConfigurationsClient struct { + Client *resourcemanager.Client +} + +func NewNetworkConfigurationsClientWithBaseURI(sdkApi sdkEnv.Api) (*NetworkConfigurationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "networkconfigurations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NetworkConfigurationsClient: %+v", err) + } + + return &NetworkConfigurationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine.go new file mode 100644 index 00000000000..7499c334143 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine.go @@ -0,0 +1,130 @@ +package networkconfigurations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine_test.go new file mode 100644 index 00000000000..29591dcb28a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/id_machine_test.go @@ -0,0 +1,282 @@ +package networkconfigurations + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/networkconfigurations/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_createorupdate.go new file mode 100644 index 00000000000..e8a30c82ee3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_createorupdate.go @@ -0,0 +1,59 @@ +package networkconfigurations + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NetworkConfiguration +} + +// CreateOrUpdate ... +func (c NetworkConfigurationsClient) CreateOrUpdate(ctx context.Context, id MachineId, input NetworkConfiguration) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/networkConfigurations/current", 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 NetworkConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_get.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_get.go new file mode 100644 index 00000000000..fc224fbc443 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_get.go @@ -0,0 +1,54 @@ +package networkconfigurations + +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 *NetworkConfiguration +} + +// Get ... +func (c NetworkConfigurationsClient) Get(ctx context.Context, id MachineId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/networkConfigurations/current", 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 NetworkConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_update.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_update.go new file mode 100644 index 00000000000..5e71ab516de --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/method_update.go @@ -0,0 +1,58 @@ +package networkconfigurations + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NetworkConfiguration +} + +// Update ... +func (c NetworkConfigurationsClient) Update(ctx context.Context, id MachineId, input NetworkConfiguration) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/networkConfigurations/current", 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 NetworkConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keydetails.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keydetails.go new file mode 100644 index 00000000000..583b8261f21 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keydetails.go @@ -0,0 +1,40 @@ +package networkconfigurations + +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 KeyDetails struct { + NotAfter *string `json:"notAfter,omitempty"` + PublicKey *string `json:"publicKey,omitempty"` + RenewAfter *string `json:"renewAfter,omitempty"` +} + +func (o *KeyDetails) GetNotAfterAsTime() (*time.Time, error) { + if o.NotAfter == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NotAfter, "2006-01-02T15:04:05Z07:00") +} + +func (o *KeyDetails) SetNotAfterAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NotAfter = &formatted +} + +func (o *KeyDetails) GetRenewAfterAsTime() (*time.Time, error) { + if o.RenewAfter == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RenewAfter, "2006-01-02T15:04:05Z07:00") +} + +func (o *KeyDetails) SetRenewAfterAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RenewAfter = &formatted +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keyproperties.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keyproperties.go new file mode 100644 index 00000000000..5ad0a69bb98 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_keyproperties.go @@ -0,0 +1,9 @@ +package networkconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyProperties struct { + CandidatePublicKey *KeyDetails `json:"candidatePublicKey,omitempty"` + ClientPublicKey *KeyDetails `json:"clientPublicKey,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfiguration.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfiguration.go new file mode 100644 index 00000000000..44838291f9d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfiguration.go @@ -0,0 +1,16 @@ +package networkconfigurations + +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 NetworkConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkConfigurationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfigurationproperties.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfigurationproperties.go new file mode 100644 index 00000000000..56511023722 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/model_networkconfigurationproperties.go @@ -0,0 +1,12 @@ +package networkconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkConfigurationProperties struct { + KeyProperties *KeyProperties `json:"keyProperties,omitempty"` + Location *string `json:"location,omitempty"` + NetworkConfigurationScopeId *string `json:"networkConfigurationScopeId,omitempty"` + NetworkConfigurationScopeResourceId *string `json:"networkConfigurationScopeResourceId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networkconfigurations/version.go b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/version.go new file mode 100644 index 00000000000..a2a5f0a924e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networkconfigurations/version.go @@ -0,0 +1,10 @@ +package networkconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/networkconfigurations/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/README.md b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/README.md new file mode 100644 index 00000000000..b1fecd994f6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/README.md @@ -0,0 +1,65 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration` Documentation + +The `networksecurityperimeterconfiguration` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/networksecurityperimeterconfiguration" +``` + + +### Client Initialization + +```go +client := networksecurityperimeterconfiguration.NewNetworkSecurityPerimeterConfigurationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NetworkSecurityPerimeterConfigurationClient.GetByPrivateLinkScope` + +```go +ctx := context.TODO() +id := networksecurityperimeterconfiguration.NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "networkSecurityPerimeterConfigurationName") + +read, err := client.GetByPrivateLinkScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NetworkSecurityPerimeterConfigurationClient.ListByPrivateLinkScope` + +```go +ctx := context.TODO() +id := networksecurityperimeterconfiguration.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +// alternatively `client.ListByPrivateLinkScope(ctx, id)` can be used to do batched pagination +items, err := client.ListByPrivateLinkScopeComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NetworkSecurityPerimeterConfigurationClient.ReconcileForPrivateLinkScope` + +```go +ctx := context.TODO() +id := networksecurityperimeterconfiguration.NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "networkSecurityPerimeterConfigurationName") + +if err := client.ReconcileForPrivateLinkScopeThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/client.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/client.go new file mode 100644 index 00000000000..022b3bda976 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/client.go @@ -0,0 +1,26 @@ +package networksecurityperimeterconfiguration + +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 NetworkSecurityPerimeterConfigurationClient struct { + Client *resourcemanager.Client +} + +func NewNetworkSecurityPerimeterConfigurationClientWithBaseURI(sdkApi sdkEnv.Api) (*NetworkSecurityPerimeterConfigurationClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "networksecurityperimeterconfiguration", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NetworkSecurityPerimeterConfigurationClient: %+v", err) + } + + return &NetworkSecurityPerimeterConfigurationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/constants.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/constants.go new file mode 100644 index 00000000000..27644b5afd3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/constants.go @@ -0,0 +1,183 @@ +package networksecurityperimeterconfiguration + +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 AccessMode string + +const ( + AccessModeAudit AccessMode = "audit" + AccessModeEnforced AccessMode = "enforced" + AccessModeLearning AccessMode = "learning" +) + +func PossibleValuesForAccessMode() []string { + return []string{ + string(AccessModeAudit), + string(AccessModeEnforced), + string(AccessModeLearning), + } +} + +func (s *AccessMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessMode(input string) (*AccessMode, error) { + vals := map[string]AccessMode{ + "audit": AccessModeAudit, + "enforced": AccessModeEnforced, + "learning": AccessModeLearning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessMode(input) + return &out, nil +} + +type AccessRuleDirection string + +const ( + AccessRuleDirectionInbound AccessRuleDirection = "Inbound" + AccessRuleDirectionOutbound AccessRuleDirection = "Outbound" +) + +func PossibleValuesForAccessRuleDirection() []string { + return []string{ + string(AccessRuleDirectionInbound), + string(AccessRuleDirectionOutbound), + } +} + +func (s *AccessRuleDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessRuleDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessRuleDirection(input string) (*AccessRuleDirection, error) { + vals := map[string]AccessRuleDirection{ + "inbound": AccessRuleDirectionInbound, + "outbound": AccessRuleDirectionOutbound, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessRuleDirection(input) + return &out, nil +} + +type ProvisioningIssueSeverity string + +const ( + ProvisioningIssueSeverityError ProvisioningIssueSeverity = "Error" + ProvisioningIssueSeverityWarning ProvisioningIssueSeverity = "Warning" +) + +func PossibleValuesForProvisioningIssueSeverity() []string { + return []string{ + string(ProvisioningIssueSeverityError), + string(ProvisioningIssueSeverityWarning), + } +} + +func (s *ProvisioningIssueSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningIssueSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningIssueSeverity(input string) (*ProvisioningIssueSeverity, error) { + vals := map[string]ProvisioningIssueSeverity{ + "error": ProvisioningIssueSeverityError, + "warning": ProvisioningIssueSeverityWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningIssueSeverity(input) + return &out, nil +} + +type ProvisioningIssueType string + +const ( + ProvisioningIssueTypeConfigurationPropagationFailure ProvisioningIssueType = "ConfigurationPropagationFailure" + ProvisioningIssueTypeMissingIdentityConfiguration ProvisioningIssueType = "MissingIdentityConfiguration" + ProvisioningIssueTypeMissingPerimeterConfiguration ProvisioningIssueType = "MissingPerimeterConfiguration" + ProvisioningIssueTypeOther ProvisioningIssueType = "Other" +) + +func PossibleValuesForProvisioningIssueType() []string { + return []string{ + string(ProvisioningIssueTypeConfigurationPropagationFailure), + string(ProvisioningIssueTypeMissingIdentityConfiguration), + string(ProvisioningIssueTypeMissingPerimeterConfiguration), + string(ProvisioningIssueTypeOther), + } +} + +func (s *ProvisioningIssueType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningIssueType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningIssueType(input string) (*ProvisioningIssueType, error) { + vals := map[string]ProvisioningIssueType{ + "configurationpropagationfailure": ProvisioningIssueTypeConfigurationPropagationFailure, + "missingidentityconfiguration": ProvisioningIssueTypeMissingIdentityConfiguration, + "missingperimeterconfiguration": ProvisioningIssueTypeMissingPerimeterConfiguration, + "other": ProvisioningIssueTypeOther, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningIssueType(input) + return &out, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..83f3c08f2f6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration.go @@ -0,0 +1,139 @@ +package networksecurityperimeterconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NetworkSecurityPerimeterConfigurationId{}) +} + +var _ resourceids.ResourceId = &NetworkSecurityPerimeterConfigurationId{} + +// NetworkSecurityPerimeterConfigurationId is a struct representing the Resource ID for a Network Security Perimeter Configuration +type NetworkSecurityPerimeterConfigurationId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string + NetworkSecurityPerimeterConfigurationName string +} + +// NewNetworkSecurityPerimeterConfigurationID returns a new NetworkSecurityPerimeterConfigurationId struct +func NewNetworkSecurityPerimeterConfigurationID(subscriptionId string, resourceGroupName string, privateLinkScopeName string, networkSecurityPerimeterConfigurationName string) NetworkSecurityPerimeterConfigurationId { + return NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + NetworkSecurityPerimeterConfigurationName: networkSecurityPerimeterConfigurationName, + } +} + +// ParseNetworkSecurityPerimeterConfigurationID parses 'input' into a NetworkSecurityPerimeterConfigurationId +func ParseNetworkSecurityPerimeterConfigurationID(input string) (*NetworkSecurityPerimeterConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkSecurityPerimeterConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkSecurityPerimeterConfigurationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNetworkSecurityPerimeterConfigurationIDInsensitively parses 'input' case-insensitively into a NetworkSecurityPerimeterConfigurationId +// note: this method should only be used for API response data and not user input +func ParseNetworkSecurityPerimeterConfigurationIDInsensitively(input string) (*NetworkSecurityPerimeterConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkSecurityPerimeterConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkSecurityPerimeterConfigurationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NetworkSecurityPerimeterConfigurationId) 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.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + if id.NetworkSecurityPerimeterConfigurationName, ok = input.Parsed["networkSecurityPerimeterConfigurationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "networkSecurityPerimeterConfigurationName", input) + } + + return nil +} + +// ValidateNetworkSecurityPerimeterConfigurationID checks that 'input' can be parsed as a Network Security Perimeter Configuration ID +func ValidateNetworkSecurityPerimeterConfigurationID(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 := ParseNetworkSecurityPerimeterConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Network Security Perimeter Configuration ID +func (id NetworkSecurityPerimeterConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s/networkSecurityPerimeterConfigurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName, id.NetworkSecurityPerimeterConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Network Security Perimeter Configuration ID +func (id NetworkSecurityPerimeterConfigurationId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + resourceids.StaticSegment("staticNetworkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations"), + resourceids.UserSpecifiedSegment("networkSecurityPerimeterConfigurationName", "networkSecurityPerimeterConfigurationName"), + } +} + +// String returns a human-readable description of this Network Security Perimeter Configuration ID +func (id NetworkSecurityPerimeterConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + fmt.Sprintf("Network Security Perimeter Configuration Name: %q", id.NetworkSecurityPerimeterConfigurationName), + } + return fmt.Sprintf("Network Security Perimeter Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration_test.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration_test.go new file mode 100644 index 00000000000..75c113e7a3e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_networksecurityperimeterconfiguration_test.go @@ -0,0 +1,327 @@ +package networksecurityperimeterconfiguration + +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 = &NetworkSecurityPerimeterConfigurationId{} + +func TestNewNetworkSecurityPerimeterConfigurationID(t *testing.T) { + id := NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "networkSecurityPerimeterConfigurationName") + + 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.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } + + if id.NetworkSecurityPerimeterConfigurationName != "networkSecurityPerimeterConfigurationName" { + t.Fatalf("Expected %q but got %q for Segment 'NetworkSecurityPerimeterConfigurationName'", id.NetworkSecurityPerimeterConfigurationName, "networkSecurityPerimeterConfigurationName") + } +} + +func TestFormatNetworkSecurityPerimeterConfigurationID(t *testing.T) { + actual := NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "networkSecurityPerimeterConfigurationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNetworkSecurityPerimeterConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkSecurityPerimeterConfigurationId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkSecurityPerimeterConfigurationID(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + if actual.NetworkSecurityPerimeterConfigurationName != v.Expected.NetworkSecurityPerimeterConfigurationName { + t.Fatalf("Expected %q but got %q for NetworkSecurityPerimeterConfigurationName", v.Expected.NetworkSecurityPerimeterConfigurationName, actual.NetworkSecurityPerimeterConfigurationName) + } + + } +} + +func TestParseNetworkSecurityPerimeterConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkSecurityPerimeterConfigurationId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnNaMe", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + NetworkSecurityPerimeterConfigurationName: "nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkSecurityPerimeterConfigurationIDInsensitively(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + if actual.NetworkSecurityPerimeterConfigurationName != v.Expected.NetworkSecurityPerimeterConfigurationName { + t.Fatalf("Expected %q but got %q for NetworkSecurityPerimeterConfigurationName", v.Expected.NetworkSecurityPerimeterConfigurationName, actual.NetworkSecurityPerimeterConfigurationName) + } + + } +} + +func TestSegmentsForNetworkSecurityPerimeterConfigurationId(t *testing.T) { + segments := NetworkSecurityPerimeterConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NetworkSecurityPerimeterConfigurationId 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/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope.go new file mode 100644 index 00000000000..3df939df2bd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope.go @@ -0,0 +1,130 @@ +package networksecurityperimeterconfiguration + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderPrivateLinkScopeId{}) +} + +var _ resourceids.ResourceId = &ProviderPrivateLinkScopeId{} + +// ProviderPrivateLinkScopeId is a struct representing the Resource ID for a Provider Private Link Scope +type ProviderPrivateLinkScopeId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string +} + +// NewProviderPrivateLinkScopeID returns a new ProviderPrivateLinkScopeId struct +func NewProviderPrivateLinkScopeID(subscriptionId string, resourceGroupName string, privateLinkScopeName string) ProviderPrivateLinkScopeId { + return ProviderPrivateLinkScopeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + } +} + +// ParseProviderPrivateLinkScopeID parses 'input' into a ProviderPrivateLinkScopeId +func ParseProviderPrivateLinkScopeID(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderPrivateLinkScopeIDInsensitively parses 'input' case-insensitively into a ProviderPrivateLinkScopeId +// note: this method should only be used for API response data and not user input +func ParseProviderPrivateLinkScopeIDInsensitively(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderPrivateLinkScopeId) 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.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + return nil +} + +// ValidateProviderPrivateLinkScopeID checks that 'input' can be parsed as a Provider Private Link Scope ID +func ValidateProviderPrivateLinkScopeID(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 := ParseProviderPrivateLinkScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + } +} + +// String returns a human-readable description of this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + } + return fmt.Sprintf("Provider Private Link Scope (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope_test.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope_test.go new file mode 100644 index 00000000000..28d08ae5ccf --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/id_providerprivatelinkscope_test.go @@ -0,0 +1,282 @@ +package networksecurityperimeterconfiguration + +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 = &ProviderPrivateLinkScopeId{} + +func TestNewProviderPrivateLinkScopeID(t *testing.T) { + id := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + + 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.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } +} + +func TestFormatProviderPrivateLinkScopeID(t *testing.T) { + actual := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderPrivateLinkScopeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeID(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestParseProviderPrivateLinkScopeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + }, + }, + { + // 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.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeIDInsensitively(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestSegmentsForProviderPrivateLinkScopeId(t *testing.T) { + segments := ProviderPrivateLinkScopeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderPrivateLinkScopeId 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/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_getbyprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_getbyprivatelinkscope.go new file mode 100644 index 00000000000..f2a48a71292 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_getbyprivatelinkscope.go @@ -0,0 +1,53 @@ +package networksecurityperimeterconfiguration + +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 GetByPrivateLinkScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *NetworkSecurityPerimeterConfiguration +} + +// GetByPrivateLinkScope ... +func (c NetworkSecurityPerimeterConfigurationClient) GetByPrivateLinkScope(ctx context.Context, id NetworkSecurityPerimeterConfigurationId) (result GetByPrivateLinkScopeOperationResponse, 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 NetworkSecurityPerimeterConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_listbyprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_listbyprivatelinkscope.go new file mode 100644 index 00000000000..8db33c08dcd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_listbyprivatelinkscope.go @@ -0,0 +1,105 @@ +package networksecurityperimeterconfiguration + +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 ListByPrivateLinkScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NetworkSecurityPerimeterConfiguration +} + +type ListByPrivateLinkScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []NetworkSecurityPerimeterConfiguration +} + +type ListByPrivateLinkScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByPrivateLinkScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByPrivateLinkScope ... +func (c NetworkSecurityPerimeterConfigurationClient) ListByPrivateLinkScope(ctx context.Context, id ProviderPrivateLinkScopeId) (result ListByPrivateLinkScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByPrivateLinkScopeCustomPager{}, + Path: fmt.Sprintf("%s/networkSecurityPerimeterConfigurations", 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 *[]NetworkSecurityPerimeterConfiguration `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPrivateLinkScopeComplete retrieves all the results into a single object +func (c NetworkSecurityPerimeterConfigurationClient) ListByPrivateLinkScopeComplete(ctx context.Context, id ProviderPrivateLinkScopeId) (ListByPrivateLinkScopeCompleteResult, error) { + return c.ListByPrivateLinkScopeCompleteMatchingPredicate(ctx, id, NetworkSecurityPerimeterConfigurationOperationPredicate{}) +} + +// ListByPrivateLinkScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NetworkSecurityPerimeterConfigurationClient) ListByPrivateLinkScopeCompleteMatchingPredicate(ctx context.Context, id ProviderPrivateLinkScopeId, predicate NetworkSecurityPerimeterConfigurationOperationPredicate) (result ListByPrivateLinkScopeCompleteResult, err error) { + items := make([]NetworkSecurityPerimeterConfiguration, 0) + + resp, err := c.ListByPrivateLinkScope(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByPrivateLinkScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_reconcileforprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_reconcileforprivatelinkscope.go new file mode 100644 index 00000000000..6d57bf1dc5a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/method_reconcileforprivatelinkscope.go @@ -0,0 +1,71 @@ +package networksecurityperimeterconfiguration + +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 ReconcileForPrivateLinkScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NetworkSecurityPerimeterConfigurationReconcileResult +} + +// ReconcileForPrivateLinkScope ... +func (c NetworkSecurityPerimeterConfigurationClient) ReconcileForPrivateLinkScope(ctx context.Context, id NetworkSecurityPerimeterConfigurationId) (result ReconcileForPrivateLinkScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/reconcile", 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 +} + +// ReconcileForPrivateLinkScopeThenPoll performs ReconcileForPrivateLinkScope then polls until it's completed +func (c NetworkSecurityPerimeterConfigurationClient) ReconcileForPrivateLinkScopeThenPoll(ctx context.Context, id NetworkSecurityPerimeterConfigurationId) error { + result, err := c.ReconcileForPrivateLinkScope(ctx, id) + if err != nil { + return fmt.Errorf("performing ReconcileForPrivateLinkScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ReconcileForPrivateLinkScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessrule.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessrule.go new file mode 100644 index 00000000000..4c74aaef833 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessrule.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessRule struct { + Name *string `json:"name,omitempty"` + Properties *AccessRuleProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessruleproperties.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessruleproperties.go new file mode 100644 index 00000000000..11e1c58bc9c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_accessruleproperties.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessRuleProperties struct { + AddressPrefixes *[]string `json:"addressPrefixes,omitempty"` + Direction *AccessRuleDirection `json:"direction,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeter.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeter.go new file mode 100644 index 00000000000..bcd83d98c35 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeter.go @@ -0,0 +1,10 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeter struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + PerimeterGuid *string `json:"perimeterGuid,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfiguration.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..05100bc8f9c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfiguration.go @@ -0,0 +1,11 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkSecurityPerimeterConfigurationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationproperties.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationproperties.go new file mode 100644 index 00000000000..838e3eaf619 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationproperties.go @@ -0,0 +1,12 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationProperties struct { + NetworkSecurityPerimeter *NetworkSecurityPerimeter `json:"networkSecurityPerimeter,omitempty"` + Profile *NetworkSecurityPerimeterProfile `json:"profile,omitempty"` + ProvisioningIssues *[]ProvisioningIssue `json:"provisioningIssues,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceAssociation *ResourceAssociation `json:"resourceAssociation,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationreconcileresult.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationreconcileresult.go new file mode 100644 index 00000000000..46acceae074 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterconfigurationreconcileresult.go @@ -0,0 +1,8 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationReconcileResult struct { + Location *string `json:"location,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterprofile.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterprofile.go new file mode 100644 index 00000000000..2061ccf6fff --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_networksecurityperimeterprofile.go @@ -0,0 +1,12 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterProfile struct { + AccessRules *[]AccessRule `json:"accessRules,omitempty"` + AccessRulesVersion *int64 `json:"accessRulesVersion,omitempty"` + DiagnosticSettingsVersion *int64 `json:"diagnosticSettingsVersion,omitempty"` + EnabledLogCategories *[]string `json:"enabledLogCategories,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissue.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissue.go new file mode 100644 index 00000000000..146309f0904 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissue.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningIssue struct { + Name *string `json:"name,omitempty"` + Properties *ProvisioningIssueProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissueproperties.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissueproperties.go new file mode 100644 index 00000000000..c297d302bf9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_provisioningissueproperties.go @@ -0,0 +1,12 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningIssueProperties struct { + Description *string `json:"description,omitempty"` + IssueType *ProvisioningIssueType `json:"issueType,omitempty"` + Severity *ProvisioningIssueSeverity `json:"severity,omitempty"` + SuggestedAccessRules *[]AccessRule `json:"suggestedAccessRules,omitempty"` + SuggestedResourceIds *[]string `json:"suggestedResourceIds,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_resourceassociation.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_resourceassociation.go new file mode 100644 index 00000000000..15547885eca --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/model_resourceassociation.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceAssociation struct { + AccessMode *AccessMode `json:"accessMode,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/predicates.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/predicates.go new file mode 100644 index 00000000000..37fd5b68579 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/predicates.go @@ -0,0 +1,27 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p NetworkSecurityPerimeterConfigurationOperationPredicate) Matches(input NetworkSecurityPerimeterConfiguration) 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/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/version.go b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/version.go new file mode 100644 index 00000000000..8d435472b8e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/networksecurityperimeterconfiguration/version.go @@ -0,0 +1,10 @@ +package networksecurityperimeterconfiguration + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/networksecurityperimeterconfiguration/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/README.md b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/README.md new file mode 100644 index 00000000000..829a1bcf3cb --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.ListByPrivateLinkScope` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +// alternatively `client.ListByPrivateLinkScope(ctx, id)` can be used to do batched pagination +items, err := client.ListByPrivateLinkScopeComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/client.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..48f7cbc1068 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, privateLinkScopeName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..25064b5ca1e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope.go new file mode 100644 index 00000000000..e65e13354bc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderPrivateLinkScopeId{}) +} + +var _ resourceids.ResourceId = &ProviderPrivateLinkScopeId{} + +// ProviderPrivateLinkScopeId is a struct representing the Resource ID for a Provider Private Link Scope +type ProviderPrivateLinkScopeId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string +} + +// NewProviderPrivateLinkScopeID returns a new ProviderPrivateLinkScopeId struct +func NewProviderPrivateLinkScopeID(subscriptionId string, resourceGroupName string, privateLinkScopeName string) ProviderPrivateLinkScopeId { + return ProviderPrivateLinkScopeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + } +} + +// ParseProviderPrivateLinkScopeID parses 'input' into a ProviderPrivateLinkScopeId +func ParseProviderPrivateLinkScopeID(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderPrivateLinkScopeIDInsensitively parses 'input' case-insensitively into a ProviderPrivateLinkScopeId +// note: this method should only be used for API response data and not user input +func ParseProviderPrivateLinkScopeIDInsensitively(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderPrivateLinkScopeId) 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.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + return nil +} + +// ValidateProviderPrivateLinkScopeID checks that 'input' can be parsed as a Provider Private Link Scope ID +func ValidateProviderPrivateLinkScopeID(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 := ParseProviderPrivateLinkScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + } +} + +// String returns a human-readable description of this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + } + return fmt.Sprintf("Provider Private Link Scope (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope_test.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope_test.go new file mode 100644 index 00000000000..bf57b72fb1d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/id_providerprivatelinkscope_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +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 = &ProviderPrivateLinkScopeId{} + +func TestNewProviderPrivateLinkScopeID(t *testing.T) { + id := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + + 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.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } +} + +func TestFormatProviderPrivateLinkScopeID(t *testing.T) { + actual := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderPrivateLinkScopeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeID(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestParseProviderPrivateLinkScopeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + }, + }, + { + // 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.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeIDInsensitively(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestSegmentsForProviderPrivateLinkScopeId(t *testing.T) { + segments := ProviderPrivateLinkScopeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderPrivateLinkScopeId 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/hybridcompute/2025-01-13/privateendpointconnections/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..943007e4641 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_createorupdate.go @@ -0,0 +1,75 @@ +package privateendpointconnections + +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 *PrivateEndpointConnection +} + +// CreateOrUpdate ... +func (c PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) 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/hybridcompute/2025-01-13/privateendpointconnections/method_delete.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package privateendpointconnections + +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 PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_get.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..351242746d4 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_listbyprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_listbyprivatelinkscope.go new file mode 100644 index 00000000000..6f549ecb04d --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/method_listbyprivatelinkscope.go @@ -0,0 +1,105 @@ +package privateendpointconnections + +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 ListByPrivateLinkScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListByPrivateLinkScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +type ListByPrivateLinkScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByPrivateLinkScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByPrivateLinkScope ... +func (c PrivateEndpointConnectionsClient) ListByPrivateLinkScope(ctx context.Context, id ProviderPrivateLinkScopeId) (result ListByPrivateLinkScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByPrivateLinkScopeCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPrivateLinkScopeComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListByPrivateLinkScopeComplete(ctx context.Context, id ProviderPrivateLinkScopeId) (ListByPrivateLinkScopeCompleteResult, error) { + return c.ListByPrivateLinkScopeCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListByPrivateLinkScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListByPrivateLinkScopeCompleteMatchingPredicate(ctx context.Context, id ProviderPrivateLinkScopeId, predicate PrivateEndpointConnectionOperationPredicate) (result ListByPrivateLinkScopeCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.ListByPrivateLinkScope(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByPrivateLinkScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..977fe056fe3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package privateendpointconnections + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..948cf6c47dc --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionStateProperty `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointproperty.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointproperty.go new file mode 100644 index 00000000000..b0b0ff18482 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privateendpointproperty.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..ba250769d7a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionStateProperty struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status string `json:"status"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/predicates.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..4a03a91ce52 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/predicates.go @@ -0,0 +1,27 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/version.go b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/version.go new file mode 100644 index 00000000000..0e74a0bfdf4 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/README.md b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/README.md new file mode 100644 index 00000000000..85d5ce5f646 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkresources.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateLinkResourceName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByPrivateLinkScope` + +```go +ctx := context.TODO() +id := privatelinkresources.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +// alternatively `client.ListByPrivateLinkScope(ctx, id)` can be used to do batched pagination +items, err := client.ListByPrivateLinkScopeComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/client.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/client.go new file mode 100644 index 00000000000..28c00b21f03 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource.go new file mode 100644 index 00000000000..bc340a22775 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource.go @@ -0,0 +1,139 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateLinkResourceId{}) +} + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, privateLinkScopeName string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceName"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource_test.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource_test.go new file mode 100644 index 00000000000..43a8b6e7d3a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateLinkResourceName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } + + if id.PrivateLinkResourceName != "privateLinkResourceName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceName") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName", "privateLinkResourceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources/privateLinkResourceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope.go new file mode 100644 index 00000000000..f21dc62c87e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope.go @@ -0,0 +1,130 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderPrivateLinkScopeId{}) +} + +var _ resourceids.ResourceId = &ProviderPrivateLinkScopeId{} + +// ProviderPrivateLinkScopeId is a struct representing the Resource ID for a Provider Private Link Scope +type ProviderPrivateLinkScopeId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string +} + +// NewProviderPrivateLinkScopeID returns a new ProviderPrivateLinkScopeId struct +func NewProviderPrivateLinkScopeID(subscriptionId string, resourceGroupName string, privateLinkScopeName string) ProviderPrivateLinkScopeId { + return ProviderPrivateLinkScopeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + } +} + +// ParseProviderPrivateLinkScopeID parses 'input' into a ProviderPrivateLinkScopeId +func ParseProviderPrivateLinkScopeID(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderPrivateLinkScopeIDInsensitively parses 'input' case-insensitively into a ProviderPrivateLinkScopeId +// note: this method should only be used for API response data and not user input +func ParseProviderPrivateLinkScopeIDInsensitively(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderPrivateLinkScopeId) 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.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + return nil +} + +// ValidateProviderPrivateLinkScopeID checks that 'input' can be parsed as a Provider Private Link Scope ID +func ValidateProviderPrivateLinkScopeID(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 := ParseProviderPrivateLinkScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + } +} + +// String returns a human-readable description of this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + } + return fmt.Sprintf("Provider Private Link Scope (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope_test.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope_test.go new file mode 100644 index 00000000000..b2da5008a8c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/id_providerprivatelinkscope_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +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 = &ProviderPrivateLinkScopeId{} + +func TestNewProviderPrivateLinkScopeID(t *testing.T) { + id := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + + 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.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } +} + +func TestFormatProviderPrivateLinkScopeID(t *testing.T) { + actual := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderPrivateLinkScopeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeID(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestParseProviderPrivateLinkScopeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + }, + }, + { + // 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.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeIDInsensitively(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestSegmentsForProviderPrivateLinkScopeId(t *testing.T) { + segments := ProviderPrivateLinkScopeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderPrivateLinkScopeId 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/hybridcompute/2025-01-13/privatelinkresources/method_get.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_get.go new file mode 100644 index 00000000000..4fe26146181 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_get.go @@ -0,0 +1,53 @@ +package privatelinkresources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkResourcesClient) Get(ctx context.Context, id PrivateLinkResourceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_listbyprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_listbyprivatelinkscope.go new file mode 100644 index 00000000000..3d0cadde9f7 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/method_listbyprivatelinkscope.go @@ -0,0 +1,105 @@ +package privatelinkresources + +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 ListByPrivateLinkScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListByPrivateLinkScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +type ListByPrivateLinkScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByPrivateLinkScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByPrivateLinkScope ... +func (c PrivateLinkResourcesClient) ListByPrivateLinkScope(ctx context.Context, id ProviderPrivateLinkScopeId) (result ListByPrivateLinkScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByPrivateLinkScopeCustomPager{}, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPrivateLinkScopeComplete retrieves all the results into a single object +func (c PrivateLinkResourcesClient) ListByPrivateLinkScopeComplete(ctx context.Context, id ProviderPrivateLinkScopeId) (ListByPrivateLinkScopeCompleteResult, error) { + return c.ListByPrivateLinkScopeCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListByPrivateLinkScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkResourcesClient) ListByPrivateLinkScopeCompleteMatchingPredicate(ctx context.Context, id ProviderPrivateLinkScopeId, predicate PrivateLinkResourceOperationPredicate) (result ListByPrivateLinkScopeCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.ListByPrivateLinkScope(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByPrivateLinkScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresource.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..6e8c3d8148b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,16 @@ +package privatelinkresources + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/predicates.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/predicates.go new file mode 100644 index 00000000000..19b771c3994 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/predicates.go @@ -0,0 +1,27 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkresources/version.go b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/version.go new file mode 100644 index 00000000000..c5a43c583fb --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkresources/version.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresources/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/README.md b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/README.md new file mode 100644 index 00000000000..7f5c1499435 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/README.md @@ -0,0 +1,157 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/privatelinkscopes` Documentation + +The `privatelinkscopes` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/privatelinkscopes" +``` + + +### Client Initialization + +```go +client := privatelinkscopes.NewPrivateLinkScopesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkScopesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privatelinkscopes.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +payload := privatelinkscopes.HybridComputePrivateLinkScope{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkScopesClient.Delete` + +```go +ctx := context.TODO() +id := privatelinkscopes.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateLinkScopesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkscopes.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +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: `PrivateLinkScopesClient.GetValidationDetails` + +```go +ctx := context.TODO() +id := privatelinkscopes.NewPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "locationName", "privateLinkScopeId") + +read, err := client.GetValidationDetails(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkScopesClient.GetValidationDetailsForMachine` + +```go +ctx := context.TODO() +id := privatelinkscopes.NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + +read, err := client.GetValidationDetailsForMachine(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkScopesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `PrivateLinkScopesClient.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: `PrivateLinkScopesClient.UpdateTags` + +```go +ctx := context.TODO() +id := privatelinkscopes.NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + +payload := privatelinkscopes.TagsResource{ + // ... +} + + +read, err := client.UpdateTags(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/hybridcompute/2025-01-13/privatelinkscopes/client.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/client.go new file mode 100644 index 00000000000..6ad00026164 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/client.go @@ -0,0 +1,26 @@ +package privatelinkscopes + +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 PrivateLinkScopesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkScopesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkScopesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkscopes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkScopesClient: %+v", err) + } + + return &PrivateLinkScopesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/constants.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/constants.go new file mode 100644 index 00000000000..89bd271900e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/constants.go @@ -0,0 +1,51 @@ +package privatelinkscopes + +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 PublicNetworkAccessType string + +const ( + PublicNetworkAccessTypeDisabled PublicNetworkAccessType = "Disabled" + PublicNetworkAccessTypeEnabled PublicNetworkAccessType = "Enabled" +) + +func PossibleValuesForPublicNetworkAccessType() []string { + return []string{ + string(PublicNetworkAccessTypeDisabled), + string(PublicNetworkAccessTypeEnabled), + } +} + +func (s *PublicNetworkAccessType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccessType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccessType(input string) (*PublicNetworkAccessType, error) { + vals := map[string]PublicNetworkAccessType{ + "disabled": PublicNetworkAccessTypeDisabled, + "enabled": PublicNetworkAccessTypeEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccessType(input) + return &out, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine.go new file mode 100644 index 00000000000..ae7b09c821b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine.go @@ -0,0 +1,130 @@ +package privatelinkscopes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MachineId{}) +} + +var _ resourceids.ResourceId = &MachineId{} + +// MachineId is a struct representing the Resource ID for a Machine +type MachineId struct { + SubscriptionId string + ResourceGroupName string + MachineName string +} + +// NewMachineID returns a new MachineId struct +func NewMachineID(subscriptionId string, resourceGroupName string, machineName string) MachineId { + return MachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MachineName: machineName, + } +} + +// ParseMachineID parses 'input' into a MachineId +func ParseMachineID(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMachineIDInsensitively parses 'input' case-insensitively into a MachineId +// note: this method should only be used for API response data and not user input +func ParseMachineIDInsensitively(input string) (*MachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&MachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MachineId) 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.MachineName, ok = input.Parsed["machineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "machineName", input) + } + + return nil +} + +// ValidateMachineID checks that 'input' can be parsed as a Machine ID +func ValidateMachineID(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 := ParseMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Machine ID +func (id MachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/machines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Machine ID +func (id MachineId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticMachines", "machines", "machines"), + resourceids.UserSpecifiedSegment("machineName", "machineName"), + } +} + +// String returns a human-readable description of this Machine ID +func (id MachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Machine Name: %q", id.MachineName), + } + return fmt.Sprintf("Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine_test.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine_test.go new file mode 100644 index 00000000000..83b00fb5691 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_machine_test.go @@ -0,0 +1,282 @@ +package privatelinkscopes + +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 = &MachineId{} + +func TestNewMachineID(t *testing.T) { + id := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName") + + 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.MachineName != "machineName" { + t.Fatalf("Expected %q but got %q for Segment 'MachineName'", id.MachineName, "machineName") + } +} + +func TestFormatMachineID(t *testing.T) { + actual := NewMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "machineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineID(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestParseMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MachineId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MachineName: "machineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/machines/machineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe", + Expected: &MachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MachineName: "mAcHiNeNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/mAcHiNeS/mAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMachineIDInsensitively(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.MachineName != v.Expected.MachineName { + t.Fatalf("Expected %q but got %q for MachineName", v.Expected.MachineName, actual.MachineName) + } + + } +} + +func TestSegmentsForMachineId(t *testing.T) { + segments := MachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MachineId 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/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope.go new file mode 100644 index 00000000000..a2a5feb8bb6 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope.go @@ -0,0 +1,130 @@ +package privatelinkscopes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateLinkScopeId{}) +} + +var _ resourceids.ResourceId = &PrivateLinkScopeId{} + +// PrivateLinkScopeId is a struct representing the Resource ID for a Private Link Scope +type PrivateLinkScopeId struct { + SubscriptionId string + LocationName string + PrivateLinkScopeId string +} + +// NewPrivateLinkScopeID returns a new PrivateLinkScopeId struct +func NewPrivateLinkScopeID(subscriptionId string, locationName string, privateLinkScopeId string) PrivateLinkScopeId { + return PrivateLinkScopeId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + PrivateLinkScopeId: privateLinkScopeId, + } +} + +// ParsePrivateLinkScopeID parses 'input' into a PrivateLinkScopeId +func ParsePrivateLinkScopeID(input string) (*PrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkScopeIDInsensitively parses 'input' case-insensitively into a PrivateLinkScopeId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkScopeIDInsensitively(input string) (*PrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkScopeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.PrivateLinkScopeId, ok = input.Parsed["privateLinkScopeId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeId", input) + } + + return nil +} + +// ValidatePrivateLinkScopeID checks that 'input' can be parsed as a Private Link Scope ID +func ValidatePrivateLinkScopeID(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 := ParsePrivateLinkScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Scope ID +func (id PrivateLinkScopeId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.HybridCompute/locations/%s/privateLinkScopes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.PrivateLinkScopeId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Scope ID +func (id PrivateLinkScopeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeId", "privateLinkScopeId"), + } +} + +// String returns a human-readable description of this Private Link Scope ID +func (id PrivateLinkScopeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Private Link Scope: %q", id.PrivateLinkScopeId), + } + return fmt.Sprintf("Private Link Scope (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope_test.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope_test.go new file mode 100644 index 00000000000..9a5f850d2bf --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_privatelinkscope_test.go @@ -0,0 +1,282 @@ +package privatelinkscopes + +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 = &PrivateLinkScopeId{} + +func TestNewPrivateLinkScopeID(t *testing.T) { + id := NewPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "locationName", "privateLinkScopeId") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.PrivateLinkScopeId != "privateLinkScopeId" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeId'", id.PrivateLinkScopeId, "privateLinkScopeId") + } +} + +func TestFormatPrivateLinkScopeID(t *testing.T) { + actual := NewPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "locationName", "privateLinkScopeId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes/privateLinkScopeId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkScopeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkScopeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes/privateLinkScopeId", + Expected: &PrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + PrivateLinkScopeId: "privateLinkScopeId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes/privateLinkScopeId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkScopeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PrivateLinkScopeId != v.Expected.PrivateLinkScopeId { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeId", v.Expected.PrivateLinkScopeId, actual.PrivateLinkScopeId) + } + + } +} + +func TestParsePrivateLinkScopeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkScopeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes/privateLinkScopeId", + Expected: &PrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + PrivateLinkScopeId: "privateLinkScopeId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.HybridCompute/locations/locationName/privateLinkScopes/privateLinkScopeId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEiD", + Expected: &PrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + PrivateLinkScopeId: "pRiVaTeLiNkScOpEiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/lOcAtIoNs/lOcAtIoNnAmE/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkScopeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.PrivateLinkScopeId != v.Expected.PrivateLinkScopeId { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeId", v.Expected.PrivateLinkScopeId, actual.PrivateLinkScopeId) + } + + } +} + +func TestSegmentsForPrivateLinkScopeId(t *testing.T) { + segments := PrivateLinkScopeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkScopeId 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/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope.go new file mode 100644 index 00000000000..33c545a7749 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope.go @@ -0,0 +1,130 @@ +package privatelinkscopes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderPrivateLinkScopeId{}) +} + +var _ resourceids.ResourceId = &ProviderPrivateLinkScopeId{} + +// ProviderPrivateLinkScopeId is a struct representing the Resource ID for a Provider Private Link Scope +type ProviderPrivateLinkScopeId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkScopeName string +} + +// NewProviderPrivateLinkScopeID returns a new ProviderPrivateLinkScopeId struct +func NewProviderPrivateLinkScopeID(subscriptionId string, resourceGroupName string, privateLinkScopeName string) ProviderPrivateLinkScopeId { + return ProviderPrivateLinkScopeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkScopeName: privateLinkScopeName, + } +} + +// ParseProviderPrivateLinkScopeID parses 'input' into a ProviderPrivateLinkScopeId +func ParseProviderPrivateLinkScopeID(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderPrivateLinkScopeIDInsensitively parses 'input' case-insensitively into a ProviderPrivateLinkScopeId +// note: this method should only be used for API response data and not user input +func ParseProviderPrivateLinkScopeIDInsensitively(input string) (*ProviderPrivateLinkScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderPrivateLinkScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderPrivateLinkScopeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderPrivateLinkScopeId) 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.PrivateLinkScopeName, ok = input.Parsed["privateLinkScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkScopeName", input) + } + + return nil +} + +// ValidateProviderPrivateLinkScopeID checks that 'input' can be parsed as a Provider Private Link Scope ID +func ValidateProviderPrivateLinkScopeID(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 := ParseProviderPrivateLinkScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.HybridCompute/privateLinkScopes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkScopeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) 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("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticPrivateLinkScopes", "privateLinkScopes", "privateLinkScopes"), + resourceids.UserSpecifiedSegment("privateLinkScopeName", "privateLinkScopeName"), + } +} + +// String returns a human-readable description of this Provider Private Link Scope ID +func (id ProviderPrivateLinkScopeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Scope Name: %q", id.PrivateLinkScopeName), + } + return fmt.Sprintf("Provider Private Link Scope (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope_test.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope_test.go new file mode 100644 index 00000000000..1ebda450104 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/id_providerprivatelinkscope_test.go @@ -0,0 +1,282 @@ +package privatelinkscopes + +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 = &ProviderPrivateLinkScopeId{} + +func TestNewProviderPrivateLinkScopeID(t *testing.T) { + id := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName") + + 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.PrivateLinkScopeName != "privateLinkScopeName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkScopeName'", id.PrivateLinkScopeName, "privateLinkScopeName") + } +} + +func TestFormatProviderPrivateLinkScopeID(t *testing.T) { + actual := NewProviderPrivateLinkScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkScopeName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderPrivateLinkScopeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeID(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestParseProviderPrivateLinkScopeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderPrivateLinkScopeId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkScopeName: "privateLinkScopeName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.HybridCompute/privateLinkScopes/privateLinkScopeName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE", + Expected: &ProviderPrivateLinkScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkScopeName: "pRiVaTeLiNkScOpEnAmE", + }, + }, + { + // 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.hYbRiDcOmPuTe/pRiVaTeLiNkScOpEs/pRiVaTeLiNkScOpEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderPrivateLinkScopeIDInsensitively(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.PrivateLinkScopeName != v.Expected.PrivateLinkScopeName { + t.Fatalf("Expected %q but got %q for PrivateLinkScopeName", v.Expected.PrivateLinkScopeName, actual.PrivateLinkScopeName) + } + + } +} + +func TestSegmentsForProviderPrivateLinkScopeId(t *testing.T) { + segments := ProviderPrivateLinkScopeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderPrivateLinkScopeId 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/hybridcompute/2025-01-13/privatelinkscopes/method_createorupdate.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_createorupdate.go new file mode 100644 index 00000000000..e443fdeae45 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_createorupdate.go @@ -0,0 +1,58 @@ +package privatelinkscopes + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *HybridComputePrivateLinkScope +} + +// CreateOrUpdate ... +func (c PrivateLinkScopesClient) CreateOrUpdate(ctx context.Context, id ProviderPrivateLinkScopeId, input HybridComputePrivateLinkScope) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model HybridComputePrivateLinkScope + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_delete.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_delete.go new file mode 100644 index 00000000000..59dfe5ecb40 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_delete.go @@ -0,0 +1,71 @@ +package privatelinkscopes + +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 PrivateLinkScopesClient) Delete(ctx context.Context, id ProviderPrivateLinkScopeId) (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 PrivateLinkScopesClient) DeleteThenPoll(ctx context.Context, id ProviderPrivateLinkScopeId) 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/hybridcompute/2025-01-13/privatelinkscopes/method_get.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_get.go new file mode 100644 index 00000000000..1d8b307be87 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_get.go @@ -0,0 +1,53 @@ +package privatelinkscopes + +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 *HybridComputePrivateLinkScope +} + +// Get ... +func (c PrivateLinkScopesClient) Get(ctx context.Context, id ProviderPrivateLinkScopeId) (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 HybridComputePrivateLinkScope + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetails.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetails.go new file mode 100644 index 00000000000..6b32c351ffa --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetails.go @@ -0,0 +1,53 @@ +package privatelinkscopes + +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 GetValidationDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkScopeValidationDetails +} + +// GetValidationDetails ... +func (c PrivateLinkScopesClient) GetValidationDetails(ctx context.Context, id PrivateLinkScopeId) (result GetValidationDetailsOperationResponse, 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 PrivateLinkScopeValidationDetails + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetailsformachine.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetailsformachine.go new file mode 100644 index 00000000000..ee67466fe66 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_getvalidationdetailsformachine.go @@ -0,0 +1,54 @@ +package privatelinkscopes + +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 GetValidationDetailsForMachineOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkScopeValidationDetails +} + +// GetValidationDetailsForMachine ... +func (c PrivateLinkScopesClient) GetValidationDetailsForMachine(ctx context.Context, id MachineId) (result GetValidationDetailsForMachineOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkScopes/current", 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 PrivateLinkScopeValidationDetails + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_list.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_list.go new file mode 100644 index 00000000000..cf7cb6a98b9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_list.go @@ -0,0 +1,106 @@ +package privatelinkscopes + +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 *[]HybridComputePrivateLinkScope +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []HybridComputePrivateLinkScope +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c PrivateLinkScopesClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/privateLinkScopes", 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 *[]HybridComputePrivateLinkScope `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 PrivateLinkScopesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, HybridComputePrivateLinkScopeOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkScopesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate HybridComputePrivateLinkScopeOperationPredicate) (result ListCompleteResult, err error) { + items := make([]HybridComputePrivateLinkScope, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_listbyresourcegroup.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_listbyresourcegroup.go new file mode 100644 index 00000000000..816a40b7f9e --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package privatelinkscopes + +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 *[]HybridComputePrivateLinkScope +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []HybridComputePrivateLinkScope +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c PrivateLinkScopesClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.HybridCompute/privateLinkScopes", 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 *[]HybridComputePrivateLinkScope `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 PrivateLinkScopesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, HybridComputePrivateLinkScopeOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkScopesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate HybridComputePrivateLinkScopeOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]HybridComputePrivateLinkScope, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_updatetags.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_updatetags.go new file mode 100644 index 00000000000..2b50c500623 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/method_updatetags.go @@ -0,0 +1,57 @@ +package privatelinkscopes + +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 UpdateTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *HybridComputePrivateLinkScope +} + +// UpdateTags ... +func (c PrivateLinkScopesClient) UpdateTags(ctx context.Context, id ProviderPrivateLinkScopeId, input TagsResource) (result UpdateTagsOperationResponse, 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 HybridComputePrivateLinkScope + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_connectiondetail.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_connectiondetail.go new file mode 100644 index 00000000000..23704820122 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_connectiondetail.go @@ -0,0 +1,12 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionDetail struct { + GroupId *string `json:"groupId,omitempty"` + Id *string `json:"id,omitempty"` + LinkIdentifier *string `json:"linkIdentifier,omitempty"` + MemberName *string `json:"memberName,omitempty"` + PrivateIPAddress *string `json:"privateIpAddress,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscope.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscope.go new file mode 100644 index 00000000000..410d4826626 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscope.go @@ -0,0 +1,18 @@ +package privatelinkscopes + +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 HybridComputePrivateLinkScope struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *HybridComputePrivateLinkScopeProperties `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/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscopeproperties.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscopeproperties.go new file mode 100644 index 00000000000..d525c698b8c --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_hybridcomputeprivatelinkscopeproperties.go @@ -0,0 +1,11 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridComputePrivateLinkScopeProperties struct { + PrivateEndpointConnections *[]PrivateEndpointConnectionDataModel `json:"privateEndpointConnections,omitempty"` + PrivateLinkScopeId *string `json:"privateLinkScopeId,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccessType `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectiondatamodel.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectiondatamodel.go new file mode 100644 index 00000000000..954af3e5dfd --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectiondatamodel.go @@ -0,0 +1,11 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionDataModel struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectionproperties.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..58abb2b5719 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionStateProperty `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointproperty.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointproperty.go new file mode 100644 index 00000000000..69fce723b97 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privateendpointproperty.go @@ -0,0 +1,8 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkscopevalidationdetails.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkscopevalidationdetails.go new file mode 100644 index 00000000000..9c6f9562dc9 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkscopevalidationdetails.go @@ -0,0 +1,10 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkScopeValidationDetails struct { + ConnectionDetails *[]ConnectionDetail `json:"connectionDetails,omitempty"` + Id *string `json:"id,omitempty"` + PublicNetworkAccess *PublicNetworkAccessType `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkserviceconnectionstateproperty.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..685eb71d83a --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_privatelinkserviceconnectionstateproperty.go @@ -0,0 +1,10 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionStateProperty struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status string `json:"status"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_tagsresource.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_tagsresource.go new file mode 100644 index 00000000000..63d0bb42123 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/model_tagsresource.go @@ -0,0 +1,8 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsResource struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/predicates.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/predicates.go new file mode 100644 index 00000000000..d0efec03876 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/predicates.go @@ -0,0 +1,32 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridComputePrivateLinkScopeOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p HybridComputePrivateLinkScopeOperationPredicate) Matches(input HybridComputePrivateLinkScope) 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/hybridcompute/2025-01-13/privatelinkscopes/version.go b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/version.go new file mode 100644 index 00000000000..3f1f23540d0 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/privatelinkscopes/version.go @@ -0,0 +1,10 @@ +package privatelinkscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkscopes/2025-01-13" +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/README.md b/resource-manager/hybridcompute/2025-01-13/settings/README.md new file mode 100644 index 00000000000..76bfc5fd7a1 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/README.md @@ -0,0 +1,78 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2025-01-13/settings` Documentation + +The `settings` SDK allows for interaction with Azure Resource Manager `hybridcompute` (API Version `2025-01-13`). + +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/hybridcompute/2025-01-13/settings" +``` + + +### Client Initialization + +```go +client := settings.NewSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SettingsClient.Get` + +```go +ctx := context.TODO() +id := settings.NewScopedSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "settingName") + +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: `SettingsClient.Patch` + +```go +ctx := context.TODO() +id := settings.NewScopedSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "settingName") + +payload := settings.Settings{ + // ... +} + + +read, err := client.Patch(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SettingsClient.Update` + +```go +ctx := context.TODO() +id := settings.NewScopedSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "settingName") + +payload := settings.Settings{ + // ... +} + + +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/hybridcompute/2025-01-13/settings/client.go b/resource-manager/hybridcompute/2025-01-13/settings/client.go new file mode 100644 index 00000000000..a111b1f00a7 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/client.go @@ -0,0 +1,26 @@ +package settings + +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 SettingsClient struct { + Client *resourcemanager.Client +} + +func NewSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "settings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SettingsClient: %+v", err) + } + + return &SettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting.go b/resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting.go new file mode 100644 index 00000000000..ede13e743a3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting.go @@ -0,0 +1,120 @@ +package settings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedSettingId{}) +} + +var _ resourceids.ResourceId = &ScopedSettingId{} + +// ScopedSettingId is a struct representing the Resource ID for a Scoped Setting +type ScopedSettingId struct { + Scope string + SettingName string +} + +// NewScopedSettingID returns a new ScopedSettingId struct +func NewScopedSettingID(scope string, settingName string) ScopedSettingId { + return ScopedSettingId{ + Scope: scope, + SettingName: settingName, + } +} + +// ParseScopedSettingID parses 'input' into a ScopedSettingId +func ParseScopedSettingID(input string) (*ScopedSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedSettingId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedSettingIDInsensitively parses 'input' case-insensitively into a ScopedSettingId +// note: this method should only be used for API response data and not user input +func ParseScopedSettingIDInsensitively(input string) (*ScopedSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedSettingId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedSettingId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.SettingName, ok = input.Parsed["settingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "settingName", input) + } + + return nil +} + +// ValidateScopedSettingID checks that 'input' can be parsed as a Scoped Setting ID +func ValidateScopedSettingID(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 := ParseScopedSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Setting ID +func (id ScopedSettingId) ID() string { + fmtString := "/%s/providers/Microsoft.HybridCompute/settings/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.SettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Setting ID +func (id ScopedSettingId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftHybridCompute", "Microsoft.HybridCompute", "Microsoft.HybridCompute"), + resourceids.StaticSegment("staticSettings", "settings", "settings"), + resourceids.UserSpecifiedSegment("settingName", "settingName"), + } +} + +// String returns a human-readable description of this Scoped Setting ID +func (id ScopedSettingId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Setting Name: %q", id.SettingName), + } + return fmt.Sprintf("Scoped Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting_test.go b/resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting_test.go new file mode 100644 index 00000000000..33e3425e2f3 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/id_scopedsetting_test.go @@ -0,0 +1,222 @@ +package settings + +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 = &ScopedSettingId{} + +func TestNewScopedSettingID(t *testing.T) { + id := NewScopedSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "settingName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.SettingName != "settingName" { + t.Fatalf("Expected %q but got %q for Segment 'SettingName'", id.SettingName, "settingName") + } +} + +func TestFormatScopedSettingID(t *testing.T) { + actual := NewScopedSettingID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "settingName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings/settingName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedSettingId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings/settingName", + Expected: &ScopedSettingId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + SettingName: "settingName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings/settingName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedSettingID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.SettingName != v.Expected.SettingName { + t.Fatalf("Expected %q but got %q for SettingName", v.Expected.SettingName, actual.SettingName) + } + + } +} + +func TestParseScopedSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedSettingId + }{ + { + // 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.HybridCompute", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/sEtTiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings/settingName", + Expected: &ScopedSettingId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + SettingName: "settingName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.HybridCompute/settings/settingName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.hYbRiDcOmPuTe/sEtTiNgS/sEtTiNgNaMe", + Expected: &ScopedSettingId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + SettingName: "sEtTiNgNaMe", + }, + }, + { + // 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.hYbRiDcOmPuTe/sEtTiNgS/sEtTiNgNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedSettingIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.SettingName != v.Expected.SettingName { + t.Fatalf("Expected %q but got %q for SettingName", v.Expected.SettingName, actual.SettingName) + } + + } +} + +func TestSegmentsForScopedSettingId(t *testing.T) { + segments := ScopedSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedSettingId 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/hybridcompute/2025-01-13/settings/method_get.go b/resource-manager/hybridcompute/2025-01-13/settings/method_get.go new file mode 100644 index 00000000000..d570f6b5769 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/method_get.go @@ -0,0 +1,53 @@ +package settings + +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 *Settings +} + +// Get ... +func (c SettingsClient) Get(ctx context.Context, id ScopedSettingId) (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 Settings + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/method_patch.go b/resource-manager/hybridcompute/2025-01-13/settings/method_patch.go new file mode 100644 index 00000000000..fd9c695fa5b --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/method_patch.go @@ -0,0 +1,57 @@ +package settings + +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 PatchOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Settings +} + +// Patch ... +func (c SettingsClient) Patch(ctx context.Context, id ScopedSettingId, input Settings) (result PatchOperationResponse, 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 Settings + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/method_update.go b/resource-manager/hybridcompute/2025-01-13/settings/method_update.go new file mode 100644 index 00000000000..4e3e6429ead --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/method_update.go @@ -0,0 +1,58 @@ +package settings + +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 *Settings +} + +// Update ... +func (c SettingsClient) Update(ctx context.Context, id ScopedSettingId, input Settings) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Settings + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/model_settings.go b/resource-manager/hybridcompute/2025-01-13/settings/model_settings.go new file mode 100644 index 00000000000..60e399919a7 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/model_settings.go @@ -0,0 +1,16 @@ +package settings + +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 Settings struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SettingsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/model_settingsgatewayproperties.go b/resource-manager/hybridcompute/2025-01-13/settings/model_settingsgatewayproperties.go new file mode 100644 index 00000000000..71a561f2ba5 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/model_settingsgatewayproperties.go @@ -0,0 +1,8 @@ +package settings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SettingsGatewayProperties struct { + GatewayResourceId *string `json:"gatewayResourceId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/model_settingsproperties.go b/resource-manager/hybridcompute/2025-01-13/settings/model_settingsproperties.go new file mode 100644 index 00000000000..9ce7db5c05f --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/model_settingsproperties.go @@ -0,0 +1,9 @@ +package settings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SettingsProperties struct { + GatewayProperties *SettingsGatewayProperties `json:"gatewayProperties,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/hybridcompute/2025-01-13/settings/version.go b/resource-manager/hybridcompute/2025-01-13/settings/version.go new file mode 100644 index 00000000000..1643f1f2f70 --- /dev/null +++ b/resource-manager/hybridcompute/2025-01-13/settings/version.go @@ -0,0 +1,10 @@ +package settings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-13" + +func userAgent() string { + return "hashicorp/go-azure-sdk/settings/2025-01-13" +} diff --git a/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go b/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go index 793caeabedc..c9291fb2fab 100644 --- a/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go +++ b/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go @@ -138,8 +138,6 @@ func parseGroupMemberType(input string) (*GroupMemberType, error) { type ProvisioningState string const ( - ProvisioningStateCanceled ProvisioningState = "Canceled" - ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -148,8 +146,6 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ - string(ProvisioningStateCanceled), - string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -172,8 +168,6 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ - "canceled": ProvisioningStateCanceled, - "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go b/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go index 6f3a6c4f554..642ecd4a0bd 100644 --- a/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go +++ b/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go @@ -217,8 +217,6 @@ func parseIsGlobal(input string) (*IsGlobal, error) { type ProvisioningState string const ( - ProvisioningStateCanceled ProvisioningState = "Canceled" - ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -227,8 +225,6 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ - string(ProvisioningStateCanceled), - string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -251,8 +247,6 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ - "canceled": ProvisioningStateCanceled, - "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go b/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go index caa8b3c8747..9007e4a33df 100644 --- a/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go +++ b/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go @@ -217,6 +217,8 @@ func parseIsGlobal(input string) (*IsGlobal, error) { type ProvisioningState string const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -225,6 +227,8 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -247,6 +251,8 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go b/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go index 67086d778e3..6dbd1e6db74 100644 --- a/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go +++ b/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go @@ -138,6 +138,8 @@ func parseGroupMemberType(input string) (*GroupMemberType, error) { type ProvisioningState string const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -146,6 +148,8 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -168,6 +172,8 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/README.md b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/README.md new file mode 100644 index 00000000000..49186f3588a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/availableservicetiers` Documentation + +The `availableservicetiers` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/availableservicetiers" +``` + + +### Client Initialization + +```go +client := availableservicetiers.NewAvailableServiceTiersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AvailableServiceTiersClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := availableservicetiers.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/client.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/client.go new file mode 100644 index 00000000000..3396efc04c9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/client.go @@ -0,0 +1,26 @@ +package availableservicetiers + +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 AvailableServiceTiersClient struct { + Client *resourcemanager.Client +} + +func NewAvailableServiceTiersClientWithBaseURI(sdkApi sdkEnv.Api) (*AvailableServiceTiersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "availableservicetiers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AvailableServiceTiersClient: %+v", err) + } + + return &AvailableServiceTiersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/constants.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/constants.go new file mode 100644 index 00000000000..26729cec9cc --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/constants.go @@ -0,0 +1,66 @@ +package availableservicetiers + +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 SkuNameEnum string + +const ( + SkuNameEnumCapacityReservation SkuNameEnum = "CapacityReservation" + SkuNameEnumFree SkuNameEnum = "Free" + SkuNameEnumPerGBTwoZeroOneEight SkuNameEnum = "PerGB2018" + SkuNameEnumPerNode SkuNameEnum = "PerNode" + SkuNameEnumPremium SkuNameEnum = "Premium" + SkuNameEnumStandalone SkuNameEnum = "Standalone" + SkuNameEnumStandard SkuNameEnum = "Standard" +) + +func PossibleValuesForSkuNameEnum() []string { + return []string{ + string(SkuNameEnumCapacityReservation), + string(SkuNameEnumFree), + string(SkuNameEnumPerGBTwoZeroOneEight), + string(SkuNameEnumPerNode), + string(SkuNameEnumPremium), + string(SkuNameEnumStandalone), + string(SkuNameEnumStandard), + } +} + +func (s *SkuNameEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuNameEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuNameEnum(input string) (*SkuNameEnum, error) { + vals := map[string]SkuNameEnum{ + "capacityreservation": SkuNameEnumCapacityReservation, + "free": SkuNameEnumFree, + "pergb2018": SkuNameEnumPerGBTwoZeroOneEight, + "pernode": SkuNameEnumPerNode, + "premium": SkuNameEnumPremium, + "standalone": SkuNameEnumStandalone, + "standard": SkuNameEnumStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuNameEnum(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace.go new file mode 100644 index 00000000000..4600980eb71 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace.go @@ -0,0 +1,130 @@ +package availableservicetiers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace_test.go new file mode 100644 index 00000000000..34b0b9e1f18 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/id_workspace_test.go @@ -0,0 +1,282 @@ +package availableservicetiers + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/availableservicetiers/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/method_listbyworkspace.go new file mode 100644 index 00000000000..431f2b6767c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/method_listbyworkspace.go @@ -0,0 +1,54 @@ +package availableservicetiers + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AvailableServiceTier +} + +// ListByWorkspace ... +func (c AvailableServiceTiersClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/availableServiceTiers", 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 []AvailableServiceTier + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/model_availableservicetier.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/model_availableservicetier.go new file mode 100644 index 00000000000..b41b7f9b19a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/model_availableservicetier.go @@ -0,0 +1,14 @@ +package availableservicetiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableServiceTier struct { + CapacityReservationLevel *int64 `json:"capacityReservationLevel,omitempty"` + DefaultRetention *int64 `json:"defaultRetention,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + LastSkuUpdate *string `json:"lastSkuUpdate,omitempty"` + MaximumRetention *int64 `json:"maximumRetention,omitempty"` + MinimumRetention *int64 `json:"minimumRetention,omitempty"` + ServiceTier *SkuNameEnum `json:"serviceTier,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/availableservicetiers/version.go b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/version.go new file mode 100644 index 00000000000..b64fa4bcf1a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/availableservicetiers/version.go @@ -0,0 +1,10 @@ +package availableservicetiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/availableservicetiers/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/client.go b/resource-manager/operationalinsights/2025-02-01/client.go new file mode 100644 index 00000000000..656cf30bf43 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/client.go @@ -0,0 +1,145 @@ +package v2025_02_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/availableservicetiers" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/clusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/dataexport" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/datasources" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/deletedworkspaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/intelligencepacks" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/linkedservices" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/querypackqueries" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/querypacks" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/savedsearches" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/storageinsights" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/tables" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/workspaces" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AvailableServiceTiers *availableservicetiers.AvailableServiceTiersClient + Clusters *clusters.ClustersClient + DataExport *dataexport.DataExportClient + DataSources *datasources.DataSourcesClient + DeletedWorkspaces *deletedworkspaces.DeletedWorkspacesClient + IntelligencePacks *intelligencepacks.IntelligencePacksClient + LinkedServices *linkedservices.LinkedServicesClient + LinkedStorageAccounts *linkedstorageaccounts.LinkedStorageAccountsClient + QueryPackQueries *querypackqueries.QueryPackQueriesClient + QueryPacks *querypacks.QueryPacksClient + SavedSearches *savedsearches.SavedSearchesClient + StorageInsights *storageinsights.StorageInsightsClient + Tables *tables.TablesClient + Workspaces *workspaces.WorkspacesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + availableServiceTiersClient, err := availableservicetiers.NewAvailableServiceTiersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AvailableServiceTiers client: %+v", err) + } + configureFunc(availableServiceTiersClient.Client) + + clustersClient, err := clusters.NewClustersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Clusters client: %+v", err) + } + configureFunc(clustersClient.Client) + + dataExportClient, err := dataexport.NewDataExportClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataExport client: %+v", err) + } + configureFunc(dataExportClient.Client) + + dataSourcesClient, err := datasources.NewDataSourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataSources client: %+v", err) + } + configureFunc(dataSourcesClient.Client) + + deletedWorkspacesClient, err := deletedworkspaces.NewDeletedWorkspacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeletedWorkspaces client: %+v", err) + } + configureFunc(deletedWorkspacesClient.Client) + + intelligencePacksClient, err := intelligencepacks.NewIntelligencePacksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IntelligencePacks client: %+v", err) + } + configureFunc(intelligencePacksClient.Client) + + linkedServicesClient, err := linkedservices.NewLinkedServicesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LinkedServices client: %+v", err) + } + configureFunc(linkedServicesClient.Client) + + linkedStorageAccountsClient, err := linkedstorageaccounts.NewLinkedStorageAccountsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LinkedStorageAccounts client: %+v", err) + } + configureFunc(linkedStorageAccountsClient.Client) + + queryPackQueriesClient, err := querypackqueries.NewQueryPackQueriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building QueryPackQueries client: %+v", err) + } + configureFunc(queryPackQueriesClient.Client) + + queryPacksClient, err := querypacks.NewQueryPacksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building QueryPacks client: %+v", err) + } + configureFunc(queryPacksClient.Client) + + savedSearchesClient, err := savedsearches.NewSavedSearchesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SavedSearches client: %+v", err) + } + configureFunc(savedSearchesClient.Client) + + storageInsightsClient, err := storageinsights.NewStorageInsightsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StorageInsights client: %+v", err) + } + configureFunc(storageInsightsClient.Client) + + tablesClient, err := tables.NewTablesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Tables client: %+v", err) + } + configureFunc(tablesClient.Client) + + workspacesClient, err := workspaces.NewWorkspacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Workspaces client: %+v", err) + } + configureFunc(workspacesClient.Client) + + return &Client{ + AvailableServiceTiers: availableServiceTiersClient, + Clusters: clustersClient, + DataExport: dataExportClient, + DataSources: dataSourcesClient, + DeletedWorkspaces: deletedWorkspacesClient, + IntelligencePacks: intelligencePacksClient, + LinkedServices: linkedServicesClient, + LinkedStorageAccounts: linkedStorageAccountsClient, + QueryPackQueries: queryPackQueriesClient, + QueryPacks: queryPacksClient, + SavedSearches: savedSearchesClient, + StorageInsights: storageInsightsClient, + Tables: tablesClient, + Workspaces: workspacesClient, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/README.md b/resource-manager/operationalinsights/2025-02-01/clusters/README.md new file mode 100644 index 00000000000..be480340521 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/clusters` Documentation + +The `clusters` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/clusters" +``` + + +### Client Initialization + +```go +client := clusters.NewClustersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ClustersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterName") + +payload := clusters.Cluster{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ClustersClient.Delete` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterName") + +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", "clusterName") + +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.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `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.Update` + +```go +ctx := context.TODO() +id := clusters.NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterName") + +payload := clusters.ClusterPatch{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/client.go b/resource-manager/operationalinsights/2025-02-01/clusters/client.go new file mode 100644 index 00000000000..4ead092b486 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/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.NewClient(sdkApi, "clusters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ClustersClient: %+v", err) + } + + return &ClustersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/constants.go b/resource-manager/operationalinsights/2025-02-01/clusters/constants.go new file mode 100644 index 00000000000..abd818b7a42 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/constants.go @@ -0,0 +1,239 @@ +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 BillingType string + +const ( + BillingTypeCluster BillingType = "Cluster" + BillingTypeWorkspaces BillingType = "Workspaces" +) + +func PossibleValuesForBillingType() []string { + return []string{ + string(BillingTypeCluster), + string(BillingTypeWorkspaces), + } +} + +func (s *BillingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBillingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBillingType(input string) (*BillingType, error) { + vals := map[string]BillingType{ + "cluster": BillingTypeCluster, + "workspaces": BillingTypeWorkspaces, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BillingType(input) + return &out, nil +} + +type Capacity int64 + +const ( + CapacityFiveHundred Capacity = 500 + CapacityFiveThousand Capacity = 5000 + CapacityFiveZeroThousand Capacity = 50000 + CapacityFourHundred Capacity = 400 + CapacityOneHundred Capacity = 100 + CapacityOneThousand Capacity = 1000 + CapacityOneZeroThousand Capacity = 10000 + CapacityThreeHundred Capacity = 300 + CapacityTwoFiveThousand Capacity = 25000 + CapacityTwoHundred Capacity = 200 + CapacityTwoThousand Capacity = 2000 +) + +func PossibleValuesForCapacity() []int64 { + return []int64{ + int64(CapacityFiveHundred), + int64(CapacityFiveThousand), + int64(CapacityFiveZeroThousand), + int64(CapacityFourHundred), + int64(CapacityOneHundred), + int64(CapacityOneThousand), + int64(CapacityOneZeroThousand), + int64(CapacityThreeHundred), + int64(CapacityTwoFiveThousand), + int64(CapacityTwoHundred), + int64(CapacityTwoThousand), + } +} + +type ClusterEntityStatus string + +const ( + ClusterEntityStatusCanceled ClusterEntityStatus = "Canceled" + ClusterEntityStatusCreating ClusterEntityStatus = "Creating" + ClusterEntityStatusDeleting ClusterEntityStatus = "Deleting" + ClusterEntityStatusFailed ClusterEntityStatus = "Failed" + ClusterEntityStatusProvisioningAccount ClusterEntityStatus = "ProvisioningAccount" + ClusterEntityStatusSucceeded ClusterEntityStatus = "Succeeded" + ClusterEntityStatusUpdating ClusterEntityStatus = "Updating" +) + +func PossibleValuesForClusterEntityStatus() []string { + return []string{ + string(ClusterEntityStatusCanceled), + string(ClusterEntityStatusCreating), + string(ClusterEntityStatusDeleting), + string(ClusterEntityStatusFailed), + string(ClusterEntityStatusProvisioningAccount), + string(ClusterEntityStatusSucceeded), + string(ClusterEntityStatusUpdating), + } +} + +func (s *ClusterEntityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterEntityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusterEntityStatus(input string) (*ClusterEntityStatus, error) { + vals := map[string]ClusterEntityStatus{ + "canceled": ClusterEntityStatusCanceled, + "creating": ClusterEntityStatusCreating, + "deleting": ClusterEntityStatusDeleting, + "failed": ClusterEntityStatusFailed, + "provisioningaccount": ClusterEntityStatusProvisioningAccount, + "succeeded": ClusterEntityStatusSucceeded, + "updating": ClusterEntityStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusterEntityStatus(input) + return &out, nil +} + +type ClusterReplicationState string + +const ( + ClusterReplicationStateCanceled ClusterReplicationState = "Canceled" + ClusterReplicationStateDisableRequested ClusterReplicationState = "DisableRequested" + ClusterReplicationStateDisabling ClusterReplicationState = "Disabling" + ClusterReplicationStateEnableRequested ClusterReplicationState = "EnableRequested" + ClusterReplicationStateEnabling ClusterReplicationState = "Enabling" + ClusterReplicationStateFailed ClusterReplicationState = "Failed" + ClusterReplicationStateRollbackRequested ClusterReplicationState = "RollbackRequested" + ClusterReplicationStateRollingBack ClusterReplicationState = "RollingBack" + ClusterReplicationStateSucceeded ClusterReplicationState = "Succeeded" +) + +func PossibleValuesForClusterReplicationState() []string { + return []string{ + string(ClusterReplicationStateCanceled), + string(ClusterReplicationStateDisableRequested), + string(ClusterReplicationStateDisabling), + string(ClusterReplicationStateEnableRequested), + string(ClusterReplicationStateEnabling), + string(ClusterReplicationStateFailed), + string(ClusterReplicationStateRollbackRequested), + string(ClusterReplicationStateRollingBack), + string(ClusterReplicationStateSucceeded), + } +} + +func (s *ClusterReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusterReplicationState(input string) (*ClusterReplicationState, error) { + vals := map[string]ClusterReplicationState{ + "canceled": ClusterReplicationStateCanceled, + "disablerequested": ClusterReplicationStateDisableRequested, + "disabling": ClusterReplicationStateDisabling, + "enablerequested": ClusterReplicationStateEnableRequested, + "enabling": ClusterReplicationStateEnabling, + "failed": ClusterReplicationStateFailed, + "rollbackrequested": ClusterReplicationStateRollbackRequested, + "rollingback": ClusterReplicationStateRollingBack, + "succeeded": ClusterReplicationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusterReplicationState(input) + return &out, nil +} + +type ClusterSkuNameEnum string + +const ( + ClusterSkuNameEnumCapacityReservation ClusterSkuNameEnum = "CapacityReservation" +) + +func PossibleValuesForClusterSkuNameEnum() []string { + return []string{ + string(ClusterSkuNameEnumCapacityReservation), + } +} + +func (s *ClusterSkuNameEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterSkuNameEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusterSkuNameEnum(input string) (*ClusterSkuNameEnum, error) { + vals := map[string]ClusterSkuNameEnum{ + "capacityreservation": ClusterSkuNameEnumCapacityReservation, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusterSkuNameEnum(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/id_cluster.go b/resource-manager/operationalinsights/2025-02-01/clusters/id_cluster.go new file mode 100644 index 00000000000..0bb42eab67c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/id_cluster.go @@ -0,0 +1,130 @@ +package clusters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ClusterId{}) +} + +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.OperationalInsights/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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticClusters", "clusters", "clusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterName"), + } +} + +// 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/operationalinsights/2025-02-01/clusters/id_cluster_test.go b/resource-manager/operationalinsights/2025-02-01/clusters/id_cluster_test.go new file mode 100644 index 00000000000..c450b8197c7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/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", "clusterName") + + 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 != "clusterName" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterName") + } +} + +func TestFormatClusterID(t *testing.T) { + actual := NewClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters/clusterName" + 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters/clusterName", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters/clusterName/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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/cLuStErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters/clusterName", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/clusters/clusterName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/cLuStErS/cLuStErNaMe", + Expected: &ClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/cLuStErS/cLuStErNaMe/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/operationalinsights/2025-02-01/clusters/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/clusters/method_createorupdate.go new file mode 100644 index 00000000000..c4896586cde --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/method_createorupdate.go @@ -0,0 +1,75 @@ +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 CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +// CreateOrUpdate ... +func (c ClustersClient) CreateOrUpdate(ctx context.Context, id ClusterId, input Cluster) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ClustersClient) CreateOrUpdateThenPoll(ctx context.Context, id ClusterId, input Cluster) 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/operationalinsights/2025-02-01/clusters/method_delete.go b/resource-manager/operationalinsights/2025-02-01/clusters/method_delete.go new file mode 100644 index 00000000000..13e2610ffd6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/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/operationalinsights/2025-02-01/clusters/method_get.go b/resource-manager/operationalinsights/2025-02-01/clusters/method_get.go new file mode 100644 index 00000000000..8265f74e863 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/method_get.go @@ -0,0 +1,53 @@ +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/operationalinsights/2025-02-01/clusters/method_list.go b/resource-manager/operationalinsights/2025-02-01/clusters/method_list.go new file mode 100644 index 00000000000..84041722337 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/method_list.go @@ -0,0 +1,106 @@ +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Cluster +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ClustersClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/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 +} + +// ListComplete retrieves all the results into a single object +func (c ClustersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClustersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/method_listbyresourcegroup.go b/resource-manager/operationalinsights/2025-02-01/clusters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..2bd22023e91 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +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 +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/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 { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/method_update.go b/resource-manager/operationalinsights/2025-02-01/clusters/method_update.go new file mode 100644 index 00000000000..55fe3507602 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/method_update.go @@ -0,0 +1,75 @@ +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 UpdateOperationResponse struct { + Poller pollers.Poller + 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.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 ClustersClient) UpdateThenPoll(ctx context.Context, id ClusterId, input ClusterPatch) 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/operationalinsights/2025-02-01/clusters/model_associatedworkspace.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_associatedworkspace.go new file mode 100644 index 00000000000..c66b56d47f7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_associatedworkspace.go @@ -0,0 +1,29 @@ +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 AssociatedWorkspace struct { + AssociateDate *string `json:"associateDate,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + WorkspaceId *string `json:"workspaceId,omitempty"` + WorkspaceName *string `json:"workspaceName,omitempty"` +} + +func (o *AssociatedWorkspace) GetAssociateDateAsTime() (*time.Time, error) { + if o.AssociateDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AssociateDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *AssociatedWorkspace) SetAssociateDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AssociateDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_capacityreservationproperties.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_capacityreservationproperties.go new file mode 100644 index 00000000000..47b40bf71f4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_capacityreservationproperties.go @@ -0,0 +1,27 @@ +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 CapacityReservationProperties struct { + LastSkuUpdate *string `json:"lastSkuUpdate,omitempty"` + MinCapacity *int64 `json:"minCapacity,omitempty"` +} + +func (o *CapacityReservationProperties) GetLastSkuUpdateAsTime() (*time.Time, error) { + if o.LastSkuUpdate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSkuUpdate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CapacityReservationProperties) SetLastSkuUpdateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSkuUpdate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_cluster.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_cluster.go new file mode 100644 index 00000000000..be303015217 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_cluster.go @@ -0,0 +1,19 @@ +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 Cluster struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ClusterProperties `json:"properties,omitempty"` + Sku *ClusterSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatch.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatch.go new file mode 100644 index 00000000000..9524c09d0bc --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatch.go @@ -0,0 +1,15 @@ +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.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ClusterPatchProperties `json:"properties,omitempty"` + Sku *ClusterSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatchproperties.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatchproperties.go new file mode 100644 index 00000000000..7960ea89b28 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterpatchproperties.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 ClusterPatchProperties struct { + BillingType *BillingType `json:"billingType,omitempty"` + KeyVaultProperties *KeyVaultProperties `json:"keyVaultProperties,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterproperties.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterproperties.go new file mode 100644 index 00000000000..24d43091d19 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterproperties.go @@ -0,0 +1,48 @@ +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 { + AssociatedWorkspaces *[]AssociatedWorkspace `json:"associatedWorkspaces,omitempty"` + BillingType *BillingType `json:"billingType,omitempty"` + CapacityReservationProperties *CapacityReservationProperties `json:"capacityReservationProperties,omitempty"` + ClusterId *string `json:"clusterId,omitempty"` + CreatedDate *string `json:"createdDate,omitempty"` + IsAvailabilityZonesEnabled *bool `json:"isAvailabilityZonesEnabled,omitempty"` + IsDoubleEncryptionEnabled *bool `json:"isDoubleEncryptionEnabled,omitempty"` + KeyVaultProperties *KeyVaultProperties `json:"keyVaultProperties,omitempty"` + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + ProvisioningState *ClusterEntityStatus `json:"provisioningState,omitempty"` + Replication *ClusterReplicationProperties `json:"replication,omitempty"` +} + +func (o *ClusterProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *ClusterProperties) GetLastModifiedDateAsTime() (*time.Time, error) { + if o.LastModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterProperties) SetLastModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterreplicationproperties.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterreplicationproperties.go new file mode 100644 index 00000000000..15d18e05825 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_clusterreplicationproperties.go @@ -0,0 +1,43 @@ +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 ClusterReplicationProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + IsAvailabilityZonesEnabled *bool `json:"isAvailabilityZonesEnabled,omitempty"` + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + Location *string `json:"location,omitempty"` + ProvisioningState *ClusterReplicationState `json:"provisioningState,omitempty"` +} + +func (o *ClusterReplicationProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterReplicationProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *ClusterReplicationProperties) GetLastModifiedDateAsTime() (*time.Time, error) { + if o.LastModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ClusterReplicationProperties) SetLastModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_clustersku.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_clustersku.go new file mode 100644 index 00000000000..6f279c158d7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_clustersku.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 ClusterSku struct { + Capacity *Capacity `json:"capacity,omitempty"` + Name *ClusterSkuNameEnum `json:"name,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/model_keyvaultproperties.go b/resource-manager/operationalinsights/2025-02-01/clusters/model_keyvaultproperties.go new file mode 100644 index 00000000000..b2cfa77b7d4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/model_keyvaultproperties.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 KeyVaultProperties struct { + KeyName *string `json:"keyName,omitempty"` + KeyRsaSize *int64 `json:"keyRsaSize,omitempty"` + KeyVaultUri *string `json:"keyVaultUri,omitempty"` + KeyVersion *string `json:"keyVersion,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/clusters/predicates.go b/resource-manager/operationalinsights/2025-02-01/clusters/predicates.go new file mode 100644 index 00000000000..cc13b7c6220 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/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/operationalinsights/2025-02-01/clusters/version.go b/resource-manager/operationalinsights/2025-02-01/clusters/version.go new file mode 100644 index 00000000000..5796210f639 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/clusters/version.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. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/clusters/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/README.md b/resource-manager/operationalinsights/2025-02-01/dataexport/README.md new file mode 100644 index 00000000000..6d6f52f6439 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/dataexport` Documentation + +The `dataexport` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/dataexport" +``` + + +### Client Initialization + +```go +client := dataexport.NewDataExportClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataExportClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := dataexport.NewDataExportID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataExportName") + +payload := dataexport.DataExport{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataExportClient.Delete` + +```go +ctx := context.TODO() +id := dataexport.NewDataExportID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataExportName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataExportClient.Get` + +```go +ctx := context.TODO() +id := dataexport.NewDataExportID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataExportName") + +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: `DataExportClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := dataexport.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/client.go b/resource-manager/operationalinsights/2025-02-01/dataexport/client.go new file mode 100644 index 00000000000..5113e66d9c0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/client.go @@ -0,0 +1,26 @@ +package dataexport + +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 DataExportClient struct { + Client *resourcemanager.Client +} + +func NewDataExportClientWithBaseURI(sdkApi sdkEnv.Api) (*DataExportClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "dataexport", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataExportClient: %+v", err) + } + + return &DataExportClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/constants.go b/resource-manager/operationalinsights/2025-02-01/dataexport/constants.go new file mode 100644 index 00000000000..c103dc9f1ef --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/constants.go @@ -0,0 +1,51 @@ +package dataexport + +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 Type string + +const ( + TypeEventHub Type = "EventHub" + TypeStorageAccount Type = "StorageAccount" +) + +func PossibleValuesForType() []string { + return []string{ + string(TypeEventHub), + string(TypeStorageAccount), + } +} + +func (s *Type) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseType(input string) (*Type, error) { + vals := map[string]Type{ + "eventhub": TypeEventHub, + "storageaccount": TypeStorageAccount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Type(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport.go b/resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport.go new file mode 100644 index 00000000000..a8de549cff8 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport.go @@ -0,0 +1,139 @@ +package dataexport + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DataExportId{}) +} + +var _ resourceids.ResourceId = &DataExportId{} + +// DataExportId is a struct representing the Resource ID for a Data Export +type DataExportId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + DataExportName string +} + +// NewDataExportID returns a new DataExportId struct +func NewDataExportID(subscriptionId string, resourceGroupName string, workspaceName string, dataExportName string) DataExportId { + return DataExportId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + DataExportName: dataExportName, + } +} + +// ParseDataExportID parses 'input' into a DataExportId +func ParseDataExportID(input string) (*DataExportId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataExportId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataExportId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDataExportIDInsensitively parses 'input' case-insensitively into a DataExportId +// note: this method should only be used for API response data and not user input +func ParseDataExportIDInsensitively(input string) (*DataExportId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataExportId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataExportId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DataExportId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.DataExportName, ok = input.Parsed["dataExportName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dataExportName", input) + } + + return nil +} + +// ValidateDataExportID checks that 'input' can be parsed as a Data Export ID +func ValidateDataExportID(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 := ParseDataExportID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Data Export ID +func (id DataExportId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/dataExports/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.DataExportName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Data Export ID +func (id DataExportId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticDataExports", "dataExports", "dataExports"), + resourceids.UserSpecifiedSegment("dataExportName", "dataExportName"), + } +} + +// String returns a human-readable description of this Data Export ID +func (id DataExportId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Data Export Name: %q", id.DataExportName), + } + return fmt.Sprintf("Data Export (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport_test.go b/resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport_test.go new file mode 100644 index 00000000000..d88423d09bc --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/id_dataexport_test.go @@ -0,0 +1,327 @@ +package dataexport + +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 = &DataExportId{} + +func TestNewDataExportID(t *testing.T) { + id := NewDataExportID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataExportName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.DataExportName != "dataExportName" { + t.Fatalf("Expected %q but got %q for Segment 'DataExportName'", id.DataExportName, "dataExportName") + } +} + +func TestFormatDataExportID(t *testing.T) { + actual := NewDataExportID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataExportName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports/dataExportName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDataExportID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataExportId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports/dataExportName", + Expected: &DataExportId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + DataExportName: "dataExportName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports/dataExportName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataExportID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataExportName != v.Expected.DataExportName { + t.Fatalf("Expected %q but got %q for DataExportName", v.Expected.DataExportName, actual.DataExportName) + } + + } +} + +func TestParseDataExportIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataExportId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/dAtAeXpOrTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports/dataExportName", + Expected: &DataExportId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + DataExportName: "dataExportName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataExports/dataExportName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/dAtAeXpOrTs/dAtAeXpOrTnAmE", + Expected: &DataExportId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + DataExportName: "dAtAeXpOrTnAmE", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/dAtAeXpOrTs/dAtAeXpOrTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataExportIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataExportName != v.Expected.DataExportName { + t.Fatalf("Expected %q but got %q for DataExportName", v.Expected.DataExportName, actual.DataExportName) + } + + } +} + +func TestSegmentsForDataExportId(t *testing.T) { + segments := DataExportId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DataExportId 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/operationalinsights/2025-02-01/dataexport/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace.go new file mode 100644 index 00000000000..c2506a768f9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace.go @@ -0,0 +1,130 @@ +package dataexport + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace_test.go new file mode 100644 index 00000000000..5373c883c57 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/id_workspace_test.go @@ -0,0 +1,282 @@ +package dataexport + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/dataexport/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/dataexport/method_createorupdate.go new file mode 100644 index 00000000000..6715bd687d9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/method_createorupdate.go @@ -0,0 +1,58 @@ +package dataexport + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataExport +} + +// CreateOrUpdate ... +func (c DataExportClient) CreateOrUpdate(ctx context.Context, id DataExportId, input DataExport) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DataExport + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/method_delete.go b/resource-manager/operationalinsights/2025-02-01/dataexport/method_delete.go new file mode 100644 index 00000000000..0955b9b73ef --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/method_delete.go @@ -0,0 +1,46 @@ +package dataexport + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataExportClient) Delete(ctx context.Context, id DataExportId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/method_get.go b/resource-manager/operationalinsights/2025-02-01/dataexport/method_get.go new file mode 100644 index 00000000000..31181e61127 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/method_get.go @@ -0,0 +1,53 @@ +package dataexport + +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 *DataExport +} + +// Get ... +func (c DataExportClient) Get(ctx context.Context, id DataExportId) (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 DataExport + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/dataexport/method_listbyworkspace.go new file mode 100644 index 00000000000..aa783d2a041 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/method_listbyworkspace.go @@ -0,0 +1,54 @@ +package dataexport + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataExportListResult +} + +// ListByWorkspace ... +func (c DataExportClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dataExports", 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 DataExportListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexport.go b/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexport.go new file mode 100644 index 00000000000..b7f7ca1ec04 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexport.go @@ -0,0 +1,11 @@ +package dataexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataExport struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataExportProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportlistresult.go b/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportlistresult.go new file mode 100644 index 00000000000..0944681ef9d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportlistresult.go @@ -0,0 +1,8 @@ +package dataexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataExportListResult struct { + Value *[]DataExport `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportproperties.go b/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportproperties.go new file mode 100644 index 00000000000..f3677b9395d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/model_dataexportproperties.go @@ -0,0 +1,13 @@ +package dataexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataExportProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + DataExportId *string `json:"dataExportId,omitempty"` + Destination *Destination `json:"destination,omitempty"` + Enable *bool `json:"enable,omitempty"` + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + TableNames []string `json:"tableNames"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/model_destination.go b/resource-manager/operationalinsights/2025-02-01/dataexport/model_destination.go new file mode 100644 index 00000000000..534e7081b71 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/model_destination.go @@ -0,0 +1,10 @@ +package dataexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Destination struct { + MetaData *DestinationMetaData `json:"metaData,omitempty"` + ResourceId string `json:"resourceId"` + Type *Type `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/model_destinationmetadata.go b/resource-manager/operationalinsights/2025-02-01/dataexport/model_destinationmetadata.go new file mode 100644 index 00000000000..abf5e37918e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/model_destinationmetadata.go @@ -0,0 +1,8 @@ +package dataexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DestinationMetaData struct { + EventHubName *string `json:"eventHubName,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/dataexport/version.go b/resource-manager/operationalinsights/2025-02-01/dataexport/version.go new file mode 100644 index 00000000000..6d31ef56c62 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/dataexport/version.go @@ -0,0 +1,10 @@ +package dataexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/dataexport/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/README.md b/resource-manager/operationalinsights/2025-02-01/datasources/README.md new file mode 100644 index 00000000000..3753c1d9a7d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/datasources` Documentation + +The `datasources` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/datasources" +``` + + +### Client Initialization + +```go +client := datasources.NewDataSourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataSourcesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := datasources.NewDataSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataSourceName") + +payload := datasources.DataSource{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataSourcesClient.Delete` + +```go +ctx := context.TODO() +id := datasources.NewDataSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataSourceName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataSourcesClient.Get` + +```go +ctx := context.TODO() +id := datasources.NewDataSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataSourceName") + +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: `DataSourcesClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := datasources.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +// alternatively `client.ListByWorkspace(ctx, id, datasources.DefaultListByWorkspaceOperationOptions())` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id, datasources.DefaultListByWorkspaceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/client.go b/resource-manager/operationalinsights/2025-02-01/datasources/client.go new file mode 100644 index 00000000000..ab9ec31dddc --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/client.go @@ -0,0 +1,26 @@ +package datasources + +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 DataSourcesClient struct { + Client *resourcemanager.Client +} + +func NewDataSourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*DataSourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "datasources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataSourcesClient: %+v", err) + } + + return &DataSourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/constants.go b/resource-manager/operationalinsights/2025-02-01/datasources/constants.go new file mode 100644 index 00000000000..91241eeca9f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/constants.go @@ -0,0 +1,144 @@ +package datasources + +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 DataSourceKind string + +const ( + DataSourceKindApplicationInsights DataSourceKind = "ApplicationInsights" + DataSourceKindAzureActivityLog DataSourceKind = "AzureActivityLog" + DataSourceKindAzureAuditLog DataSourceKind = "AzureAuditLog" + DataSourceKindChangeTrackingContentLocation DataSourceKind = "ChangeTrackingContentLocation" + DataSourceKindChangeTrackingCustomPath DataSourceKind = "ChangeTrackingCustomPath" + DataSourceKindChangeTrackingDataTypeConfiguration DataSourceKind = "ChangeTrackingDataTypeConfiguration" + DataSourceKindChangeTrackingDefaultRegistry DataSourceKind = "ChangeTrackingDefaultRegistry" + DataSourceKindChangeTrackingLinuxPath DataSourceKind = "ChangeTrackingLinuxPath" + DataSourceKindChangeTrackingPath DataSourceKind = "ChangeTrackingPath" + DataSourceKindChangeTrackingRegistry DataSourceKind = "ChangeTrackingRegistry" + DataSourceKindChangeTrackingServices DataSourceKind = "ChangeTrackingServices" + DataSourceKindCustomLog DataSourceKind = "CustomLog" + DataSourceKindCustomLogCollection DataSourceKind = "CustomLogCollection" + DataSourceKindDnsAnalytics DataSourceKind = "DnsAnalytics" + DataSourceKindGenericDataSource DataSourceKind = "GenericDataSource" + DataSourceKindIISLogs DataSourceKind = "IISLogs" + DataSourceKindImportComputerGroup DataSourceKind = "ImportComputerGroup" + DataSourceKindItsm DataSourceKind = "Itsm" + DataSourceKindLinuxChangeTrackingPath DataSourceKind = "LinuxChangeTrackingPath" + DataSourceKindLinuxPerformanceCollection DataSourceKind = "LinuxPerformanceCollection" + DataSourceKindLinuxPerformanceObject DataSourceKind = "LinuxPerformanceObject" + DataSourceKindLinuxSyslog DataSourceKind = "LinuxSyslog" + DataSourceKindLinuxSyslogCollection DataSourceKind = "LinuxSyslogCollection" + DataSourceKindNetworkMonitoring DataSourceKind = "NetworkMonitoring" + DataSourceKindOfficeThreeSixFive DataSourceKind = "Office365" + DataSourceKindSecurityCenterSecurityWindowsBaselineConfiguration DataSourceKind = "SecurityCenterSecurityWindowsBaselineConfiguration" + DataSourceKindSecurityEventCollectionConfiguration DataSourceKind = "SecurityEventCollectionConfiguration" + DataSourceKindSecurityInsightsSecurityEventCollectionConfiguration DataSourceKind = "SecurityInsightsSecurityEventCollectionConfiguration" + DataSourceKindSecurityWindowsBaselineConfiguration DataSourceKind = "SecurityWindowsBaselineConfiguration" + DataSourceKindSqlDataClassification DataSourceKind = "SqlDataClassification" + DataSourceKindWindowsEvent DataSourceKind = "WindowsEvent" + DataSourceKindWindowsPerformanceCounter DataSourceKind = "WindowsPerformanceCounter" + DataSourceKindWindowsTelemetry DataSourceKind = "WindowsTelemetry" +) + +func PossibleValuesForDataSourceKind() []string { + return []string{ + string(DataSourceKindApplicationInsights), + string(DataSourceKindAzureActivityLog), + string(DataSourceKindAzureAuditLog), + string(DataSourceKindChangeTrackingContentLocation), + string(DataSourceKindChangeTrackingCustomPath), + string(DataSourceKindChangeTrackingDataTypeConfiguration), + string(DataSourceKindChangeTrackingDefaultRegistry), + string(DataSourceKindChangeTrackingLinuxPath), + string(DataSourceKindChangeTrackingPath), + string(DataSourceKindChangeTrackingRegistry), + string(DataSourceKindChangeTrackingServices), + string(DataSourceKindCustomLog), + string(DataSourceKindCustomLogCollection), + string(DataSourceKindDnsAnalytics), + string(DataSourceKindGenericDataSource), + string(DataSourceKindIISLogs), + string(DataSourceKindImportComputerGroup), + string(DataSourceKindItsm), + string(DataSourceKindLinuxChangeTrackingPath), + string(DataSourceKindLinuxPerformanceCollection), + string(DataSourceKindLinuxPerformanceObject), + string(DataSourceKindLinuxSyslog), + string(DataSourceKindLinuxSyslogCollection), + string(DataSourceKindNetworkMonitoring), + string(DataSourceKindOfficeThreeSixFive), + string(DataSourceKindSecurityCenterSecurityWindowsBaselineConfiguration), + string(DataSourceKindSecurityEventCollectionConfiguration), + string(DataSourceKindSecurityInsightsSecurityEventCollectionConfiguration), + string(DataSourceKindSecurityWindowsBaselineConfiguration), + string(DataSourceKindSqlDataClassification), + string(DataSourceKindWindowsEvent), + string(DataSourceKindWindowsPerformanceCounter), + string(DataSourceKindWindowsTelemetry), + } +} + +func (s *DataSourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataSourceKind(input string) (*DataSourceKind, error) { + vals := map[string]DataSourceKind{ + "applicationinsights": DataSourceKindApplicationInsights, + "azureactivitylog": DataSourceKindAzureActivityLog, + "azureauditlog": DataSourceKindAzureAuditLog, + "changetrackingcontentlocation": DataSourceKindChangeTrackingContentLocation, + "changetrackingcustompath": DataSourceKindChangeTrackingCustomPath, + "changetrackingdatatypeconfiguration": DataSourceKindChangeTrackingDataTypeConfiguration, + "changetrackingdefaultregistry": DataSourceKindChangeTrackingDefaultRegistry, + "changetrackinglinuxpath": DataSourceKindChangeTrackingLinuxPath, + "changetrackingpath": DataSourceKindChangeTrackingPath, + "changetrackingregistry": DataSourceKindChangeTrackingRegistry, + "changetrackingservices": DataSourceKindChangeTrackingServices, + "customlog": DataSourceKindCustomLog, + "customlogcollection": DataSourceKindCustomLogCollection, + "dnsanalytics": DataSourceKindDnsAnalytics, + "genericdatasource": DataSourceKindGenericDataSource, + "iislogs": DataSourceKindIISLogs, + "importcomputergroup": DataSourceKindImportComputerGroup, + "itsm": DataSourceKindItsm, + "linuxchangetrackingpath": DataSourceKindLinuxChangeTrackingPath, + "linuxperformancecollection": DataSourceKindLinuxPerformanceCollection, + "linuxperformanceobject": DataSourceKindLinuxPerformanceObject, + "linuxsyslog": DataSourceKindLinuxSyslog, + "linuxsyslogcollection": DataSourceKindLinuxSyslogCollection, + "networkmonitoring": DataSourceKindNetworkMonitoring, + "office365": DataSourceKindOfficeThreeSixFive, + "securitycentersecuritywindowsbaselineconfiguration": DataSourceKindSecurityCenterSecurityWindowsBaselineConfiguration, + "securityeventcollectionconfiguration": DataSourceKindSecurityEventCollectionConfiguration, + "securityinsightssecurityeventcollectionconfiguration": DataSourceKindSecurityInsightsSecurityEventCollectionConfiguration, + "securitywindowsbaselineconfiguration": DataSourceKindSecurityWindowsBaselineConfiguration, + "sqldataclassification": DataSourceKindSqlDataClassification, + "windowsevent": DataSourceKindWindowsEvent, + "windowsperformancecounter": DataSourceKindWindowsPerformanceCounter, + "windowstelemetry": DataSourceKindWindowsTelemetry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSourceKind(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/id_datasource.go b/resource-manager/operationalinsights/2025-02-01/datasources/id_datasource.go new file mode 100644 index 00000000000..2a95ddb8e6c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/id_datasource.go @@ -0,0 +1,139 @@ +package datasources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DataSourceId{}) +} + +var _ resourceids.ResourceId = &DataSourceId{} + +// DataSourceId is a struct representing the Resource ID for a Data Source +type DataSourceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + DataSourceName string +} + +// NewDataSourceID returns a new DataSourceId struct +func NewDataSourceID(subscriptionId string, resourceGroupName string, workspaceName string, dataSourceName string) DataSourceId { + return DataSourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + DataSourceName: dataSourceName, + } +} + +// ParseDataSourceID parses 'input' into a DataSourceId +func ParseDataSourceID(input string) (*DataSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataSourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataSourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDataSourceIDInsensitively parses 'input' case-insensitively into a DataSourceId +// note: this method should only be used for API response data and not user input +func ParseDataSourceIDInsensitively(input string) (*DataSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataSourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataSourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DataSourceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.DataSourceName, ok = input.Parsed["dataSourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dataSourceName", input) + } + + return nil +} + +// ValidateDataSourceID checks that 'input' can be parsed as a Data Source ID +func ValidateDataSourceID(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 := ParseDataSourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Data Source ID +func (id DataSourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/dataSources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.DataSourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Data Source ID +func (id DataSourceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticDataSources", "dataSources", "dataSources"), + resourceids.UserSpecifiedSegment("dataSourceName", "dataSourceName"), + } +} + +// String returns a human-readable description of this Data Source ID +func (id DataSourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Data Source Name: %q", id.DataSourceName), + } + return fmt.Sprintf("Data Source (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/id_datasource_test.go b/resource-manager/operationalinsights/2025-02-01/datasources/id_datasource_test.go new file mode 100644 index 00000000000..13a6a7a7e0c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/id_datasource_test.go @@ -0,0 +1,327 @@ +package datasources + +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 = &DataSourceId{} + +func TestNewDataSourceID(t *testing.T) { + id := NewDataSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataSourceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.DataSourceName != "dataSourceName" { + t.Fatalf("Expected %q but got %q for Segment 'DataSourceName'", id.DataSourceName, "dataSourceName") + } +} + +func TestFormatDataSourceID(t *testing.T) { + actual := NewDataSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "dataSourceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources/dataSourceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDataSourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataSourceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources/dataSourceName", + Expected: &DataSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + DataSourceName: "dataSourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources/dataSourceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataSourceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataSourceName != v.Expected.DataSourceName { + t.Fatalf("Expected %q but got %q for DataSourceName", v.Expected.DataSourceName, actual.DataSourceName) + } + + } +} + +func TestParseDataSourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataSourceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/dAtAsOuRcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources/dataSourceName", + Expected: &DataSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + DataSourceName: "dataSourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/dataSources/dataSourceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/dAtAsOuRcEs/dAtAsOuRcEnAmE", + Expected: &DataSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + DataSourceName: "dAtAsOuRcEnAmE", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/dAtAsOuRcEs/dAtAsOuRcEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataSourceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataSourceName != v.Expected.DataSourceName { + t.Fatalf("Expected %q but got %q for DataSourceName", v.Expected.DataSourceName, actual.DataSourceName) + } + + } +} + +func TestSegmentsForDataSourceId(t *testing.T) { + segments := DataSourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DataSourceId 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/operationalinsights/2025-02-01/datasources/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/datasources/id_workspace.go new file mode 100644 index 00000000000..5325c571db5 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/id_workspace.go @@ -0,0 +1,130 @@ +package datasources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/datasources/id_workspace_test.go new file mode 100644 index 00000000000..a4e30459ef1 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/id_workspace_test.go @@ -0,0 +1,282 @@ +package datasources + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/datasources/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/datasources/method_createorupdate.go new file mode 100644 index 00000000000..0f409fcbaab --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/method_createorupdate.go @@ -0,0 +1,58 @@ +package datasources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataSource +} + +// CreateOrUpdate ... +func (c DataSourcesClient) CreateOrUpdate(ctx context.Context, id DataSourceId, input DataSource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DataSource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/method_delete.go b/resource-manager/operationalinsights/2025-02-01/datasources/method_delete.go new file mode 100644 index 00000000000..e997877cfd3 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/method_delete.go @@ -0,0 +1,47 @@ +package datasources + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DataSourcesClient) Delete(ctx context.Context, id DataSourceId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/method_get.go b/resource-manager/operationalinsights/2025-02-01/datasources/method_get.go new file mode 100644 index 00000000000..388310f131e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/method_get.go @@ -0,0 +1,53 @@ +package datasources + +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 *DataSource +} + +// Get ... +func (c DataSourcesClient) Get(ctx context.Context, id DataSourceId) (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 DataSource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/datasources/method_listbyworkspace.go new file mode 100644 index 00000000000..909910b2332 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/method_listbyworkspace.go @@ -0,0 +1,134 @@ +package datasources + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataSource +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataSource +} + +type ListByWorkspaceOperationOptions struct { + Filter *string +} + +func DefaultListByWorkspaceOperationOptions() ListByWorkspaceOperationOptions { + return ListByWorkspaceOperationOptions{} +} + +func (o ListByWorkspaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByWorkspaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByWorkspaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByWorkspace ... +func (c DataSourcesClient) ListByWorkspace(ctx context.Context, id WorkspaceId, options ListByWorkspaceOperationOptions) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/dataSources", 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 *[]DataSource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c DataSourcesClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId, options ListByWorkspaceOperationOptions) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, options, DataSourceOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataSourcesClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListByWorkspaceOperationOptions, predicate DataSourceOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]DataSource, 0) + + resp, err := c.ListByWorkspace(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/model_datasource.go b/resource-manager/operationalinsights/2025-02-01/datasources/model_datasource.go new file mode 100644 index 00000000000..e091f526268 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/model_datasource.go @@ -0,0 +1,14 @@ +package datasources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataSource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Kind DataSourceKind `json:"kind"` + Name *string `json:"name,omitempty"` + Properties interface{} `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/predicates.go b/resource-manager/operationalinsights/2025-02-01/datasources/predicates.go new file mode 100644 index 00000000000..1fa7b8ec8d5 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/predicates.go @@ -0,0 +1,37 @@ +package datasources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataSourceOperationPredicate struct { + Etag *string + Id *string + Name *string + Properties *interface{} + Type *string +} + +func (p DataSourceOperationPredicate) Matches(input DataSource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Properties != nil && *p.Properties != input.Properties { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/operationalinsights/2025-02-01/datasources/version.go b/resource-manager/operationalinsights/2025-02-01/datasources/version.go new file mode 100644 index 00000000000..d7ad2bcb4d4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/datasources/version.go @@ -0,0 +1,10 @@ +package datasources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/datasources/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/README.md b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/README.md new file mode 100644 index 00000000000..a75e4caca05 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/deletedworkspaces` Documentation + +The `deletedworkspaces` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/deletedworkspaces" +``` + + +### Client Initialization + +```go +client := deletedworkspaces.NewDeletedWorkspacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeletedWorkspacesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeletedWorkspacesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +read, err := client.ListByResourceGroup(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/client.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/client.go new file mode 100644 index 00000000000..dfd9fe59bb7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/client.go @@ -0,0 +1,26 @@ +package deletedworkspaces + +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 DeletedWorkspacesClient struct { + Client *resourcemanager.Client +} + +func NewDeletedWorkspacesClientWithBaseURI(sdkApi sdkEnv.Api) (*DeletedWorkspacesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "deletedworkspaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeletedWorkspacesClient: %+v", err) + } + + return &DeletedWorkspacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/constants.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/constants.go new file mode 100644 index 00000000000..0a8529f240d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/constants.go @@ -0,0 +1,363 @@ +package deletedworkspaces + +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 CapacityReservationLevel int64 + +const ( + CapacityReservationLevelFiveHundred CapacityReservationLevel = 500 + CapacityReservationLevelFiveThousand CapacityReservationLevel = 5000 + CapacityReservationLevelFiveZeroThousand CapacityReservationLevel = 50000 + CapacityReservationLevelFourHundred CapacityReservationLevel = 400 + CapacityReservationLevelOneHundred CapacityReservationLevel = 100 + CapacityReservationLevelOneThousand CapacityReservationLevel = 1000 + CapacityReservationLevelOneZeroThousand CapacityReservationLevel = 10000 + CapacityReservationLevelThreeHundred CapacityReservationLevel = 300 + CapacityReservationLevelTwoFiveThousand CapacityReservationLevel = 25000 + CapacityReservationLevelTwoHundred CapacityReservationLevel = 200 + CapacityReservationLevelTwoThousand CapacityReservationLevel = 2000 +) + +func PossibleValuesForCapacityReservationLevel() []int64 { + return []int64{ + int64(CapacityReservationLevelFiveHundred), + int64(CapacityReservationLevelFiveThousand), + int64(CapacityReservationLevelFiveZeroThousand), + int64(CapacityReservationLevelFourHundred), + int64(CapacityReservationLevelOneHundred), + int64(CapacityReservationLevelOneThousand), + int64(CapacityReservationLevelOneZeroThousand), + int64(CapacityReservationLevelThreeHundred), + int64(CapacityReservationLevelTwoFiveThousand), + int64(CapacityReservationLevelTwoHundred), + int64(CapacityReservationLevelTwoThousand), + } +} + +type DataIngestionStatus string + +const ( + DataIngestionStatusApproachingQuota DataIngestionStatus = "ApproachingQuota" + DataIngestionStatusForceOff DataIngestionStatus = "ForceOff" + DataIngestionStatusForceOn DataIngestionStatus = "ForceOn" + DataIngestionStatusOverQuota DataIngestionStatus = "OverQuota" + DataIngestionStatusRespectQuota DataIngestionStatus = "RespectQuota" + DataIngestionStatusSubscriptionSuspended DataIngestionStatus = "SubscriptionSuspended" +) + +func PossibleValuesForDataIngestionStatus() []string { + return []string{ + string(DataIngestionStatusApproachingQuota), + string(DataIngestionStatusForceOff), + string(DataIngestionStatusForceOn), + string(DataIngestionStatusOverQuota), + string(DataIngestionStatusRespectQuota), + string(DataIngestionStatusSubscriptionSuspended), + } +} + +func (s *DataIngestionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataIngestionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataIngestionStatus(input string) (*DataIngestionStatus, error) { + vals := map[string]DataIngestionStatus{ + "approachingquota": DataIngestionStatusApproachingQuota, + "forceoff": DataIngestionStatusForceOff, + "forceon": DataIngestionStatusForceOn, + "overquota": DataIngestionStatusOverQuota, + "respectquota": DataIngestionStatusRespectQuota, + "subscriptionsuspended": DataIngestionStatusSubscriptionSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataIngestionStatus(input) + return &out, nil +} + +type PublicNetworkAccessType string + +const ( + PublicNetworkAccessTypeDisabled PublicNetworkAccessType = "Disabled" + PublicNetworkAccessTypeEnabled PublicNetworkAccessType = "Enabled" +) + +func PossibleValuesForPublicNetworkAccessType() []string { + return []string{ + string(PublicNetworkAccessTypeDisabled), + string(PublicNetworkAccessTypeEnabled), + } +} + +func (s *PublicNetworkAccessType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccessType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccessType(input string) (*PublicNetworkAccessType, error) { + vals := map[string]PublicNetworkAccessType{ + "disabled": PublicNetworkAccessTypeDisabled, + "enabled": PublicNetworkAccessTypeEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccessType(input) + return &out, nil +} + +type WorkspaceEntityStatus string + +const ( + WorkspaceEntityStatusCanceled WorkspaceEntityStatus = "Canceled" + WorkspaceEntityStatusCreating WorkspaceEntityStatus = "Creating" + WorkspaceEntityStatusDeleting WorkspaceEntityStatus = "Deleting" + WorkspaceEntityStatusFailed WorkspaceEntityStatus = "Failed" + WorkspaceEntityStatusProvisioningAccount WorkspaceEntityStatus = "ProvisioningAccount" + WorkspaceEntityStatusSucceeded WorkspaceEntityStatus = "Succeeded" + WorkspaceEntityStatusUpdating WorkspaceEntityStatus = "Updating" +) + +func PossibleValuesForWorkspaceEntityStatus() []string { + return []string{ + string(WorkspaceEntityStatusCanceled), + string(WorkspaceEntityStatusCreating), + string(WorkspaceEntityStatusDeleting), + string(WorkspaceEntityStatusFailed), + string(WorkspaceEntityStatusProvisioningAccount), + string(WorkspaceEntityStatusSucceeded), + string(WorkspaceEntityStatusUpdating), + } +} + +func (s *WorkspaceEntityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceEntityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceEntityStatus(input string) (*WorkspaceEntityStatus, error) { + vals := map[string]WorkspaceEntityStatus{ + "canceled": WorkspaceEntityStatusCanceled, + "creating": WorkspaceEntityStatusCreating, + "deleting": WorkspaceEntityStatusDeleting, + "failed": WorkspaceEntityStatusFailed, + "provisioningaccount": WorkspaceEntityStatusProvisioningAccount, + "succeeded": WorkspaceEntityStatusSucceeded, + "updating": WorkspaceEntityStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceEntityStatus(input) + return &out, nil +} + +type WorkspaceFailoverState string + +const ( + WorkspaceFailoverStateActivating WorkspaceFailoverState = "Activating" + WorkspaceFailoverStateActive WorkspaceFailoverState = "Active" + WorkspaceFailoverStateDeactivating WorkspaceFailoverState = "Deactivating" + WorkspaceFailoverStateFailed WorkspaceFailoverState = "Failed" + WorkspaceFailoverStateInactive WorkspaceFailoverState = "Inactive" +) + +func PossibleValuesForWorkspaceFailoverState() []string { + return []string{ + string(WorkspaceFailoverStateActivating), + string(WorkspaceFailoverStateActive), + string(WorkspaceFailoverStateDeactivating), + string(WorkspaceFailoverStateFailed), + string(WorkspaceFailoverStateInactive), + } +} + +func (s *WorkspaceFailoverState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceFailoverState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceFailoverState(input string) (*WorkspaceFailoverState, error) { + vals := map[string]WorkspaceFailoverState{ + "activating": WorkspaceFailoverStateActivating, + "active": WorkspaceFailoverStateActive, + "deactivating": WorkspaceFailoverStateDeactivating, + "failed": WorkspaceFailoverStateFailed, + "inactive": WorkspaceFailoverStateInactive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceFailoverState(input) + return &out, nil +} + +type WorkspaceReplicationState string + +const ( + WorkspaceReplicationStateCanceled WorkspaceReplicationState = "Canceled" + WorkspaceReplicationStateDisableRequested WorkspaceReplicationState = "DisableRequested" + WorkspaceReplicationStateDisabling WorkspaceReplicationState = "Disabling" + WorkspaceReplicationStateEnableRequested WorkspaceReplicationState = "EnableRequested" + WorkspaceReplicationStateEnabling WorkspaceReplicationState = "Enabling" + WorkspaceReplicationStateFailed WorkspaceReplicationState = "Failed" + WorkspaceReplicationStateRollbackRequested WorkspaceReplicationState = "RollbackRequested" + WorkspaceReplicationStateRollingBack WorkspaceReplicationState = "RollingBack" + WorkspaceReplicationStateSucceeded WorkspaceReplicationState = "Succeeded" +) + +func PossibleValuesForWorkspaceReplicationState() []string { + return []string{ + string(WorkspaceReplicationStateCanceled), + string(WorkspaceReplicationStateDisableRequested), + string(WorkspaceReplicationStateDisabling), + string(WorkspaceReplicationStateEnableRequested), + string(WorkspaceReplicationStateEnabling), + string(WorkspaceReplicationStateFailed), + string(WorkspaceReplicationStateRollbackRequested), + string(WorkspaceReplicationStateRollingBack), + string(WorkspaceReplicationStateSucceeded), + } +} + +func (s *WorkspaceReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceReplicationState(input string) (*WorkspaceReplicationState, error) { + vals := map[string]WorkspaceReplicationState{ + "canceled": WorkspaceReplicationStateCanceled, + "disablerequested": WorkspaceReplicationStateDisableRequested, + "disabling": WorkspaceReplicationStateDisabling, + "enablerequested": WorkspaceReplicationStateEnableRequested, + "enabling": WorkspaceReplicationStateEnabling, + "failed": WorkspaceReplicationStateFailed, + "rollbackrequested": WorkspaceReplicationStateRollbackRequested, + "rollingback": WorkspaceReplicationStateRollingBack, + "succeeded": WorkspaceReplicationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceReplicationState(input) + return &out, nil +} + +type WorkspaceSkuNameEnum string + +const ( + WorkspaceSkuNameEnumCapacityReservation WorkspaceSkuNameEnum = "CapacityReservation" + WorkspaceSkuNameEnumFree WorkspaceSkuNameEnum = "Free" + WorkspaceSkuNameEnumLACluster WorkspaceSkuNameEnum = "LACluster" + WorkspaceSkuNameEnumPerGBTwoZeroOneEight WorkspaceSkuNameEnum = "PerGB2018" + WorkspaceSkuNameEnumPerNode WorkspaceSkuNameEnum = "PerNode" + WorkspaceSkuNameEnumPremium WorkspaceSkuNameEnum = "Premium" + WorkspaceSkuNameEnumStandalone WorkspaceSkuNameEnum = "Standalone" + WorkspaceSkuNameEnumStandard WorkspaceSkuNameEnum = "Standard" +) + +func PossibleValuesForWorkspaceSkuNameEnum() []string { + return []string{ + string(WorkspaceSkuNameEnumCapacityReservation), + string(WorkspaceSkuNameEnumFree), + string(WorkspaceSkuNameEnumLACluster), + string(WorkspaceSkuNameEnumPerGBTwoZeroOneEight), + string(WorkspaceSkuNameEnumPerNode), + string(WorkspaceSkuNameEnumPremium), + string(WorkspaceSkuNameEnumStandalone), + string(WorkspaceSkuNameEnumStandard), + } +} + +func (s *WorkspaceSkuNameEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceSkuNameEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceSkuNameEnum(input string) (*WorkspaceSkuNameEnum, error) { + vals := map[string]WorkspaceSkuNameEnum{ + "capacityreservation": WorkspaceSkuNameEnumCapacityReservation, + "free": WorkspaceSkuNameEnumFree, + "lacluster": WorkspaceSkuNameEnumLACluster, + "pergb2018": WorkspaceSkuNameEnumPerGBTwoZeroOneEight, + "pernode": WorkspaceSkuNameEnumPerNode, + "premium": WorkspaceSkuNameEnumPremium, + "standalone": WorkspaceSkuNameEnumStandalone, + "standard": WorkspaceSkuNameEnumStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceSkuNameEnum(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_list.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_list.go new file mode 100644 index 00000000000..fdd141b3757 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_list.go @@ -0,0 +1,55 @@ +package deletedworkspaces + +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 *WorkspaceListResult +} + +// List ... +func (c DeletedWorkspacesClient) List(ctx context.Context, id commonids.SubscriptionId) (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.OperationalInsights/deletedWorkspaces", 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 WorkspaceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_listbyresourcegroup.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_listbyresourcegroup.go new file mode 100644 index 00000000000..bc5fbefd94f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/method_listbyresourcegroup.go @@ -0,0 +1,55 @@ +package deletedworkspaces + +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 *WorkspaceListResult +} + +// ListByResourceGroup ... +func (c DeletedWorkspacesClient) 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.OperationalInsights/deletedWorkspaces", 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 WorkspaceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_privatelinkscopedresource.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_privatelinkscopedresource.go new file mode 100644 index 00000000000..a92034903ad --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_privatelinkscopedresource.go @@ -0,0 +1,9 @@ +package deletedworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkScopedResource struct { + ResourceId *string `json:"resourceId,omitempty"` + ScopeId *string `json:"scopeId,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspace.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspace.go new file mode 100644 index 00000000000..7e78ea4beb7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspace.go @@ -0,0 +1,21 @@ +package deletedworkspaces + +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 Workspace struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemOrUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *WorkspaceProperties `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/operationalinsights/2025-02-01/deletedworkspaces/model_workspacecapping.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacecapping.go new file mode 100644 index 00000000000..5f669fe2b4d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacecapping.go @@ -0,0 +1,10 @@ +package deletedworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceCapping struct { + DailyQuotaGb *float64 `json:"dailyQuotaGb,omitempty"` + DataIngestionStatus *DataIngestionStatus `json:"dataIngestionStatus,omitempty"` + QuotaNextResetTime *string `json:"quotaNextResetTime,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefailoverproperties.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefailoverproperties.go new file mode 100644 index 00000000000..0e5ec2a9287 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefailoverproperties.go @@ -0,0 +1,27 @@ +package deletedworkspaces + +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 WorkspaceFailoverProperties struct { + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + State *WorkspaceFailoverState `json:"state,omitempty"` +} + +func (o *WorkspaceFailoverProperties) GetLastModifiedDateAsTime() (*time.Time, error) { + if o.LastModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceFailoverProperties) SetLastModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefeatures.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefeatures.go new file mode 100644 index 00000000000..2f1150f6c87 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacefeatures.go @@ -0,0 +1,13 @@ +package deletedworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceFeatures struct { + ClusterResourceId *string `json:"clusterResourceId,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + EnableDataExport *bool `json:"enableDataExport,omitempty"` + EnableLogAccessUsingOnlyResourcePermissions *bool `json:"enableLogAccessUsingOnlyResourcePermissions,omitempty"` + ImmediatePurgeDataOn30Days *bool `json:"immediatePurgeDataOn30Days,omitempty"` + UnifiedSentinelBillingOnly *bool `json:"unifiedSentinelBillingOnly,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacelistresult.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacelistresult.go new file mode 100644 index 00000000000..5cf7fdb0764 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacelistresult.go @@ -0,0 +1,8 @@ +package deletedworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceListResult struct { + Value *[]Workspace `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspaceproperties.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspaceproperties.go new file mode 100644 index 00000000000..09e5ea3f8ad --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspaceproperties.go @@ -0,0 +1,52 @@ +package deletedworkspaces + +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 WorkspaceProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + CustomerId *string `json:"customerId,omitempty"` + DefaultDataCollectionRuleResourceId *string `json:"defaultDataCollectionRuleResourceId,omitempty"` + Failover *WorkspaceFailoverProperties `json:"failover,omitempty"` + Features *WorkspaceFeatures `json:"features,omitempty"` + ForceCmkForQuery *bool `json:"forceCmkForQuery,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + PrivateLinkScopedResources *[]PrivateLinkScopedResource `json:"privateLinkScopedResources,omitempty"` + ProvisioningState *WorkspaceEntityStatus `json:"provisioningState,omitempty"` + PublicNetworkAccessForIngestion *PublicNetworkAccessType `json:"publicNetworkAccessForIngestion,omitempty"` + PublicNetworkAccessForQuery *PublicNetworkAccessType `json:"publicNetworkAccessForQuery,omitempty"` + Replication *WorkspaceReplicationProperties `json:"replication,omitempty"` + RetentionInDays *int64 `json:"retentionInDays,omitempty"` + Sku *WorkspaceSku `json:"sku,omitempty"` + WorkspaceCapping *WorkspaceCapping `json:"workspaceCapping,omitempty"` +} + +func (o *WorkspaceProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *WorkspaceProperties) GetModifiedDateAsTime() (*time.Time, error) { + if o.ModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceProperties) SetModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacereplicationproperties.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacereplicationproperties.go new file mode 100644 index 00000000000..bd656847802 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacereplicationproperties.go @@ -0,0 +1,42 @@ +package deletedworkspaces + +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 WorkspaceReplicationProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + Location *string `json:"location,omitempty"` + ProvisioningState *WorkspaceReplicationState `json:"provisioningState,omitempty"` +} + +func (o *WorkspaceReplicationProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceReplicationProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *WorkspaceReplicationProperties) GetLastModifiedDateAsTime() (*time.Time, error) { + if o.LastModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceReplicationProperties) SetLastModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacesku.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacesku.go new file mode 100644 index 00000000000..b4e845e72e6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/model_workspacesku.go @@ -0,0 +1,28 @@ +package deletedworkspaces + +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 WorkspaceSku struct { + CapacityReservationLevel *CapacityReservationLevel `json:"capacityReservationLevel,omitempty"` + LastSkuUpdate *string `json:"lastSkuUpdate,omitempty"` + Name WorkspaceSkuNameEnum `json:"name"` +} + +func (o *WorkspaceSku) GetLastSkuUpdateAsTime() (*time.Time, error) { + if o.LastSkuUpdate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSkuUpdate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceSku) SetLastSkuUpdateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSkuUpdate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/version.go b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/version.go new file mode 100644 index 00000000000..78b2794a257 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/deletedworkspaces/version.go @@ -0,0 +1,10 @@ +package deletedworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/deletedworkspaces/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/README.md b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/README.md new file mode 100644 index 00000000000..b9ad9a51e34 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/README.md @@ -0,0 +1,68 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/intelligencepacks` Documentation + +The `intelligencepacks` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/intelligencepacks" +``` + + +### Client Initialization + +```go +client := intelligencepacks.NewIntelligencePacksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IntelligencePacksClient.Disable` + +```go +ctx := context.TODO() +id := intelligencepacks.NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName") + +read, err := client.Disable(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntelligencePacksClient.Enable` + +```go +ctx := context.TODO() +id := intelligencepacks.NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName") + +read, err := client.Enable(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntelligencePacksClient.List` + +```go +ctx := context.TODO() +id := intelligencepacks.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/client.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/client.go new file mode 100644 index 00000000000..518c60eaae5 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/client.go @@ -0,0 +1,26 @@ +package intelligencepacks + +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 IntelligencePacksClient struct { + Client *resourcemanager.Client +} + +func NewIntelligencePacksClientWithBaseURI(sdkApi sdkEnv.Api) (*IntelligencePacksClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "intelligencepacks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IntelligencePacksClient: %+v", err) + } + + return &IntelligencePacksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack.go new file mode 100644 index 00000000000..ee98a42386d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack.go @@ -0,0 +1,139 @@ +package intelligencepacks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&IntelligencePackId{}) +} + +var _ resourceids.ResourceId = &IntelligencePackId{} + +// IntelligencePackId is a struct representing the Resource ID for a Intelligence Pack +type IntelligencePackId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IntelligencePackName string +} + +// NewIntelligencePackID returns a new IntelligencePackId struct +func NewIntelligencePackID(subscriptionId string, resourceGroupName string, workspaceName string, intelligencePackName string) IntelligencePackId { + return IntelligencePackId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IntelligencePackName: intelligencePackName, + } +} + +// ParseIntelligencePackID parses 'input' into a IntelligencePackId +func ParseIntelligencePackID(input string) (*IntelligencePackId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntelligencePackId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntelligencePackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIntelligencePackIDInsensitively parses 'input' case-insensitively into a IntelligencePackId +// note: this method should only be used for API response data and not user input +func ParseIntelligencePackIDInsensitively(input string) (*IntelligencePackId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntelligencePackId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntelligencePackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IntelligencePackId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IntelligencePackName, ok = input.Parsed["intelligencePackName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "intelligencePackName", input) + } + + return nil +} + +// ValidateIntelligencePackID checks that 'input' can be parsed as a Intelligence Pack ID +func ValidateIntelligencePackID(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 := ParseIntelligencePackID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Intelligence Pack ID +func (id IntelligencePackId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/intelligencePacks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IntelligencePackName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Intelligence Pack ID +func (id IntelligencePackId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticIntelligencePacks", "intelligencePacks", "intelligencePacks"), + resourceids.UserSpecifiedSegment("intelligencePackName", "intelligencePackName"), + } +} + +// String returns a human-readable description of this Intelligence Pack ID +func (id IntelligencePackId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Intelligence Pack Name: %q", id.IntelligencePackName), + } + return fmt.Sprintf("Intelligence Pack (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack_test.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack_test.go new file mode 100644 index 00000000000..032f02668b8 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_intelligencepack_test.go @@ -0,0 +1,327 @@ +package intelligencepacks + +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 = &IntelligencePackId{} + +func TestNewIntelligencePackID(t *testing.T) { + id := NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.IntelligencePackName != "intelligencePackName" { + t.Fatalf("Expected %q but got %q for Segment 'IntelligencePackName'", id.IntelligencePackName, "intelligencePackName") + } +} + +func TestFormatIntelligencePackID(t *testing.T) { + actual := NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIntelligencePackID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntelligencePackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName", + Expected: &IntelligencePackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + IntelligencePackName: "intelligencePackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntelligencePackID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntelligencePackName != v.Expected.IntelligencePackName { + t.Fatalf("Expected %q but got %q for IntelligencePackName", v.Expected.IntelligencePackName, actual.IntelligencePackName) + } + + } +} + +func TestParseIntelligencePackIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntelligencePackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/iNtElLiGeNcEpAcKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName", + Expected: &IntelligencePackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + IntelligencePackName: "intelligencePackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/iNtElLiGeNcEpAcKs/iNtElLiGeNcEpAcKnAmE", + Expected: &IntelligencePackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + IntelligencePackName: "iNtElLiGeNcEpAcKnAmE", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/iNtElLiGeNcEpAcKs/iNtElLiGeNcEpAcKnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntelligencePackIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntelligencePackName != v.Expected.IntelligencePackName { + t.Fatalf("Expected %q but got %q for IntelligencePackName", v.Expected.IntelligencePackName, actual.IntelligencePackName) + } + + } +} + +func TestSegmentsForIntelligencePackId(t *testing.T) { + segments := IntelligencePackId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IntelligencePackId 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/operationalinsights/2025-02-01/intelligencepacks/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace.go new file mode 100644 index 00000000000..f771f3365e1 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace.go @@ -0,0 +1,130 @@ +package intelligencepacks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace_test.go new file mode 100644 index 00000000000..d5445b09646 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/id_workspace_test.go @@ -0,0 +1,282 @@ +package intelligencepacks + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/intelligencepacks/method_disable.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_disable.go new file mode 100644 index 00000000000..1697c5db1e6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_disable.go @@ -0,0 +1,47 @@ +package intelligencepacks + +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 DisableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Disable ... +func (c IntelligencePacksClient) Disable(ctx context.Context, id IntelligencePackId) (result DisableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_enable.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_enable.go new file mode 100644 index 00000000000..cdae66e4a20 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_enable.go @@ -0,0 +1,47 @@ +package intelligencepacks + +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 EnableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Enable ... +func (c IntelligencePacksClient) Enable(ctx context.Context, id IntelligencePackId) (result EnableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/enable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_list.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_list.go new file mode 100644 index 00000000000..935b628393d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/method_list.go @@ -0,0 +1,54 @@ +package intelligencepacks + +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 *[]IntelligencePack +} + +// List ... +func (c IntelligencePacksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/intelligencePacks", 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 []IntelligencePack + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/model_intelligencepack.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/model_intelligencepack.go new file mode 100644 index 00000000000..258fdc2abbf --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/model_intelligencepack.go @@ -0,0 +1,10 @@ +package intelligencepacks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntelligencePack struct { + DisplayName *string `json:"displayName,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/intelligencepacks/version.go b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/version.go new file mode 100644 index 00000000000..3d80c847de7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/intelligencepacks/version.go @@ -0,0 +1,10 @@ +package intelligencepacks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/intelligencepacks/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/README.md b/resource-manager/operationalinsights/2025-02-01/linkedservices/README.md new file mode 100644 index 00000000000..ef3c6050db7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/linkedservices` Documentation + +The `linkedservices` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/linkedservices" +``` + + +### Client Initialization + +```go +client := linkedservices.NewLinkedServicesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LinkedServicesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := linkedservices.NewLinkedServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "linkedServiceName") + +payload := linkedservices.LinkedService{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LinkedServicesClient.Delete` + +```go +ctx := context.TODO() +id := linkedservices.NewLinkedServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "linkedServiceName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LinkedServicesClient.Get` + +```go +ctx := context.TODO() +id := linkedservices.NewLinkedServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "linkedServiceName") + +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: `LinkedServicesClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := linkedservices.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/client.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/client.go new file mode 100644 index 00000000000..3dad68f5d5e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/client.go @@ -0,0 +1,26 @@ +package linkedservices + +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 LinkedServicesClient struct { + Client *resourcemanager.Client +} + +func NewLinkedServicesClientWithBaseURI(sdkApi sdkEnv.Api) (*LinkedServicesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "linkedservices", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LinkedServicesClient: %+v", err) + } + + return &LinkedServicesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/constants.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/constants.go new file mode 100644 index 00000000000..8522d1f6ced --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/constants.go @@ -0,0 +1,57 @@ +package linkedservices + +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 LinkedServiceEntityStatus string + +const ( + LinkedServiceEntityStatusDeleting LinkedServiceEntityStatus = "Deleting" + LinkedServiceEntityStatusProvisioningAccount LinkedServiceEntityStatus = "ProvisioningAccount" + LinkedServiceEntityStatusSucceeded LinkedServiceEntityStatus = "Succeeded" + LinkedServiceEntityStatusUpdating LinkedServiceEntityStatus = "Updating" +) + +func PossibleValuesForLinkedServiceEntityStatus() []string { + return []string{ + string(LinkedServiceEntityStatusDeleting), + string(LinkedServiceEntityStatusProvisioningAccount), + string(LinkedServiceEntityStatusSucceeded), + string(LinkedServiceEntityStatusUpdating), + } +} + +func (s *LinkedServiceEntityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkedServiceEntityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkedServiceEntityStatus(input string) (*LinkedServiceEntityStatus, error) { + vals := map[string]LinkedServiceEntityStatus{ + "deleting": LinkedServiceEntityStatusDeleting, + "provisioningaccount": LinkedServiceEntityStatusProvisioningAccount, + "succeeded": LinkedServiceEntityStatusSucceeded, + "updating": LinkedServiceEntityStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkedServiceEntityStatus(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice.go new file mode 100644 index 00000000000..a2f3b24e491 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice.go @@ -0,0 +1,139 @@ +package linkedservices + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LinkedServiceId{}) +} + +var _ resourceids.ResourceId = &LinkedServiceId{} + +// LinkedServiceId is a struct representing the Resource ID for a Linked Service +type LinkedServiceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + LinkedServiceName string +} + +// NewLinkedServiceID returns a new LinkedServiceId struct +func NewLinkedServiceID(subscriptionId string, resourceGroupName string, workspaceName string, linkedServiceName string) LinkedServiceId { + return LinkedServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + LinkedServiceName: linkedServiceName, + } +} + +// ParseLinkedServiceID parses 'input' into a LinkedServiceId +func ParseLinkedServiceID(input string) (*LinkedServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&LinkedServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LinkedServiceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLinkedServiceIDInsensitively parses 'input' case-insensitively into a LinkedServiceId +// note: this method should only be used for API response data and not user input +func ParseLinkedServiceIDInsensitively(input string) (*LinkedServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&LinkedServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LinkedServiceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LinkedServiceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.LinkedServiceName, ok = input.Parsed["linkedServiceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "linkedServiceName", input) + } + + return nil +} + +// ValidateLinkedServiceID checks that 'input' can be parsed as a Linked Service ID +func ValidateLinkedServiceID(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 := ParseLinkedServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Linked Service ID +func (id LinkedServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/linkedServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.LinkedServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Linked Service ID +func (id LinkedServiceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticLinkedServices", "linkedServices", "linkedServices"), + resourceids.UserSpecifiedSegment("linkedServiceName", "linkedServiceName"), + } +} + +// String returns a human-readable description of this Linked Service ID +func (id LinkedServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Linked Service Name: %q", id.LinkedServiceName), + } + return fmt.Sprintf("Linked Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice_test.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice_test.go new file mode 100644 index 00000000000..93e06914e53 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_linkedservice_test.go @@ -0,0 +1,327 @@ +package linkedservices + +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 = &LinkedServiceId{} + +func TestNewLinkedServiceID(t *testing.T) { + id := NewLinkedServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "linkedServiceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.LinkedServiceName != "linkedServiceName" { + t.Fatalf("Expected %q but got %q for Segment 'LinkedServiceName'", id.LinkedServiceName, "linkedServiceName") + } +} + +func TestFormatLinkedServiceID(t *testing.T) { + actual := NewLinkedServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "linkedServiceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices/linkedServiceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLinkedServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LinkedServiceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices/linkedServiceName", + Expected: &LinkedServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + LinkedServiceName: "linkedServiceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices/linkedServiceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLinkedServiceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.LinkedServiceName != v.Expected.LinkedServiceName { + t.Fatalf("Expected %q but got %q for LinkedServiceName", v.Expected.LinkedServiceName, actual.LinkedServiceName) + } + + } +} + +func TestParseLinkedServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LinkedServiceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/lInKeDsErViCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices/linkedServiceName", + Expected: &LinkedServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + LinkedServiceName: "linkedServiceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedServices/linkedServiceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/lInKeDsErViCeS/lInKeDsErViCeNaMe", + Expected: &LinkedServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + LinkedServiceName: "lInKeDsErViCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/lInKeDsErViCeS/lInKeDsErViCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLinkedServiceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.LinkedServiceName != v.Expected.LinkedServiceName { + t.Fatalf("Expected %q but got %q for LinkedServiceName", v.Expected.LinkedServiceName, actual.LinkedServiceName) + } + + } +} + +func TestSegmentsForLinkedServiceId(t *testing.T) { + segments := LinkedServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LinkedServiceId 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/operationalinsights/2025-02-01/linkedservices/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace.go new file mode 100644 index 00000000000..16b754510d2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace.go @@ -0,0 +1,130 @@ +package linkedservices + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace_test.go new file mode 100644 index 00000000000..7df7975ebf9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/id_workspace_test.go @@ -0,0 +1,282 @@ +package linkedservices + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/linkedservices/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_createorupdate.go new file mode 100644 index 00000000000..18c4e4d1dd4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_createorupdate.go @@ -0,0 +1,76 @@ +package linkedservices + +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 *LinkedService +} + +// CreateOrUpdate ... +func (c LinkedServicesClient) CreateOrUpdate(ctx context.Context, id LinkedServiceId, input LinkedService) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 LinkedServicesClient) CreateOrUpdateThenPoll(ctx context.Context, id LinkedServiceId, input LinkedService) 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/operationalinsights/2025-02-01/linkedservices/method_delete.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_delete.go new file mode 100644 index 00000000000..65d01a5e7aa --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_delete.go @@ -0,0 +1,72 @@ +package linkedservices + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LinkedService +} + +// Delete ... +func (c LinkedServicesClient) Delete(ctx context.Context, id LinkedServiceId) (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 LinkedServicesClient) DeleteThenPoll(ctx context.Context, id LinkedServiceId) 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/operationalinsights/2025-02-01/linkedservices/method_get.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_get.go new file mode 100644 index 00000000000..f4d0d98ffdd --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_get.go @@ -0,0 +1,53 @@ +package linkedservices + +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 *LinkedService +} + +// Get ... +func (c LinkedServicesClient) Get(ctx context.Context, id LinkedServiceId) (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 LinkedService + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_listbyworkspace.go new file mode 100644 index 00000000000..9c72f2b544d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/method_listbyworkspace.go @@ -0,0 +1,54 @@ +package linkedservices + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LinkedServiceListResult +} + +// ListByWorkspace ... +func (c LinkedServicesClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/linkedServices", 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 LinkedServiceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservice.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservice.go new file mode 100644 index 00000000000..f4b120ae7af --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservice.go @@ -0,0 +1,12 @@ +package linkedservices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedService struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties LinkedServiceProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservicelistresult.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservicelistresult.go new file mode 100644 index 00000000000..8d5731b5785 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedservicelistresult.go @@ -0,0 +1,8 @@ +package linkedservices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedServiceListResult struct { + Value *[]LinkedService `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedserviceproperties.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedserviceproperties.go new file mode 100644 index 00000000000..779209d9e11 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/model_linkedserviceproperties.go @@ -0,0 +1,10 @@ +package linkedservices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedServiceProperties struct { + ProvisioningState *LinkedServiceEntityStatus `json:"provisioningState,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + WriteAccessResourceId *string `json:"writeAccessResourceId,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedservices/version.go b/resource-manager/operationalinsights/2025-02-01/linkedservices/version.go new file mode 100644 index 00000000000..f0cf32eedf2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedservices/version.go @@ -0,0 +1,10 @@ +package linkedservices + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/linkedservices/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/README.md b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/README.md new file mode 100644 index 00000000000..bf14d7d25a9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts` Documentation + +The `linkedstorageaccounts` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts" +``` + + +### Client Initialization + +```go +client := linkedstorageaccounts.NewLinkedStorageAccountsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LinkedStorageAccountsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := linkedstorageaccounts.NewDataSourceTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "Alerts") + +payload := linkedstorageaccounts.LinkedStorageAccountsResource{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LinkedStorageAccountsClient.Delete` + +```go +ctx := context.TODO() +id := linkedstorageaccounts.NewDataSourceTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "Alerts") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LinkedStorageAccountsClient.Get` + +```go +ctx := context.TODO() +id := linkedstorageaccounts.NewDataSourceTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "Alerts") + +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: `LinkedStorageAccountsClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := linkedstorageaccounts.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/client.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/client.go new file mode 100644 index 00000000000..951ac7536f6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/client.go @@ -0,0 +1,26 @@ +package linkedstorageaccounts + +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 LinkedStorageAccountsClient struct { + Client *resourcemanager.Client +} + +func NewLinkedStorageAccountsClientWithBaseURI(sdkApi sdkEnv.Api) (*LinkedStorageAccountsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "linkedstorageaccounts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LinkedStorageAccountsClient: %+v", err) + } + + return &LinkedStorageAccountsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/constants.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/constants.go new file mode 100644 index 00000000000..abf0284b4b7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/constants.go @@ -0,0 +1,60 @@ +package linkedstorageaccounts + +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 DataSourceType string + +const ( + DataSourceTypeAlerts DataSourceType = "Alerts" + DataSourceTypeAzureWatson DataSourceType = "AzureWatson" + DataSourceTypeCustomLogs DataSourceType = "CustomLogs" + DataSourceTypeIngestion DataSourceType = "Ingestion" + DataSourceTypeQuery DataSourceType = "Query" +) + +func PossibleValuesForDataSourceType() []string { + return []string{ + string(DataSourceTypeAlerts), + string(DataSourceTypeAzureWatson), + string(DataSourceTypeCustomLogs), + string(DataSourceTypeIngestion), + string(DataSourceTypeQuery), + } +} + +func (s *DataSourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataSourceType(input string) (*DataSourceType, error) { + vals := map[string]DataSourceType{ + "alerts": DataSourceTypeAlerts, + "azurewatson": DataSourceTypeAzureWatson, + "customlogs": DataSourceTypeCustomLogs, + "ingestion": DataSourceTypeIngestion, + "query": DataSourceTypeQuery, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataSourceType(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype.go new file mode 100644 index 00000000000..42d6a1c2a50 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype.go @@ -0,0 +1,147 @@ +package linkedstorageaccounts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DataSourceTypeId{}) +} + +var _ resourceids.ResourceId = &DataSourceTypeId{} + +// DataSourceTypeId is a struct representing the Resource ID for a Data Source Type +type DataSourceTypeId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + DataSourceType DataSourceType +} + +// NewDataSourceTypeID returns a new DataSourceTypeId struct +func NewDataSourceTypeID(subscriptionId string, resourceGroupName string, workspaceName string, dataSourceType DataSourceType) DataSourceTypeId { + return DataSourceTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + DataSourceType: dataSourceType, + } +} + +// ParseDataSourceTypeID parses 'input' into a DataSourceTypeId +func ParseDataSourceTypeID(input string) (*DataSourceTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataSourceTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataSourceTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDataSourceTypeIDInsensitively parses 'input' case-insensitively into a DataSourceTypeId +// note: this method should only be used for API response data and not user input +func ParseDataSourceTypeIDInsensitively(input string) (*DataSourceTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataSourceTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataSourceTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DataSourceTypeId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if v, ok := input.Parsed["dataSourceType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dataSourceType", input) + } + + dataSourceType, err := parseDataSourceType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.DataSourceType = *dataSourceType + } + + return nil +} + +// ValidateDataSourceTypeID checks that 'input' can be parsed as a Data Source Type ID +func ValidateDataSourceTypeID(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 := ParseDataSourceTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Data Source Type ID +func (id DataSourceTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/linkedStorageAccounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, string(id.DataSourceType)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Data Source Type ID +func (id DataSourceTypeId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticLinkedStorageAccounts", "linkedStorageAccounts", "linkedStorageAccounts"), + resourceids.ConstantSegment("dataSourceType", PossibleValuesForDataSourceType(), "Alerts"), + } +} + +// String returns a human-readable description of this Data Source Type ID +func (id DataSourceTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Data Source Type: %q", string(id.DataSourceType)), + } + return fmt.Sprintf("Data Source Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype_test.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype_test.go new file mode 100644 index 00000000000..dd022522a17 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_datasourcetype_test.go @@ -0,0 +1,327 @@ +package linkedstorageaccounts + +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 = &DataSourceTypeId{} + +func TestNewDataSourceTypeID(t *testing.T) { + id := NewDataSourceTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "Alerts") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.DataSourceType != "Alerts" { + t.Fatalf("Expected %q but got %q for Segment 'DataSourceType'", id.DataSourceType, "Alerts") + } +} + +func TestFormatDataSourceTypeID(t *testing.T) { + actual := NewDataSourceTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "Alerts").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts/Alerts" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDataSourceTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataSourceTypeId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts/Alerts", + Expected: &DataSourceTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + DataSourceType: "Alerts", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts/Alerts/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataSourceTypeID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataSourceType != v.Expected.DataSourceType { + t.Fatalf("Expected %q but got %q for DataSourceType", v.Expected.DataSourceType, actual.DataSourceType) + } + + } +} + +func TestParseDataSourceTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataSourceTypeId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/lInKeDsToRaGeAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts/Alerts", + Expected: &DataSourceTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + DataSourceType: "Alerts", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/linkedStorageAccounts/Alerts/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/lInKeDsToRaGeAcCoUnTs/aLeRtS", + Expected: &DataSourceTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + DataSourceType: "Alerts", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/lInKeDsToRaGeAcCoUnTs/aLeRtS/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataSourceTypeIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataSourceType != v.Expected.DataSourceType { + t.Fatalf("Expected %q but got %q for DataSourceType", v.Expected.DataSourceType, actual.DataSourceType) + } + + } +} + +func TestSegmentsForDataSourceTypeId(t *testing.T) { + segments := DataSourceTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DataSourceTypeId 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/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace.go new file mode 100644 index 00000000000..1f6d261f8a7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace.go @@ -0,0 +1,130 @@ +package linkedstorageaccounts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace_test.go new file mode 100644 index 00000000000..9e32eb5abee --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/id_workspace_test.go @@ -0,0 +1,282 @@ +package linkedstorageaccounts + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/linkedstorageaccounts/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_createorupdate.go new file mode 100644 index 00000000000..713373c104f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_createorupdate.go @@ -0,0 +1,57 @@ +package linkedstorageaccounts + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LinkedStorageAccountsResource +} + +// CreateOrUpdate ... +func (c LinkedStorageAccountsClient) CreateOrUpdate(ctx context.Context, id DataSourceTypeId, input LinkedStorageAccountsResource) (result CreateOrUpdateOperationResponse, 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 LinkedStorageAccountsResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_delete.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_delete.go new file mode 100644 index 00000000000..65907ea3542 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_delete.go @@ -0,0 +1,46 @@ +package linkedstorageaccounts + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c LinkedStorageAccountsClient) Delete(ctx context.Context, id DataSourceTypeId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_get.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_get.go new file mode 100644 index 00000000000..085a74b9f9a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_get.go @@ -0,0 +1,53 @@ +package linkedstorageaccounts + +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 *LinkedStorageAccountsResource +} + +// Get ... +func (c LinkedStorageAccountsClient) Get(ctx context.Context, id DataSourceTypeId) (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 LinkedStorageAccountsResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_listbyworkspace.go new file mode 100644 index 00000000000..2e40bd1dc6c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/method_listbyworkspace.go @@ -0,0 +1,54 @@ +package linkedstorageaccounts + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LinkedStorageAccountsListResult +} + +// ListByWorkspace ... +func (c LinkedStorageAccountsClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/linkedStorageAccounts", 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 LinkedStorageAccountsListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountslistresult.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountslistresult.go new file mode 100644 index 00000000000..d9be9e74ab9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountslistresult.go @@ -0,0 +1,8 @@ +package linkedstorageaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedStorageAccountsListResult struct { + Value *[]LinkedStorageAccountsResource `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsproperties.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsproperties.go new file mode 100644 index 00000000000..43730125135 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsproperties.go @@ -0,0 +1,9 @@ +package linkedstorageaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedStorageAccountsProperties struct { + DataSourceType *DataSourceType `json:"dataSourceType,omitempty"` + StorageAccountIds *[]string `json:"storageAccountIds,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsresource.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsresource.go new file mode 100644 index 00000000000..c4a02711ff6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/model_linkedstorageaccountsresource.go @@ -0,0 +1,11 @@ +package linkedstorageaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedStorageAccountsResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties LinkedStorageAccountsProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/version.go b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/version.go new file mode 100644 index 00000000000..158580e985c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/linkedstorageaccounts/version.go @@ -0,0 +1,10 @@ +package linkedstorageaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/linkedstorageaccounts/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/README.md b/resource-manager/operationalinsights/2025-02-01/querypackqueries/README.md new file mode 100644 index 00000000000..780113058d4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/README.md @@ -0,0 +1,133 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/querypackqueries` Documentation + +The `querypackqueries` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/querypackqueries" +``` + + +### Client Initialization + +```go +client := querypackqueries.NewQueryPackQueriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QueryPackQueriesClient.QueriesDelete` + +```go +ctx := context.TODO() +id := querypackqueries.NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName", "queryName") + +read, err := client.QueriesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryPackQueriesClient.QueriesGet` + +```go +ctx := context.TODO() +id := querypackqueries.NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName", "queryName") + +read, err := client.QueriesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryPackQueriesClient.QueriesList` + +```go +ctx := context.TODO() +id := querypackqueries.NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + +// alternatively `client.QueriesList(ctx, id, querypackqueries.DefaultQueriesListOperationOptions())` can be used to do batched pagination +items, err := client.QueriesListComplete(ctx, id, querypackqueries.DefaultQueriesListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `QueryPackQueriesClient.QueriesPut` + +```go +ctx := context.TODO() +id := querypackqueries.NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName", "queryName") + +payload := querypackqueries.LogAnalyticsQueryPackQuery{ + // ... +} + + +read, err := client.QueriesPut(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryPackQueriesClient.QueriesSearch` + +```go +ctx := context.TODO() +id := querypackqueries.NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + +payload := querypackqueries.LogAnalyticsQueryPackQuerySearchProperties{ + // ... +} + + +// alternatively `client.QueriesSearch(ctx, id, payload, querypackqueries.DefaultQueriesSearchOperationOptions())` can be used to do batched pagination +items, err := client.QueriesSearchComplete(ctx, id, payload, querypackqueries.DefaultQueriesSearchOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `QueryPackQueriesClient.QueriesUpdate` + +```go +ctx := context.TODO() +id := querypackqueries.NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName", "queryName") + +payload := querypackqueries.LogAnalyticsQueryPackQuery{ + // ... +} + + +read, err := client.QueriesUpdate(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/operationalinsights/2025-02-01/querypackqueries/client.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/client.go new file mode 100644 index 00000000000..d858936012f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/client.go @@ -0,0 +1,26 @@ +package querypackqueries + +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 QueryPackQueriesClient struct { + Client *resourcemanager.Client +} + +func NewQueryPackQueriesClientWithBaseURI(sdkApi sdkEnv.Api) (*QueryPackQueriesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "querypackqueries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QueryPackQueriesClient: %+v", err) + } + + return &QueryPackQueriesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query.go new file mode 100644 index 00000000000..d28ec182a6d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query.go @@ -0,0 +1,139 @@ +package querypackqueries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QueryId{}) +} + +var _ resourceids.ResourceId = &QueryId{} + +// QueryId is a struct representing the Resource ID for a Query +type QueryId struct { + SubscriptionId string + ResourceGroupName string + QueryPackName string + QueryName string +} + +// NewQueryID returns a new QueryId struct +func NewQueryID(subscriptionId string, resourceGroupName string, queryPackName string, queryName string) QueryId { + return QueryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + QueryPackName: queryPackName, + QueryName: queryName, + } +} + +// ParseQueryID parses 'input' into a QueryId +func ParseQueryID(input string) (*QueryId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQueryIDInsensitively parses 'input' case-insensitively into a QueryId +// note: this method should only be used for API response data and not user input +func ParseQueryIDInsensitively(input string) (*QueryId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QueryId) 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.QueryPackName, ok = input.Parsed["queryPackName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "queryPackName", input) + } + + if id.QueryName, ok = input.Parsed["queryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "queryName", input) + } + + return nil +} + +// ValidateQueryID checks that 'input' can be parsed as a Query ID +func ValidateQueryID(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 := ParseQueryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Query ID +func (id QueryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/queryPacks/%s/queries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.QueryPackName, id.QueryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Query ID +func (id QueryId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticQueryPacks", "queryPacks", "queryPacks"), + resourceids.UserSpecifiedSegment("queryPackName", "queryPackName"), + resourceids.StaticSegment("staticQueries", "queries", "queries"), + resourceids.UserSpecifiedSegment("queryName", "queryName"), + } +} + +// String returns a human-readable description of this Query ID +func (id QueryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Query Pack Name: %q", id.QueryPackName), + fmt.Sprintf("Query Name: %q", id.QueryName), + } + return fmt.Sprintf("Query (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query_test.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query_test.go new file mode 100644 index 00000000000..41156889895 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_query_test.go @@ -0,0 +1,327 @@ +package querypackqueries + +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 = &QueryId{} + +func TestNewQueryID(t *testing.T) { + id := NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName", "queryName") + + 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.QueryPackName != "queryPackName" { + t.Fatalf("Expected %q but got %q for Segment 'QueryPackName'", id.QueryPackName, "queryPackName") + } + + if id.QueryName != "queryName" { + t.Fatalf("Expected %q but got %q for Segment 'QueryName'", id.QueryName, "queryName") + } +} + +func TestFormatQueryID(t *testing.T) { + actual := NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName", "queryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries/queryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQueryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries/queryName", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + QueryPackName: "queryPackName", + QueryName: "queryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries/queryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryID(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.QueryPackName != v.Expected.QueryPackName { + t.Fatalf("Expected %q but got %q for QueryPackName", v.Expected.QueryPackName, actual.QueryPackName) + } + + if actual.QueryName != v.Expected.QueryName { + t.Fatalf("Expected %q but got %q for QueryName", v.Expected.QueryName, actual.QueryName) + } + + } +} + +func TestParseQueryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe/qUeRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries/queryName", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + QueryPackName: "queryPackName", + QueryName: "queryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/queries/queryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe/qUeRiEs/qUeRyNaMe", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + QueryPackName: "qUeRyPaCkNaMe", + QueryName: "qUeRyNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe/qUeRiEs/qUeRyNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryIDInsensitively(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.QueryPackName != v.Expected.QueryPackName { + t.Fatalf("Expected %q but got %q for QueryPackName", v.Expected.QueryPackName, actual.QueryPackName) + } + + if actual.QueryName != v.Expected.QueryName { + t.Fatalf("Expected %q but got %q for QueryName", v.Expected.QueryName, actual.QueryName) + } + + } +} + +func TestSegmentsForQueryId(t *testing.T) { + segments := QueryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QueryId 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/operationalinsights/2025-02-01/querypackqueries/id_querypack.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack.go new file mode 100644 index 00000000000..4f2002aa009 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack.go @@ -0,0 +1,130 @@ +package querypackqueries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QueryPackId{}) +} + +var _ resourceids.ResourceId = &QueryPackId{} + +// QueryPackId is a struct representing the Resource ID for a Query Pack +type QueryPackId struct { + SubscriptionId string + ResourceGroupName string + QueryPackName string +} + +// NewQueryPackID returns a new QueryPackId struct +func NewQueryPackID(subscriptionId string, resourceGroupName string, queryPackName string) QueryPackId { + return QueryPackId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + QueryPackName: queryPackName, + } +} + +// ParseQueryPackID parses 'input' into a QueryPackId +func ParseQueryPackID(input string) (*QueryPackId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryPackId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryPackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQueryPackIDInsensitively parses 'input' case-insensitively into a QueryPackId +// note: this method should only be used for API response data and not user input +func ParseQueryPackIDInsensitively(input string) (*QueryPackId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryPackId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryPackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QueryPackId) 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.QueryPackName, ok = input.Parsed["queryPackName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "queryPackName", input) + } + + return nil +} + +// ValidateQueryPackID checks that 'input' can be parsed as a Query Pack ID +func ValidateQueryPackID(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 := ParseQueryPackID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Query Pack ID +func (id QueryPackId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/queryPacks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.QueryPackName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Query Pack ID +func (id QueryPackId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticQueryPacks", "queryPacks", "queryPacks"), + resourceids.UserSpecifiedSegment("queryPackName", "queryPackName"), + } +} + +// String returns a human-readable description of this Query Pack ID +func (id QueryPackId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Query Pack Name: %q", id.QueryPackName), + } + return fmt.Sprintf("Query Pack (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack_test.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack_test.go new file mode 100644 index 00000000000..eef7759ac06 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/id_querypack_test.go @@ -0,0 +1,282 @@ +package querypackqueries + +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 = &QueryPackId{} + +func TestNewQueryPackID(t *testing.T) { + id := NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + + 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.QueryPackName != "queryPackName" { + t.Fatalf("Expected %q but got %q for Segment 'QueryPackName'", id.QueryPackName, "queryPackName") + } +} + +func TestFormatQueryPackID(t *testing.T) { + actual := NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQueryPackID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryPackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName", + Expected: &QueryPackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + QueryPackName: "queryPackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryPackID(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.QueryPackName != v.Expected.QueryPackName { + t.Fatalf("Expected %q but got %q for QueryPackName", v.Expected.QueryPackName, actual.QueryPackName) + } + + } +} + +func TestParseQueryPackIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryPackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName", + Expected: &QueryPackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + QueryPackName: "queryPackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe", + Expected: &QueryPackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + QueryPackName: "qUeRyPaCkNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryPackIDInsensitively(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.QueryPackName != v.Expected.QueryPackName { + t.Fatalf("Expected %q but got %q for QueryPackName", v.Expected.QueryPackName, actual.QueryPackName) + } + + } +} + +func TestSegmentsForQueryPackId(t *testing.T) { + segments := QueryPackId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QueryPackId 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/operationalinsights/2025-02-01/querypackqueries/method_queriesdelete.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesdelete.go new file mode 100644 index 00000000000..39ddfb9e4d7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesdelete.go @@ -0,0 +1,47 @@ +package querypackqueries + +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 QueriesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// QueriesDelete ... +func (c QueryPackQueriesClient) QueriesDelete(ctx context.Context, id QueryId) (result QueriesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesget.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesget.go new file mode 100644 index 00000000000..ff8ffe93a7a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesget.go @@ -0,0 +1,53 @@ +package querypackqueries + +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 QueriesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogAnalyticsQueryPackQuery +} + +// QueriesGet ... +func (c QueryPackQueriesClient) QueriesGet(ctx context.Context, id QueryId) (result QueriesGetOperationResponse, 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 LogAnalyticsQueryPackQuery + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_querieslist.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_querieslist.go new file mode 100644 index 00000000000..f6173d9275c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_querieslist.go @@ -0,0 +1,138 @@ +package querypackqueries + +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 QueriesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LogAnalyticsQueryPackQuery +} + +type QueriesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []LogAnalyticsQueryPackQuery +} + +type QueriesListOperationOptions struct { + IncludeBody *bool + Top *int64 +} + +func DefaultQueriesListOperationOptions() QueriesListOperationOptions { + return QueriesListOperationOptions{} +} + +func (o QueriesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o QueriesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o QueriesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.IncludeBody != nil { + out.Append("includeBody", fmt.Sprintf("%v", *o.IncludeBody)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type QueriesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *QueriesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// QueriesList ... +func (c QueryPackQueriesClient) QueriesList(ctx context.Context, id QueryPackId, options QueriesListOperationOptions) (result QueriesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &QueriesListCustomPager{}, + Path: fmt.Sprintf("%s/queries", 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 *[]LogAnalyticsQueryPackQuery `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// QueriesListComplete retrieves all the results into a single object +func (c QueryPackQueriesClient) QueriesListComplete(ctx context.Context, id QueryPackId, options QueriesListOperationOptions) (QueriesListCompleteResult, error) { + return c.QueriesListCompleteMatchingPredicate(ctx, id, options, LogAnalyticsQueryPackQueryOperationPredicate{}) +} + +// QueriesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QueryPackQueriesClient) QueriesListCompleteMatchingPredicate(ctx context.Context, id QueryPackId, options QueriesListOperationOptions, predicate LogAnalyticsQueryPackQueryOperationPredicate) (result QueriesListCompleteResult, err error) { + items := make([]LogAnalyticsQueryPackQuery, 0) + + resp, err := c.QueriesList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = QueriesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesput.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesput.go new file mode 100644 index 00000000000..ecf150a8195 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesput.go @@ -0,0 +1,57 @@ +package querypackqueries + +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 QueriesPutOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogAnalyticsQueryPackQuery +} + +// QueriesPut ... +func (c QueryPackQueriesClient) QueriesPut(ctx context.Context, id QueryId, input LogAnalyticsQueryPackQuery) (result QueriesPutOperationResponse, 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 LogAnalyticsQueryPackQuery + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriessearch.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriessearch.go new file mode 100644 index 00000000000..7342fa8eeec --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriessearch.go @@ -0,0 +1,138 @@ +package querypackqueries + +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 QueriesSearchOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LogAnalyticsQueryPackQuery +} + +type QueriesSearchCompleteResult struct { + LatestHttpResponse *http.Response + Items []LogAnalyticsQueryPackQuery +} + +type QueriesSearchOperationOptions struct { + IncludeBody *bool + Top *int64 +} + +func DefaultQueriesSearchOperationOptions() QueriesSearchOperationOptions { + return QueriesSearchOperationOptions{} +} + +func (o QueriesSearchOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o QueriesSearchOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o QueriesSearchOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.IncludeBody != nil { + out.Append("includeBody", fmt.Sprintf("%v", *o.IncludeBody)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type QueriesSearchCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *QueriesSearchCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// QueriesSearch ... +func (c QueryPackQueriesClient) QueriesSearch(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions) (result QueriesSearchOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &QueriesSearchCustomPager{}, + Path: fmt.Sprintf("%s/queries/search", 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 *[]LogAnalyticsQueryPackQuery `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// QueriesSearchComplete retrieves all the results into a single object +func (c QueryPackQueriesClient) QueriesSearchComplete(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions) (QueriesSearchCompleteResult, error) { + return c.QueriesSearchCompleteMatchingPredicate(ctx, id, input, options, LogAnalyticsQueryPackQueryOperationPredicate{}) +} + +// QueriesSearchCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QueryPackQueriesClient) QueriesSearchCompleteMatchingPredicate(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions, predicate LogAnalyticsQueryPackQueryOperationPredicate) (result QueriesSearchCompleteResult, err error) { + items := make([]LogAnalyticsQueryPackQuery, 0) + + resp, err := c.QueriesSearch(ctx, id, input, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = QueriesSearchCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesupdate.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesupdate.go new file mode 100644 index 00000000000..8a547b353c8 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/method_queriesupdate.go @@ -0,0 +1,57 @@ +package querypackqueries + +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 QueriesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogAnalyticsQueryPackQuery +} + +// QueriesUpdate ... +func (c QueryPackQueriesClient) QueriesUpdate(ctx context.Context, id QueryId, input LogAnalyticsQueryPackQuery) (result QueriesUpdateOperationResponse, 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 LogAnalyticsQueryPackQuery + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquery.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquery.go new file mode 100644 index 00000000000..555d2bf023c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquery.go @@ -0,0 +1,16 @@ +package querypackqueries + +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 LogAnalyticsQueryPackQuery struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LogAnalyticsQueryPackQueryProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackqueryproperties.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackqueryproperties.go new file mode 100644 index 00000000000..25dc4ae2a31 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackqueryproperties.go @@ -0,0 +1,47 @@ +package querypackqueries + +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 LogAnalyticsQueryPackQueryProperties struct { + Author *string `json:"author,omitempty"` + Body string `json:"body"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + Id *string `json:"id,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + Related *LogAnalyticsQueryPackQueryPropertiesRelated `json:"related,omitempty"` + Tags *map[string][]string `json:"tags,omitempty"` + TimeCreated *string `json:"timeCreated,omitempty"` + TimeModified *string `json:"timeModified,omitempty"` +} + +func (o *LogAnalyticsQueryPackQueryProperties) GetTimeCreatedAsTime() (*time.Time, error) { + if o.TimeCreated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeCreated, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackQueryProperties) SetTimeCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeCreated = &formatted +} + +func (o *LogAnalyticsQueryPackQueryProperties) GetTimeModifiedAsTime() (*time.Time, error) { + if o.TimeModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackQueryProperties) SetTimeModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeModified = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerypropertiesrelated.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerypropertiesrelated.go new file mode 100644 index 00000000000..5efd7bd3027 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerypropertiesrelated.go @@ -0,0 +1,10 @@ +package querypackqueries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQueryPropertiesRelated struct { + Categories *[]string `json:"categories,omitempty"` + ResourceTypes *[]string `json:"resourceTypes,omitempty"` + Solutions *[]string `json:"solutions,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchproperties.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchproperties.go new file mode 100644 index 00000000000..5845c3f78ce --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchproperties.go @@ -0,0 +1,9 @@ +package querypackqueries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQuerySearchProperties struct { + Related *LogAnalyticsQueryPackQuerySearchPropertiesRelated `json:"related,omitempty"` + Tags *map[string][]string `json:"tags,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchpropertiesrelated.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchpropertiesrelated.go new file mode 100644 index 00000000000..d2c6bc8c290 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/model_loganalyticsquerypackquerysearchpropertiesrelated.go @@ -0,0 +1,10 @@ +package querypackqueries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQuerySearchPropertiesRelated struct { + Categories *[]string `json:"categories,omitempty"` + ResourceTypes *[]string `json:"resourceTypes,omitempty"` + Solutions *[]string `json:"solutions,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypackqueries/predicates.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/predicates.go new file mode 100644 index 00000000000..38fda83f51a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/predicates.go @@ -0,0 +1,27 @@ +package querypackqueries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQueryOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LogAnalyticsQueryPackQueryOperationPredicate) Matches(input LogAnalyticsQueryPackQuery) 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/operationalinsights/2025-02-01/querypackqueries/version.go b/resource-manager/operationalinsights/2025-02-01/querypackqueries/version.go new file mode 100644 index 00000000000..404c3c1a3c0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypackqueries/version.go @@ -0,0 +1,10 @@ +package querypackqueries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/querypackqueries/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/README.md b/resource-manager/operationalinsights/2025-02-01/querypacks/README.md new file mode 100644 index 00000000000..a51ea6b0444 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/README.md @@ -0,0 +1,150 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/querypacks` Documentation + +The `querypacks` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/querypacks" +``` + + +### Client Initialization + +```go +client := querypacks.NewQueryPacksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QueryPacksClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := querypacks.NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + +payload := querypacks.LogAnalyticsQueryPack{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryPacksClient.CreateOrUpdateWithoutName` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := querypacks.LogAnalyticsQueryPack{ + // ... +} + + +read, err := client.CreateOrUpdateWithoutName(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryPacksClient.Delete` + +```go +ctx := context.TODO() +id := querypacks.NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryPacksClient.Get` + +```go +ctx := context.TODO() +id := querypacks.NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + +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: `QueryPacksClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `QueryPacksClient.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: `QueryPacksClient.UpdateTags` + +```go +ctx := context.TODO() +id := querypacks.NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + +payload := querypacks.TagsResource{ + // ... +} + + +read, err := client.UpdateTags(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/operationalinsights/2025-02-01/querypacks/client.go b/resource-manager/operationalinsights/2025-02-01/querypacks/client.go new file mode 100644 index 00000000000..5efc5278ddd --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/client.go @@ -0,0 +1,26 @@ +package querypacks + +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 QueryPacksClient struct { + Client *resourcemanager.Client +} + +func NewQueryPacksClientWithBaseURI(sdkApi sdkEnv.Api) (*QueryPacksClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "querypacks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QueryPacksClient: %+v", err) + } + + return &QueryPacksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack.go b/resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack.go new file mode 100644 index 00000000000..3fe4cc2c22f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack.go @@ -0,0 +1,130 @@ +package querypacks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QueryPackId{}) +} + +var _ resourceids.ResourceId = &QueryPackId{} + +// QueryPackId is a struct representing the Resource ID for a Query Pack +type QueryPackId struct { + SubscriptionId string + ResourceGroupName string + QueryPackName string +} + +// NewQueryPackID returns a new QueryPackId struct +func NewQueryPackID(subscriptionId string, resourceGroupName string, queryPackName string) QueryPackId { + return QueryPackId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + QueryPackName: queryPackName, + } +} + +// ParseQueryPackID parses 'input' into a QueryPackId +func ParseQueryPackID(input string) (*QueryPackId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryPackId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryPackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQueryPackIDInsensitively parses 'input' case-insensitively into a QueryPackId +// note: this method should only be used for API response data and not user input +func ParseQueryPackIDInsensitively(input string) (*QueryPackId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryPackId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryPackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QueryPackId) 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.QueryPackName, ok = input.Parsed["queryPackName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "queryPackName", input) + } + + return nil +} + +// ValidateQueryPackID checks that 'input' can be parsed as a Query Pack ID +func ValidateQueryPackID(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 := ParseQueryPackID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Query Pack ID +func (id QueryPackId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/queryPacks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.QueryPackName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Query Pack ID +func (id QueryPackId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticQueryPacks", "queryPacks", "queryPacks"), + resourceids.UserSpecifiedSegment("queryPackName", "queryPackName"), + } +} + +// String returns a human-readable description of this Query Pack ID +func (id QueryPackId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Query Pack Name: %q", id.QueryPackName), + } + return fmt.Sprintf("Query Pack (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack_test.go b/resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack_test.go new file mode 100644 index 00000000000..e5be1caa33a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/id_querypack_test.go @@ -0,0 +1,282 @@ +package querypacks + +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 = &QueryPackId{} + +func TestNewQueryPackID(t *testing.T) { + id := NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName") + + 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.QueryPackName != "queryPackName" { + t.Fatalf("Expected %q but got %q for Segment 'QueryPackName'", id.QueryPackName, "queryPackName") + } +} + +func TestFormatQueryPackID(t *testing.T) { + actual := NewQueryPackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "queryPackName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQueryPackID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryPackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName", + Expected: &QueryPackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + QueryPackName: "queryPackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryPackID(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.QueryPackName != v.Expected.QueryPackName { + t.Fatalf("Expected %q but got %q for QueryPackName", v.Expected.QueryPackName, actual.QueryPackName) + } + + } +} + +func TestParseQueryPackIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryPackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName", + Expected: &QueryPackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + QueryPackName: "queryPackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/queryPacks/queryPackName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe", + Expected: &QueryPackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + QueryPackName: "qUeRyPaCkNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/qUeRyPaCkS/qUeRyPaCkNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryPackIDInsensitively(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.QueryPackName != v.Expected.QueryPackName { + t.Fatalf("Expected %q but got %q for QueryPackName", v.Expected.QueryPackName, actual.QueryPackName) + } + + } +} + +func TestSegmentsForQueryPackId(t *testing.T) { + segments := QueryPackId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QueryPackId 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/operationalinsights/2025-02-01/querypacks/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdate.go new file mode 100644 index 00000000000..779d071fbae --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdate.go @@ -0,0 +1,57 @@ +package querypacks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogAnalyticsQueryPack +} + +// CreateOrUpdate ... +func (c QueryPacksClient) CreateOrUpdate(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPack) (result CreateOrUpdateOperationResponse, 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 LogAnalyticsQueryPack + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdatewithoutname.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdatewithoutname.go new file mode 100644 index 00000000000..08a4740145c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_createorupdatewithoutname.go @@ -0,0 +1,59 @@ +package querypacks + +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 CreateOrUpdateWithoutNameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogAnalyticsQueryPack +} + +// CreateOrUpdateWithoutName ... +func (c QueryPacksClient) CreateOrUpdateWithoutName(ctx context.Context, id commonids.ResourceGroupId, input LogAnalyticsQueryPack) (result CreateOrUpdateWithoutNameOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/queryPacks", 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 LogAnalyticsQueryPack + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/method_delete.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_delete.go new file mode 100644 index 00000000000..c9137572bc3 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_delete.go @@ -0,0 +1,47 @@ +package querypacks + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c QueryPacksClient) Delete(ctx context.Context, id QueryPackId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/method_get.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_get.go new file mode 100644 index 00000000000..019de126545 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_get.go @@ -0,0 +1,53 @@ +package querypacks + +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 *LogAnalyticsQueryPack +} + +// Get ... +func (c QueryPacksClient) Get(ctx context.Context, id QueryPackId) (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 LogAnalyticsQueryPack + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/method_list.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_list.go new file mode 100644 index 00000000000..32b92f450e9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_list.go @@ -0,0 +1,106 @@ +package querypacks + +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 *[]LogAnalyticsQueryPack +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []LogAnalyticsQueryPack +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c QueryPacksClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/queryPacks", 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 *[]LogAnalyticsQueryPack `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 QueryPacksClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, LogAnalyticsQueryPackOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QueryPacksClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate LogAnalyticsQueryPackOperationPredicate) (result ListCompleteResult, err error) { + items := make([]LogAnalyticsQueryPack, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/method_listbyresourcegroup.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_listbyresourcegroup.go new file mode 100644 index 00000000000..e856e976ce0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package querypacks + +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 *[]LogAnalyticsQueryPack +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []LogAnalyticsQueryPack +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c QueryPacksClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/queryPacks", 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 *[]LogAnalyticsQueryPack `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 QueryPacksClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, LogAnalyticsQueryPackOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QueryPacksClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate LogAnalyticsQueryPackOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]LogAnalyticsQueryPack, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/method_updatetags.go b/resource-manager/operationalinsights/2025-02-01/querypacks/method_updatetags.go new file mode 100644 index 00000000000..d4f83732840 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/method_updatetags.go @@ -0,0 +1,57 @@ +package querypacks + +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 UpdateTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogAnalyticsQueryPack +} + +// UpdateTags ... +func (c QueryPacksClient) UpdateTags(ctx context.Context, id QueryPackId, input TagsResource) (result UpdateTagsOperationResponse, 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 LogAnalyticsQueryPack + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypack.go b/resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypack.go new file mode 100644 index 00000000000..d71c1289066 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypack.go @@ -0,0 +1,18 @@ +package querypacks + +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 LogAnalyticsQueryPack struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties LogAnalyticsQueryPackProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypackproperties.go b/resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypackproperties.go new file mode 100644 index 00000000000..772445a81e8 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/model_loganalyticsquerypackproperties.go @@ -0,0 +1,41 @@ +package querypacks + +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 LogAnalyticsQueryPackProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` + QueryPackId *string `json:"queryPackId,omitempty"` + TimeCreated *string `json:"timeCreated,omitempty"` + TimeModified *string `json:"timeModified,omitempty"` +} + +func (o *LogAnalyticsQueryPackProperties) GetTimeCreatedAsTime() (*time.Time, error) { + if o.TimeCreated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeCreated, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackProperties) SetTimeCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeCreated = &formatted +} + +func (o *LogAnalyticsQueryPackProperties) GetTimeModifiedAsTime() (*time.Time, error) { + if o.TimeModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackProperties) SetTimeModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeModified = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/model_tagsresource.go b/resource-manager/operationalinsights/2025-02-01/querypacks/model_tagsresource.go new file mode 100644 index 00000000000..7fdf7eeb6c5 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/model_tagsresource.go @@ -0,0 +1,8 @@ +package querypacks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsResource struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/querypacks/predicates.go b/resource-manager/operationalinsights/2025-02-01/querypacks/predicates.go new file mode 100644 index 00000000000..46c21c9f019 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/predicates.go @@ -0,0 +1,32 @@ +package querypacks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p LogAnalyticsQueryPackOperationPredicate) Matches(input LogAnalyticsQueryPack) 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/operationalinsights/2025-02-01/querypacks/version.go b/resource-manager/operationalinsights/2025-02-01/querypacks/version.go new file mode 100644 index 00000000000..c3a5be7be7e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/querypacks/version.go @@ -0,0 +1,10 @@ +package querypacks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/querypacks/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/README.md b/resource-manager/operationalinsights/2025-02-01/savedsearches/README.md new file mode 100644 index 00000000000..5a5812930fe --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/savedsearches` Documentation + +The `savedsearches` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/savedsearches" +``` + + +### Client Initialization + +```go +client := savedsearches.NewSavedSearchesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SavedSearchesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := savedsearches.NewSavedSearchID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "savedSearchId") + +payload := savedsearches.SavedSearch{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SavedSearchesClient.Delete` + +```go +ctx := context.TODO() +id := savedsearches.NewSavedSearchID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "savedSearchId") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SavedSearchesClient.Get` + +```go +ctx := context.TODO() +id := savedsearches.NewSavedSearchID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "savedSearchId") + +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: `SavedSearchesClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := savedsearches.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/client.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/client.go new file mode 100644 index 00000000000..feb243cf4e4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/client.go @@ -0,0 +1,26 @@ +package savedsearches + +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 SavedSearchesClient struct { + Client *resourcemanager.Client +} + +func NewSavedSearchesClientWithBaseURI(sdkApi sdkEnv.Api) (*SavedSearchesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "savedsearches", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SavedSearchesClient: %+v", err) + } + + return &SavedSearchesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch.go new file mode 100644 index 00000000000..ede0c729bf5 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch.go @@ -0,0 +1,139 @@ +package savedsearches + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SavedSearchId{}) +} + +var _ resourceids.ResourceId = &SavedSearchId{} + +// SavedSearchId is a struct representing the Resource ID for a Saved Search +type SavedSearchId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SavedSearchId string +} + +// NewSavedSearchID returns a new SavedSearchId struct +func NewSavedSearchID(subscriptionId string, resourceGroupName string, workspaceName string, savedSearchId string) SavedSearchId { + return SavedSearchId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SavedSearchId: savedSearchId, + } +} + +// ParseSavedSearchID parses 'input' into a SavedSearchId +func ParseSavedSearchID(input string) (*SavedSearchId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavedSearchId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavedSearchId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSavedSearchIDInsensitively parses 'input' case-insensitively into a SavedSearchId +// note: this method should only be used for API response data and not user input +func ParseSavedSearchIDInsensitively(input string) (*SavedSearchId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavedSearchId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavedSearchId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SavedSearchId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SavedSearchId, ok = input.Parsed["savedSearchId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savedSearchId", input) + } + + return nil +} + +// ValidateSavedSearchID checks that 'input' can be parsed as a Saved Search ID +func ValidateSavedSearchID(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 := ParseSavedSearchID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Saved Search ID +func (id SavedSearchId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/savedSearches/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SavedSearchId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Saved Search ID +func (id SavedSearchId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticSavedSearches", "savedSearches", "savedSearches"), + resourceids.UserSpecifiedSegment("savedSearchId", "savedSearchId"), + } +} + +// String returns a human-readable description of this Saved Search ID +func (id SavedSearchId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Saved Search: %q", id.SavedSearchId), + } + return fmt.Sprintf("Saved Search (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch_test.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch_test.go new file mode 100644 index 00000000000..6581bd1a01b --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_savedsearch_test.go @@ -0,0 +1,327 @@ +package savedsearches + +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 = &SavedSearchId{} + +func TestNewSavedSearchID(t *testing.T) { + id := NewSavedSearchID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "savedSearchId") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.SavedSearchId != "savedSearchId" { + t.Fatalf("Expected %q but got %q for Segment 'SavedSearchId'", id.SavedSearchId, "savedSearchId") + } +} + +func TestFormatSavedSearchID(t *testing.T) { + actual := NewSavedSearchID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "savedSearchId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches/savedSearchId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSavedSearchID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavedSearchId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches/savedSearchId", + Expected: &SavedSearchId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + SavedSearchId: "savedSearchId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches/savedSearchId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavedSearchID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SavedSearchId != v.Expected.SavedSearchId { + t.Fatalf("Expected %q but got %q for SavedSearchId", v.Expected.SavedSearchId, actual.SavedSearchId) + } + + } +} + +func TestParseSavedSearchIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavedSearchId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/sAvEdSeArChEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches/savedSearchId", + Expected: &SavedSearchId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + SavedSearchId: "savedSearchId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/savedSearches/savedSearchId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/sAvEdSeArChEs/sAvEdSeArChId", + Expected: &SavedSearchId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + SavedSearchId: "sAvEdSeArChId", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/sAvEdSeArChEs/sAvEdSeArChId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavedSearchIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SavedSearchId != v.Expected.SavedSearchId { + t.Fatalf("Expected %q but got %q for SavedSearchId", v.Expected.SavedSearchId, actual.SavedSearchId) + } + + } +} + +func TestSegmentsForSavedSearchId(t *testing.T) { + segments := SavedSearchId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SavedSearchId 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/operationalinsights/2025-02-01/savedsearches/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace.go new file mode 100644 index 00000000000..bbbfffcfced --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace.go @@ -0,0 +1,130 @@ +package savedsearches + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace_test.go new file mode 100644 index 00000000000..906f8179a44 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/id_workspace_test.go @@ -0,0 +1,282 @@ +package savedsearches + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/savedsearches/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_createorupdate.go new file mode 100644 index 00000000000..69d3a92a12d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_createorupdate.go @@ -0,0 +1,57 @@ +package savedsearches + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SavedSearch +} + +// CreateOrUpdate ... +func (c SavedSearchesClient) CreateOrUpdate(ctx context.Context, id SavedSearchId, input SavedSearch) (result CreateOrUpdateOperationResponse, 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 SavedSearch + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/method_delete.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_delete.go new file mode 100644 index 00000000000..26ca123124e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_delete.go @@ -0,0 +1,46 @@ +package savedsearches + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SavedSearchesClient) Delete(ctx context.Context, id SavedSearchId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/method_get.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_get.go new file mode 100644 index 00000000000..cd5ba498ecb --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_get.go @@ -0,0 +1,53 @@ +package savedsearches + +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 *SavedSearch +} + +// Get ... +func (c SavedSearchesClient) Get(ctx context.Context, id SavedSearchId) (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 SavedSearch + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_listbyworkspace.go new file mode 100644 index 00000000000..6c253f74e3a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/method_listbyworkspace.go @@ -0,0 +1,54 @@ +package savedsearches + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SavedSearchesListResult +} + +// ListByWorkspace ... +func (c SavedSearchesClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/savedSearches", 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 SavedSearchesListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearch.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearch.go new file mode 100644 index 00000000000..0468b07d4a2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearch.go @@ -0,0 +1,12 @@ +package savedsearches + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SavedSearch struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties SavedSearchProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearcheslistresult.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearcheslistresult.go new file mode 100644 index 00000000000..344ab1af380 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearcheslistresult.go @@ -0,0 +1,8 @@ +package savedsearches + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SavedSearchesListResult struct { + Value *[]SavedSearch `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearchproperties.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearchproperties.go new file mode 100644 index 00000000000..ab34bf3b4d1 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_savedsearchproperties.go @@ -0,0 +1,14 @@ +package savedsearches + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SavedSearchProperties struct { + Category string `json:"category"` + DisplayName string `json:"displayName"` + FunctionAlias *string `json:"functionAlias,omitempty"` + FunctionParameters *string `json:"functionParameters,omitempty"` + Query string `json:"query"` + Tags *[]Tag `json:"tags,omitempty"` + Version *int64 `json:"version,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/model_tag.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_tag.go new file mode 100644 index 00000000000..f2071dd9101 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/model_tag.go @@ -0,0 +1,9 @@ +package savedsearches + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Tag struct { + Name string `json:"name"` + Value string `json:"value"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/savedsearches/version.go b/resource-manager/operationalinsights/2025-02-01/savedsearches/version.go new file mode 100644 index 00000000000..368051ecaf0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/savedsearches/version.go @@ -0,0 +1,10 @@ +package savedsearches + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/savedsearches/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/README.md b/resource-manager/operationalinsights/2025-02-01/storageinsights/README.md new file mode 100644 index 00000000000..44db505eb9d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/storageinsights` Documentation + +The `storageinsights` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/storageinsights" +``` + + +### Client Initialization + +```go +client := storageinsights.NewStorageInsightsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StorageInsightsClient.StorageInsightConfigsCreateOrUpdate` + +```go +ctx := context.TODO() +id := storageinsights.NewStorageInsightConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "storageInsightConfigName") + +payload := storageinsights.StorageInsight{ + // ... +} + + +read, err := client.StorageInsightConfigsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StorageInsightsClient.StorageInsightConfigsDelete` + +```go +ctx := context.TODO() +id := storageinsights.NewStorageInsightConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "storageInsightConfigName") + +read, err := client.StorageInsightConfigsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StorageInsightsClient.StorageInsightConfigsGet` + +```go +ctx := context.TODO() +id := storageinsights.NewStorageInsightConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "storageInsightConfigName") + +read, err := client.StorageInsightConfigsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StorageInsightsClient.StorageInsightConfigsListByWorkspace` + +```go +ctx := context.TODO() +id := storageinsights.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +// alternatively `client.StorageInsightConfigsListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.StorageInsightConfigsListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/client.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/client.go new file mode 100644 index 00000000000..8db4661f572 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/client.go @@ -0,0 +1,26 @@ +package storageinsights + +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 StorageInsightsClient struct { + Client *resourcemanager.Client +} + +func NewStorageInsightsClientWithBaseURI(sdkApi sdkEnv.Api) (*StorageInsightsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "storageinsights", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StorageInsightsClient: %+v", err) + } + + return &StorageInsightsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/constants.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/constants.go new file mode 100644 index 00000000000..64295d09d1f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/constants.go @@ -0,0 +1,51 @@ +package storageinsights + +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 StorageInsightState string + +const ( + StorageInsightStateERROR StorageInsightState = "ERROR" + StorageInsightStateOK StorageInsightState = "OK" +) + +func PossibleValuesForStorageInsightState() []string { + return []string{ + string(StorageInsightStateERROR), + string(StorageInsightStateOK), + } +} + +func (s *StorageInsightState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageInsightState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageInsightState(input string) (*StorageInsightState, error) { + vals := map[string]StorageInsightState{ + "error": StorageInsightStateERROR, + "ok": StorageInsightStateOK, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageInsightState(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig.go new file mode 100644 index 00000000000..93477fb129e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig.go @@ -0,0 +1,139 @@ +package storageinsights + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StorageInsightConfigId{}) +} + +var _ resourceids.ResourceId = &StorageInsightConfigId{} + +// StorageInsightConfigId is a struct representing the Resource ID for a Storage Insight Config +type StorageInsightConfigId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + StorageInsightConfigName string +} + +// NewStorageInsightConfigID returns a new StorageInsightConfigId struct +func NewStorageInsightConfigID(subscriptionId string, resourceGroupName string, workspaceName string, storageInsightConfigName string) StorageInsightConfigId { + return StorageInsightConfigId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + StorageInsightConfigName: storageInsightConfigName, + } +} + +// ParseStorageInsightConfigID parses 'input' into a StorageInsightConfigId +func ParseStorageInsightConfigID(input string) (*StorageInsightConfigId, error) { + parser := resourceids.NewParserFromResourceIdType(&StorageInsightConfigId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StorageInsightConfigId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStorageInsightConfigIDInsensitively parses 'input' case-insensitively into a StorageInsightConfigId +// note: this method should only be used for API response data and not user input +func ParseStorageInsightConfigIDInsensitively(input string) (*StorageInsightConfigId, error) { + parser := resourceids.NewParserFromResourceIdType(&StorageInsightConfigId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StorageInsightConfigId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StorageInsightConfigId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.StorageInsightConfigName, ok = input.Parsed["storageInsightConfigName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "storageInsightConfigName", input) + } + + return nil +} + +// ValidateStorageInsightConfigID checks that 'input' can be parsed as a Storage Insight Config ID +func ValidateStorageInsightConfigID(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 := ParseStorageInsightConfigID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Storage Insight Config ID +func (id StorageInsightConfigId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/storageInsightConfigs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.StorageInsightConfigName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Storage Insight Config ID +func (id StorageInsightConfigId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticStorageInsightConfigs", "storageInsightConfigs", "storageInsightConfigs"), + resourceids.UserSpecifiedSegment("storageInsightConfigName", "storageInsightConfigName"), + } +} + +// String returns a human-readable description of this Storage Insight Config ID +func (id StorageInsightConfigId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Storage Insight Config Name: %q", id.StorageInsightConfigName), + } + return fmt.Sprintf("Storage Insight Config (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig_test.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig_test.go new file mode 100644 index 00000000000..286f5f06c59 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_storageinsightconfig_test.go @@ -0,0 +1,327 @@ +package storageinsights + +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 = &StorageInsightConfigId{} + +func TestNewStorageInsightConfigID(t *testing.T) { + id := NewStorageInsightConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "storageInsightConfigName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.StorageInsightConfigName != "storageInsightConfigName" { + t.Fatalf("Expected %q but got %q for Segment 'StorageInsightConfigName'", id.StorageInsightConfigName, "storageInsightConfigName") + } +} + +func TestFormatStorageInsightConfigID(t *testing.T) { + actual := NewStorageInsightConfigID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "storageInsightConfigName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs/storageInsightConfigName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStorageInsightConfigID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StorageInsightConfigId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs/storageInsightConfigName", + Expected: &StorageInsightConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + StorageInsightConfigName: "storageInsightConfigName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs/storageInsightConfigName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStorageInsightConfigID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.StorageInsightConfigName != v.Expected.StorageInsightConfigName { + t.Fatalf("Expected %q but got %q for StorageInsightConfigName", v.Expected.StorageInsightConfigName, actual.StorageInsightConfigName) + } + + } +} + +func TestParseStorageInsightConfigIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StorageInsightConfigId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/sToRaGeInSiGhTcOnFiGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs/storageInsightConfigName", + Expected: &StorageInsightConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + StorageInsightConfigName: "storageInsightConfigName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/storageInsightConfigs/storageInsightConfigName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/sToRaGeInSiGhTcOnFiGs/sToRaGeInSiGhTcOnFiGnAmE", + Expected: &StorageInsightConfigId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + StorageInsightConfigName: "sToRaGeInSiGhTcOnFiGnAmE", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/sToRaGeInSiGhTcOnFiGs/sToRaGeInSiGhTcOnFiGnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStorageInsightConfigIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.StorageInsightConfigName != v.Expected.StorageInsightConfigName { + t.Fatalf("Expected %q but got %q for StorageInsightConfigName", v.Expected.StorageInsightConfigName, actual.StorageInsightConfigName) + } + + } +} + +func TestSegmentsForStorageInsightConfigId(t *testing.T) { + segments := StorageInsightConfigId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StorageInsightConfigId 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/operationalinsights/2025-02-01/storageinsights/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace.go new file mode 100644 index 00000000000..f90f45ddb97 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace.go @@ -0,0 +1,130 @@ +package storageinsights + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace_test.go new file mode 100644 index 00000000000..99dcec64147 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/id_workspace_test.go @@ -0,0 +1,282 @@ +package storageinsights + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigscreateorupdate.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigscreateorupdate.go new file mode 100644 index 00000000000..8f2360466e4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigscreateorupdate.go @@ -0,0 +1,58 @@ +package storageinsights + +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 StorageInsightConfigsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StorageInsight +} + +// StorageInsightConfigsCreateOrUpdate ... +func (c StorageInsightsClient) StorageInsightConfigsCreateOrUpdate(ctx context.Context, id StorageInsightConfigId, input StorageInsight) (result StorageInsightConfigsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StorageInsight + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsdelete.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsdelete.go new file mode 100644 index 00000000000..c77f95ac83c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsdelete.go @@ -0,0 +1,47 @@ +package storageinsights + +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 StorageInsightConfigsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// StorageInsightConfigsDelete ... +func (c StorageInsightsClient) StorageInsightConfigsDelete(ctx context.Context, id StorageInsightConfigId) (result StorageInsightConfigsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsget.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsget.go new file mode 100644 index 00000000000..ec74aa1f07c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigsget.go @@ -0,0 +1,53 @@ +package storageinsights + +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 StorageInsightConfigsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StorageInsight +} + +// StorageInsightConfigsGet ... +func (c StorageInsightsClient) StorageInsightConfigsGet(ctx context.Context, id StorageInsightConfigId) (result StorageInsightConfigsGetOperationResponse, 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 StorageInsight + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigslistbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigslistbyworkspace.go new file mode 100644 index 00000000000..eaed4a10791 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/method_storageinsightconfigslistbyworkspace.go @@ -0,0 +1,105 @@ +package storageinsights + +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 StorageInsightConfigsListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StorageInsight +} + +type StorageInsightConfigsListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []StorageInsight +} + +type StorageInsightConfigsListByWorkspaceCustomPager struct { + NextLink *odata.Link `json:"@odata.nextLink"` +} + +func (p *StorageInsightConfigsListByWorkspaceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// StorageInsightConfigsListByWorkspace ... +func (c StorageInsightsClient) StorageInsightConfigsListByWorkspace(ctx context.Context, id WorkspaceId) (result StorageInsightConfigsListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &StorageInsightConfigsListByWorkspaceCustomPager{}, + Path: fmt.Sprintf("%s/storageInsightConfigs", 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 *[]StorageInsight `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// StorageInsightConfigsListByWorkspaceComplete retrieves all the results into a single object +func (c StorageInsightsClient) StorageInsightConfigsListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (StorageInsightConfigsListByWorkspaceCompleteResult, error) { + return c.StorageInsightConfigsListByWorkspaceCompleteMatchingPredicate(ctx, id, StorageInsightOperationPredicate{}) +} + +// StorageInsightConfigsListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StorageInsightsClient) StorageInsightConfigsListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate StorageInsightOperationPredicate) (result StorageInsightConfigsListByWorkspaceCompleteResult, err error) { + items := make([]StorageInsight, 0) + + resp, err := c.StorageInsightConfigsListByWorkspace(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = StorageInsightConfigsListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageaccount.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageaccount.go new file mode 100644 index 00000000000..101ce95c041 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageaccount.go @@ -0,0 +1,9 @@ +package storageinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageAccount struct { + Id string `json:"id"` + Key string `json:"key"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsight.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsight.go new file mode 100644 index 00000000000..c1d70f2d0b6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsight.go @@ -0,0 +1,13 @@ +package storageinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageInsight struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StorageInsightProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightproperties.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightproperties.go new file mode 100644 index 00000000000..7042ba2c8d2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightproperties.go @@ -0,0 +1,11 @@ +package storageinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageInsightProperties struct { + Containers *[]string `json:"containers,omitempty"` + Status *StorageInsightStatus `json:"status,omitempty"` + StorageAccount StorageAccount `json:"storageAccount"` + Tables *[]string `json:"tables,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightstatus.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightstatus.go new file mode 100644 index 00000000000..33051fdac25 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/model_storageinsightstatus.go @@ -0,0 +1,9 @@ +package storageinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageInsightStatus struct { + Description *string `json:"description,omitempty"` + State StorageInsightState `json:"state"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/storageinsights/predicates.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/predicates.go new file mode 100644 index 00000000000..c926b61601e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/predicates.go @@ -0,0 +1,32 @@ +package storageinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageInsightOperationPredicate struct { + ETag *string + Id *string + Name *string + Type *string +} + +func (p StorageInsightOperationPredicate) Matches(input StorageInsight) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/operationalinsights/2025-02-01/storageinsights/version.go b/resource-manager/operationalinsights/2025-02-01/storageinsights/version.go new file mode 100644 index 00000000000..4f6c8ed236f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/storageinsights/version.go @@ -0,0 +1,10 @@ +package storageinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/storageinsights/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/README.md b/resource-manager/operationalinsights/2025-02-01/tables/README.md new file mode 100644 index 00000000000..c7bd37a08e9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/README.md @@ -0,0 +1,130 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/tables` Documentation + +The `tables` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/tables" +``` + + +### Client Initialization + +```go +client := tables.NewTablesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TablesClient.CancelSearch` + +```go +ctx := context.TODO() +id := tables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + +read, err := client.CancelSearch(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TablesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + +payload := tables.Table{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TablesClient.Delete` + +```go +ctx := context.TODO() +id := tables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TablesClient.Get` + +```go +ctx := context.TODO() +id := tables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + +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: `TablesClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := tables.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TablesClient.Migrate` + +```go +ctx := context.TODO() +id := tables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + +read, err := client.Migrate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TablesClient.Update` + +```go +ctx := context.TODO() +id := tables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + +payload := tables.Table{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/operationalinsights/2025-02-01/tables/client.go b/resource-manager/operationalinsights/2025-02-01/tables/client.go new file mode 100644 index 00000000000..d448018bd46 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/client.go @@ -0,0 +1,26 @@ +package tables + +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 TablesClient struct { + Client *resourcemanager.Client +} + +func NewTablesClientWithBaseURI(sdkApi sdkEnv.Api) (*TablesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "tables", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TablesClient: %+v", err) + } + + return &TablesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/constants.go b/resource-manager/operationalinsights/2025-02-01/tables/constants.go new file mode 100644 index 00000000000..3b59c402f7c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/constants.go @@ -0,0 +1,336 @@ +package tables + +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 ColumnDataTypeHintEnum string + +const ( + ColumnDataTypeHintEnumArmPath ColumnDataTypeHintEnum = "armPath" + ColumnDataTypeHintEnumGuid ColumnDataTypeHintEnum = "guid" + ColumnDataTypeHintEnumIP ColumnDataTypeHintEnum = "ip" + ColumnDataTypeHintEnumUri ColumnDataTypeHintEnum = "uri" +) + +func PossibleValuesForColumnDataTypeHintEnum() []string { + return []string{ + string(ColumnDataTypeHintEnumArmPath), + string(ColumnDataTypeHintEnumGuid), + string(ColumnDataTypeHintEnumIP), + string(ColumnDataTypeHintEnumUri), + } +} + +func (s *ColumnDataTypeHintEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseColumnDataTypeHintEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseColumnDataTypeHintEnum(input string) (*ColumnDataTypeHintEnum, error) { + vals := map[string]ColumnDataTypeHintEnum{ + "armpath": ColumnDataTypeHintEnumArmPath, + "guid": ColumnDataTypeHintEnumGuid, + "ip": ColumnDataTypeHintEnumIP, + "uri": ColumnDataTypeHintEnumUri, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ColumnDataTypeHintEnum(input) + return &out, nil +} + +type ColumnTypeEnum string + +const ( + ColumnTypeEnumBoolean ColumnTypeEnum = "boolean" + ColumnTypeEnumDateTime ColumnTypeEnum = "dateTime" + ColumnTypeEnumDynamic ColumnTypeEnum = "dynamic" + ColumnTypeEnumGuid ColumnTypeEnum = "guid" + ColumnTypeEnumInt ColumnTypeEnum = "int" + ColumnTypeEnumLong ColumnTypeEnum = "long" + ColumnTypeEnumReal ColumnTypeEnum = "real" + ColumnTypeEnumString ColumnTypeEnum = "string" +) + +func PossibleValuesForColumnTypeEnum() []string { + return []string{ + string(ColumnTypeEnumBoolean), + string(ColumnTypeEnumDateTime), + string(ColumnTypeEnumDynamic), + string(ColumnTypeEnumGuid), + string(ColumnTypeEnumInt), + string(ColumnTypeEnumLong), + string(ColumnTypeEnumReal), + string(ColumnTypeEnumString), + } +} + +func (s *ColumnTypeEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseColumnTypeEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseColumnTypeEnum(input string) (*ColumnTypeEnum, error) { + vals := map[string]ColumnTypeEnum{ + "boolean": ColumnTypeEnumBoolean, + "datetime": ColumnTypeEnumDateTime, + "dynamic": ColumnTypeEnumDynamic, + "guid": ColumnTypeEnumGuid, + "int": ColumnTypeEnumInt, + "long": ColumnTypeEnumLong, + "real": ColumnTypeEnumReal, + "string": ColumnTypeEnumString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ColumnTypeEnum(input) + return &out, nil +} + +type ProvisioningStateEnum string + +const ( + ProvisioningStateEnumDeleting ProvisioningStateEnum = "Deleting" + ProvisioningStateEnumInProgress ProvisioningStateEnum = "InProgress" + ProvisioningStateEnumSucceeded ProvisioningStateEnum = "Succeeded" + ProvisioningStateEnumUpdating ProvisioningStateEnum = "Updating" +) + +func PossibleValuesForProvisioningStateEnum() []string { + return []string{ + string(ProvisioningStateEnumDeleting), + string(ProvisioningStateEnumInProgress), + string(ProvisioningStateEnumSucceeded), + string(ProvisioningStateEnumUpdating), + } +} + +func (s *ProvisioningStateEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningStateEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningStateEnum(input string) (*ProvisioningStateEnum, error) { + vals := map[string]ProvisioningStateEnum{ + "deleting": ProvisioningStateEnumDeleting, + "inprogress": ProvisioningStateEnumInProgress, + "succeeded": ProvisioningStateEnumSucceeded, + "updating": ProvisioningStateEnumUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningStateEnum(input) + return &out, nil +} + +type SourceEnum string + +const ( + SourceEnumCustomer SourceEnum = "customer" + SourceEnumMicrosoft SourceEnum = "microsoft" +) + +func PossibleValuesForSourceEnum() []string { + return []string{ + string(SourceEnumCustomer), + string(SourceEnumMicrosoft), + } +} + +func (s *SourceEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceEnum(input string) (*SourceEnum, error) { + vals := map[string]SourceEnum{ + "customer": SourceEnumCustomer, + "microsoft": SourceEnumMicrosoft, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceEnum(input) + return &out, nil +} + +type TablePlanEnum string + +const ( + TablePlanEnumAnalytics TablePlanEnum = "Analytics" + TablePlanEnumBasic TablePlanEnum = "Basic" +) + +func PossibleValuesForTablePlanEnum() []string { + return []string{ + string(TablePlanEnumAnalytics), + string(TablePlanEnumBasic), + } +} + +func (s *TablePlanEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTablePlanEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTablePlanEnum(input string) (*TablePlanEnum, error) { + vals := map[string]TablePlanEnum{ + "analytics": TablePlanEnumAnalytics, + "basic": TablePlanEnumBasic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TablePlanEnum(input) + return &out, nil +} + +type TableSubTypeEnum string + +const ( + TableSubTypeEnumAny TableSubTypeEnum = "Any" + TableSubTypeEnumClassic TableSubTypeEnum = "Classic" + TableSubTypeEnumDataCollectionRuleBased TableSubTypeEnum = "DataCollectionRuleBased" +) + +func PossibleValuesForTableSubTypeEnum() []string { + return []string{ + string(TableSubTypeEnumAny), + string(TableSubTypeEnumClassic), + string(TableSubTypeEnumDataCollectionRuleBased), + } +} + +func (s *TableSubTypeEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTableSubTypeEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTableSubTypeEnum(input string) (*TableSubTypeEnum, error) { + vals := map[string]TableSubTypeEnum{ + "any": TableSubTypeEnumAny, + "classic": TableSubTypeEnumClassic, + "datacollectionrulebased": TableSubTypeEnumDataCollectionRuleBased, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TableSubTypeEnum(input) + return &out, nil +} + +type TableTypeEnum string + +const ( + TableTypeEnumCustomLog TableTypeEnum = "CustomLog" + TableTypeEnumMicrosoft TableTypeEnum = "Microsoft" + TableTypeEnumRestoredLogs TableTypeEnum = "RestoredLogs" + TableTypeEnumSearchResults TableTypeEnum = "SearchResults" +) + +func PossibleValuesForTableTypeEnum() []string { + return []string{ + string(TableTypeEnumCustomLog), + string(TableTypeEnumMicrosoft), + string(TableTypeEnumRestoredLogs), + string(TableTypeEnumSearchResults), + } +} + +func (s *TableTypeEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTableTypeEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTableTypeEnum(input string) (*TableTypeEnum, error) { + vals := map[string]TableTypeEnum{ + "customlog": TableTypeEnumCustomLog, + "microsoft": TableTypeEnumMicrosoft, + "restoredlogs": TableTypeEnumRestoredLogs, + "searchresults": TableTypeEnumSearchResults, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TableTypeEnum(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/id_table.go b/resource-manager/operationalinsights/2025-02-01/tables/id_table.go new file mode 100644 index 00000000000..5dbc9e51d28 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/id_table.go @@ -0,0 +1,139 @@ +package tables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TableId{}) +} + +var _ resourceids.ResourceId = &TableId{} + +// TableId is a struct representing the Resource ID for a Table +type TableId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + TableName string +} + +// NewTableID returns a new TableId struct +func NewTableID(subscriptionId string, resourceGroupName string, workspaceName string, tableName string) TableId { + return TableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + TableName: tableName, + } +} + +// ParseTableID parses 'input' into a TableId +func ParseTableID(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableIDInsensitively parses 'input' case-insensitively into a TableId +// note: this method should only be used for API response data and not user input +func ParseTableIDInsensitively(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateTableID checks that 'input' can be parsed as a Table ID +func ValidateTableID(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 := ParseTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table ID +func (id TableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table ID +func (id TableId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + } +} + +// String returns a human-readable description of this Table ID +func (id TableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/id_table_test.go b/resource-manager/operationalinsights/2025-02-01/tables/id_table_test.go new file mode 100644 index 00000000000..1cbf7d3ee33 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/id_table_test.go @@ -0,0 +1,327 @@ +package tables + +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 = &TableId{} + +func TestNewTableID(t *testing.T) { + id := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "tableName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables/tableName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables/tableName", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables/tableName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables/tableName", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/tables/tableName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/tAbLeS/tAbLeNaMe", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + TableName: "tAbLeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/tAbLeS/tAbLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForTableId(t *testing.T) { + segments := TableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableId 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/operationalinsights/2025-02-01/tables/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/tables/id_workspace.go new file mode 100644 index 00000000000..a7abfc487d3 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/id_workspace.go @@ -0,0 +1,130 @@ +package tables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/tables/id_workspace_test.go new file mode 100644 index 00000000000..81bae7e5dab --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/id_workspace_test.go @@ -0,0 +1,282 @@ +package tables + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/tables/method_cancelsearch.go b/resource-manager/operationalinsights/2025-02-01/tables/method_cancelsearch.go new file mode 100644 index 00000000000..5268e6542a7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_cancelsearch.go @@ -0,0 +1,47 @@ +package tables + +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 CancelSearchOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CancelSearch ... +func (c TablesClient) CancelSearch(ctx context.Context, id TableId) (result CancelSearchOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancelSearch", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/tables/method_createorupdate.go new file mode 100644 index 00000000000..9b7a84a5224 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_createorupdate.go @@ -0,0 +1,75 @@ +package tables + +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 *Table +} + +// CreateOrUpdate ... +func (c TablesClient) CreateOrUpdate(ctx context.Context, id TableId, input Table) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c TablesClient) CreateOrUpdateThenPoll(ctx context.Context, id TableId, input Table) 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/operationalinsights/2025-02-01/tables/method_delete.go b/resource-manager/operationalinsights/2025-02-01/tables/method_delete.go new file mode 100644 index 00000000000..26e68dd6ed8 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_delete.go @@ -0,0 +1,71 @@ +package tables + +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 TablesClient) Delete(ctx context.Context, id TableId) (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 TablesClient) DeleteThenPoll(ctx context.Context, id TableId) 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/operationalinsights/2025-02-01/tables/method_get.go b/resource-manager/operationalinsights/2025-02-01/tables/method_get.go new file mode 100644 index 00000000000..6418a17d96d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_get.go @@ -0,0 +1,53 @@ +package tables + +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 *Table +} + +// Get ... +func (c TablesClient) Get(ctx context.Context, id TableId) (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 Table + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/method_listbyworkspace.go b/resource-manager/operationalinsights/2025-02-01/tables/method_listbyworkspace.go new file mode 100644 index 00000000000..a22495c0a5e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_listbyworkspace.go @@ -0,0 +1,54 @@ +package tables + +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 ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TablesListResult +} + +// ListByWorkspace ... +func (c TablesClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/tables", 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 TablesListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/method_migrate.go b/resource-manager/operationalinsights/2025-02-01/tables/method_migrate.go new file mode 100644 index 00000000000..af5f8e9acd1 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_migrate.go @@ -0,0 +1,47 @@ +package tables + +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 MigrateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Migrate ... +func (c TablesClient) Migrate(ctx context.Context, id TableId) (result MigrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/migrate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/method_update.go b/resource-manager/operationalinsights/2025-02-01/tables/method_update.go new file mode 100644 index 00000000000..d863c869ec7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/method_update.go @@ -0,0 +1,75 @@ +package tables + +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 *Table +} + +// Update ... +func (c TablesClient) Update(ctx context.Context, id TableId, input Table) (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 TablesClient) UpdateThenPoll(ctx context.Context, id TableId, input Table) 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/operationalinsights/2025-02-01/tables/model_column.go b/resource-manager/operationalinsights/2025-02-01/tables/model_column.go new file mode 100644 index 00000000000..8ec13720b70 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_column.go @@ -0,0 +1,14 @@ +package tables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Column struct { + DataTypeHint *ColumnDataTypeHintEnum `json:"dataTypeHint,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + IsDefaultDisplay *bool `json:"isDefaultDisplay,omitempty"` + IsHidden *bool `json:"isHidden,omitempty"` + Name *string `json:"name,omitempty"` + Type *ColumnTypeEnum `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_restoredlogs.go b/resource-manager/operationalinsights/2025-02-01/tables/model_restoredlogs.go new file mode 100644 index 00000000000..3d3bfc3f698 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_restoredlogs.go @@ -0,0 +1,41 @@ +package tables + +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 RestoredLogs struct { + AzureAsyncOperationId *string `json:"azureAsyncOperationId,omitempty"` + EndRestoreTime *string `json:"endRestoreTime,omitempty"` + SourceTable *string `json:"sourceTable,omitempty"` + StartRestoreTime *string `json:"startRestoreTime,omitempty"` +} + +func (o *RestoredLogs) GetEndRestoreTimeAsTime() (*time.Time, error) { + if o.EndRestoreTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndRestoreTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoredLogs) SetEndRestoreTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndRestoreTime = &formatted +} + +func (o *RestoredLogs) GetStartRestoreTimeAsTime() (*time.Time, error) { + if o.StartRestoreTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartRestoreTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestoredLogs) SetStartRestoreTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartRestoreTime = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_resultstatistics.go b/resource-manager/operationalinsights/2025-02-01/tables/model_resultstatistics.go new file mode 100644 index 00000000000..81582f6b191 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_resultstatistics.go @@ -0,0 +1,10 @@ +package tables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResultStatistics struct { + IngestedRecords *int64 `json:"ingestedRecords,omitempty"` + Progress *float64 `json:"progress,omitempty"` + ScannedGb *float64 `json:"scannedGb,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_schema.go b/resource-manager/operationalinsights/2025-02-01/tables/model_schema.go new file mode 100644 index 00000000000..13eb3820bd9 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_schema.go @@ -0,0 +1,18 @@ +package tables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Schema struct { + Categories *[]string `json:"categories,omitempty"` + Columns *[]Column `json:"columns,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Name *string `json:"name,omitempty"` + Solutions *[]string `json:"solutions,omitempty"` + Source *SourceEnum `json:"source,omitempty"` + StandardColumns *[]Column `json:"standardColumns,omitempty"` + TableSubType *TableSubTypeEnum `json:"tableSubType,omitempty"` + TableType *TableTypeEnum `json:"tableType,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_searchresults.go b/resource-manager/operationalinsights/2025-02-01/tables/model_searchresults.go new file mode 100644 index 00000000000..8c11e8df14a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_searchresults.go @@ -0,0 +1,44 @@ +package tables + +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 SearchResults struct { + AzureAsyncOperationId *string `json:"azureAsyncOperationId,omitempty"` + Description *string `json:"description,omitempty"` + EndSearchTime *string `json:"endSearchTime,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Query *string `json:"query,omitempty"` + SourceTable *string `json:"sourceTable,omitempty"` + StartSearchTime *string `json:"startSearchTime,omitempty"` +} + +func (o *SearchResults) GetEndSearchTimeAsTime() (*time.Time, error) { + if o.EndSearchTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndSearchTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SearchResults) SetEndSearchTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndSearchTime = &formatted +} + +func (o *SearchResults) GetStartSearchTimeAsTime() (*time.Time, error) { + if o.StartSearchTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartSearchTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SearchResults) SetStartSearchTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartSearchTime = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_table.go b/resource-manager/operationalinsights/2025-02-01/tables/model_table.go new file mode 100644 index 00000000000..b74a23702c4 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_table.go @@ -0,0 +1,16 @@ +package tables + +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 Table struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TableProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_tableproperties.go b/resource-manager/operationalinsights/2025-02-01/tables/model_tableproperties.go new file mode 100644 index 00000000000..0b0714b4dac --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_tableproperties.go @@ -0,0 +1,19 @@ +package tables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TableProperties struct { + ArchiveRetentionInDays *int64 `json:"archiveRetentionInDays,omitempty"` + LastPlanModifiedDate *string `json:"lastPlanModifiedDate,omitempty"` + Plan *TablePlanEnum `json:"plan,omitempty"` + ProvisioningState *ProvisioningStateEnum `json:"provisioningState,omitempty"` + RestoredLogs *RestoredLogs `json:"restoredLogs,omitempty"` + ResultStatistics *ResultStatistics `json:"resultStatistics,omitempty"` + RetentionInDays *int64 `json:"retentionInDays,omitempty"` + RetentionInDaysAsDefault *bool `json:"retentionInDaysAsDefault,omitempty"` + Schema *Schema `json:"schema,omitempty"` + SearchResults *SearchResults `json:"searchResults,omitempty"` + TotalRetentionInDays *int64 `json:"totalRetentionInDays,omitempty"` + TotalRetentionInDaysAsDefault *bool `json:"totalRetentionInDaysAsDefault,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/model_tableslistresult.go b/resource-manager/operationalinsights/2025-02-01/tables/model_tableslistresult.go new file mode 100644 index 00000000000..06dec5265ef --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/model_tableslistresult.go @@ -0,0 +1,8 @@ +package tables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TablesListResult struct { + Value *[]Table `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/tables/version.go b/resource-manager/operationalinsights/2025-02-01/tables/version.go new file mode 100644 index 00000000000..f653645c37a --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/tables/version.go @@ -0,0 +1,10 @@ +package tables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/tables/2025-02-01" +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/README.md b/resource-manager/operationalinsights/2025-02-01/workspaces/README.md new file mode 100644 index 00000000000..be057ed09db --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/README.md @@ -0,0 +1,300 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/workspaces` Documentation + +The `workspaces` SDK allows for interaction with Azure Resource Manager `operationalinsights` (API Version `2025-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2025-02-01/workspaces" +``` + + +### Client Initialization + +```go +client := workspaces.NewWorkspacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspacesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +payload := workspaces.Workspace{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.Delete` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +if err := client.DeleteThenPoll(ctx, id, workspaces.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.GatewaysDelete` + +```go +ctx := context.TODO() +id := workspaces.NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "gatewayId") + +read, err := client.GatewaysDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.Get` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +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: `WorkspacesClient.IntelligencePacksDisable` + +```go +ctx := context.TODO() +id := workspaces.NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName") + +read, err := client.IntelligencePacksDisable(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.IntelligencePacksEnable` + +```go +ctx := context.TODO() +id := workspaces.NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName") + +read, err := client.IntelligencePacksEnable(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.IntelligencePacksList` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.IntelligencePacksList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +read, err := client.ListByResourceGroup(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.ManagementGroupsList` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.ManagementGroupsList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.SchemaGet` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.SchemaGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.SharedKeysGetSharedKeys` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.SharedKeysGetSharedKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.SharedKeysRegenerate` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.SharedKeysRegenerate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.Update` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +payload := workspaces.WorkspacePatch{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.UsagesList` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +read, err := client.UsagesList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.WorkspacePurgeGetPurgeStatus` + +```go +ctx := context.TODO() +id := workspaces.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "purgeId") + +read, err := client.WorkspacePurgeGetPurgeStatus(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.WorkspacePurgePurge` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + +payload := workspaces.WorkspacePurgeBody{ + // ... +} + + +read, err := client.WorkspacePurgePurge(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/operationalinsights/2025-02-01/workspaces/client.go b/resource-manager/operationalinsights/2025-02-01/workspaces/client.go new file mode 100644 index 00000000000..c6ef3485d22 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/client.go @@ -0,0 +1,26 @@ +package workspaces + +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 WorkspacesClient struct { + Client *resourcemanager.Client +} + +func NewWorkspacesClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspacesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "workspaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspacesClient: %+v", err) + } + + return &WorkspacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/constants.go b/resource-manager/operationalinsights/2025-02-01/workspaces/constants.go new file mode 100644 index 00000000000..4b2dda03a6f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/constants.go @@ -0,0 +1,445 @@ +package workspaces + +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 CapacityReservationLevel int64 + +const ( + CapacityReservationLevelFiveHundred CapacityReservationLevel = 500 + CapacityReservationLevelFiveThousand CapacityReservationLevel = 5000 + CapacityReservationLevelFiveZeroThousand CapacityReservationLevel = 50000 + CapacityReservationLevelFourHundred CapacityReservationLevel = 400 + CapacityReservationLevelOneHundred CapacityReservationLevel = 100 + CapacityReservationLevelOneThousand CapacityReservationLevel = 1000 + CapacityReservationLevelOneZeroThousand CapacityReservationLevel = 10000 + CapacityReservationLevelThreeHundred CapacityReservationLevel = 300 + CapacityReservationLevelTwoFiveThousand CapacityReservationLevel = 25000 + CapacityReservationLevelTwoHundred CapacityReservationLevel = 200 + CapacityReservationLevelTwoThousand CapacityReservationLevel = 2000 +) + +func PossibleValuesForCapacityReservationLevel() []int64 { + return []int64{ + int64(CapacityReservationLevelFiveHundred), + int64(CapacityReservationLevelFiveThousand), + int64(CapacityReservationLevelFiveZeroThousand), + int64(CapacityReservationLevelFourHundred), + int64(CapacityReservationLevelOneHundred), + int64(CapacityReservationLevelOneThousand), + int64(CapacityReservationLevelOneZeroThousand), + int64(CapacityReservationLevelThreeHundred), + int64(CapacityReservationLevelTwoFiveThousand), + int64(CapacityReservationLevelTwoHundred), + int64(CapacityReservationLevelTwoThousand), + } +} + +type DataIngestionStatus string + +const ( + DataIngestionStatusApproachingQuota DataIngestionStatus = "ApproachingQuota" + DataIngestionStatusForceOff DataIngestionStatus = "ForceOff" + DataIngestionStatusForceOn DataIngestionStatus = "ForceOn" + DataIngestionStatusOverQuota DataIngestionStatus = "OverQuota" + DataIngestionStatusRespectQuota DataIngestionStatus = "RespectQuota" + DataIngestionStatusSubscriptionSuspended DataIngestionStatus = "SubscriptionSuspended" +) + +func PossibleValuesForDataIngestionStatus() []string { + return []string{ + string(DataIngestionStatusApproachingQuota), + string(DataIngestionStatusForceOff), + string(DataIngestionStatusForceOn), + string(DataIngestionStatusOverQuota), + string(DataIngestionStatusRespectQuota), + string(DataIngestionStatusSubscriptionSuspended), + } +} + +func (s *DataIngestionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataIngestionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataIngestionStatus(input string) (*DataIngestionStatus, error) { + vals := map[string]DataIngestionStatus{ + "approachingquota": DataIngestionStatusApproachingQuota, + "forceoff": DataIngestionStatusForceOff, + "forceon": DataIngestionStatusForceOn, + "overquota": DataIngestionStatusOverQuota, + "respectquota": DataIngestionStatusRespectQuota, + "subscriptionsuspended": DataIngestionStatusSubscriptionSuspended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataIngestionStatus(input) + return &out, nil +} + +type PublicNetworkAccessType string + +const ( + PublicNetworkAccessTypeDisabled PublicNetworkAccessType = "Disabled" + PublicNetworkAccessTypeEnabled PublicNetworkAccessType = "Enabled" +) + +func PossibleValuesForPublicNetworkAccessType() []string { + return []string{ + string(PublicNetworkAccessTypeDisabled), + string(PublicNetworkAccessTypeEnabled), + } +} + +func (s *PublicNetworkAccessType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccessType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccessType(input string) (*PublicNetworkAccessType, error) { + vals := map[string]PublicNetworkAccessType{ + "disabled": PublicNetworkAccessTypeDisabled, + "enabled": PublicNetworkAccessTypeEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccessType(input) + return &out, nil +} + +type PurgeState string + +const ( + PurgeStateCompleted PurgeState = "completed" + PurgeStatePending PurgeState = "pending" +) + +func PossibleValuesForPurgeState() []string { + return []string{ + string(PurgeStateCompleted), + string(PurgeStatePending), + } +} + +func (s *PurgeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePurgeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePurgeState(input string) (*PurgeState, error) { + vals := map[string]PurgeState{ + "completed": PurgeStateCompleted, + "pending": PurgeStatePending, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PurgeState(input) + return &out, nil +} + +type SearchSortEnum string + +const ( + SearchSortEnumAsc SearchSortEnum = "asc" + SearchSortEnumDesc SearchSortEnum = "desc" +) + +func PossibleValuesForSearchSortEnum() []string { + return []string{ + string(SearchSortEnumAsc), + string(SearchSortEnumDesc), + } +} + +func (s *SearchSortEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSearchSortEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSearchSortEnum(input string) (*SearchSortEnum, error) { + vals := map[string]SearchSortEnum{ + "asc": SearchSortEnumAsc, + "desc": SearchSortEnumDesc, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SearchSortEnum(input) + return &out, nil +} + +type WorkspaceEntityStatus string + +const ( + WorkspaceEntityStatusCanceled WorkspaceEntityStatus = "Canceled" + WorkspaceEntityStatusCreating WorkspaceEntityStatus = "Creating" + WorkspaceEntityStatusDeleting WorkspaceEntityStatus = "Deleting" + WorkspaceEntityStatusFailed WorkspaceEntityStatus = "Failed" + WorkspaceEntityStatusProvisioningAccount WorkspaceEntityStatus = "ProvisioningAccount" + WorkspaceEntityStatusSucceeded WorkspaceEntityStatus = "Succeeded" + WorkspaceEntityStatusUpdating WorkspaceEntityStatus = "Updating" +) + +func PossibleValuesForWorkspaceEntityStatus() []string { + return []string{ + string(WorkspaceEntityStatusCanceled), + string(WorkspaceEntityStatusCreating), + string(WorkspaceEntityStatusDeleting), + string(WorkspaceEntityStatusFailed), + string(WorkspaceEntityStatusProvisioningAccount), + string(WorkspaceEntityStatusSucceeded), + string(WorkspaceEntityStatusUpdating), + } +} + +func (s *WorkspaceEntityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceEntityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceEntityStatus(input string) (*WorkspaceEntityStatus, error) { + vals := map[string]WorkspaceEntityStatus{ + "canceled": WorkspaceEntityStatusCanceled, + "creating": WorkspaceEntityStatusCreating, + "deleting": WorkspaceEntityStatusDeleting, + "failed": WorkspaceEntityStatusFailed, + "provisioningaccount": WorkspaceEntityStatusProvisioningAccount, + "succeeded": WorkspaceEntityStatusSucceeded, + "updating": WorkspaceEntityStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceEntityStatus(input) + return &out, nil +} + +type WorkspaceFailoverState string + +const ( + WorkspaceFailoverStateActivating WorkspaceFailoverState = "Activating" + WorkspaceFailoverStateActive WorkspaceFailoverState = "Active" + WorkspaceFailoverStateDeactivating WorkspaceFailoverState = "Deactivating" + WorkspaceFailoverStateFailed WorkspaceFailoverState = "Failed" + WorkspaceFailoverStateInactive WorkspaceFailoverState = "Inactive" +) + +func PossibleValuesForWorkspaceFailoverState() []string { + return []string{ + string(WorkspaceFailoverStateActivating), + string(WorkspaceFailoverStateActive), + string(WorkspaceFailoverStateDeactivating), + string(WorkspaceFailoverStateFailed), + string(WorkspaceFailoverStateInactive), + } +} + +func (s *WorkspaceFailoverState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceFailoverState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceFailoverState(input string) (*WorkspaceFailoverState, error) { + vals := map[string]WorkspaceFailoverState{ + "activating": WorkspaceFailoverStateActivating, + "active": WorkspaceFailoverStateActive, + "deactivating": WorkspaceFailoverStateDeactivating, + "failed": WorkspaceFailoverStateFailed, + "inactive": WorkspaceFailoverStateInactive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceFailoverState(input) + return &out, nil +} + +type WorkspaceReplicationState string + +const ( + WorkspaceReplicationStateCanceled WorkspaceReplicationState = "Canceled" + WorkspaceReplicationStateDisableRequested WorkspaceReplicationState = "DisableRequested" + WorkspaceReplicationStateDisabling WorkspaceReplicationState = "Disabling" + WorkspaceReplicationStateEnableRequested WorkspaceReplicationState = "EnableRequested" + WorkspaceReplicationStateEnabling WorkspaceReplicationState = "Enabling" + WorkspaceReplicationStateFailed WorkspaceReplicationState = "Failed" + WorkspaceReplicationStateRollbackRequested WorkspaceReplicationState = "RollbackRequested" + WorkspaceReplicationStateRollingBack WorkspaceReplicationState = "RollingBack" + WorkspaceReplicationStateSucceeded WorkspaceReplicationState = "Succeeded" +) + +func PossibleValuesForWorkspaceReplicationState() []string { + return []string{ + string(WorkspaceReplicationStateCanceled), + string(WorkspaceReplicationStateDisableRequested), + string(WorkspaceReplicationStateDisabling), + string(WorkspaceReplicationStateEnableRequested), + string(WorkspaceReplicationStateEnabling), + string(WorkspaceReplicationStateFailed), + string(WorkspaceReplicationStateRollbackRequested), + string(WorkspaceReplicationStateRollingBack), + string(WorkspaceReplicationStateSucceeded), + } +} + +func (s *WorkspaceReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceReplicationState(input string) (*WorkspaceReplicationState, error) { + vals := map[string]WorkspaceReplicationState{ + "canceled": WorkspaceReplicationStateCanceled, + "disablerequested": WorkspaceReplicationStateDisableRequested, + "disabling": WorkspaceReplicationStateDisabling, + "enablerequested": WorkspaceReplicationStateEnableRequested, + "enabling": WorkspaceReplicationStateEnabling, + "failed": WorkspaceReplicationStateFailed, + "rollbackrequested": WorkspaceReplicationStateRollbackRequested, + "rollingback": WorkspaceReplicationStateRollingBack, + "succeeded": WorkspaceReplicationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceReplicationState(input) + return &out, nil +} + +type WorkspaceSkuNameEnum string + +const ( + WorkspaceSkuNameEnumCapacityReservation WorkspaceSkuNameEnum = "CapacityReservation" + WorkspaceSkuNameEnumFree WorkspaceSkuNameEnum = "Free" + WorkspaceSkuNameEnumLACluster WorkspaceSkuNameEnum = "LACluster" + WorkspaceSkuNameEnumPerGBTwoZeroOneEight WorkspaceSkuNameEnum = "PerGB2018" + WorkspaceSkuNameEnumPerNode WorkspaceSkuNameEnum = "PerNode" + WorkspaceSkuNameEnumPremium WorkspaceSkuNameEnum = "Premium" + WorkspaceSkuNameEnumStandalone WorkspaceSkuNameEnum = "Standalone" + WorkspaceSkuNameEnumStandard WorkspaceSkuNameEnum = "Standard" +) + +func PossibleValuesForWorkspaceSkuNameEnum() []string { + return []string{ + string(WorkspaceSkuNameEnumCapacityReservation), + string(WorkspaceSkuNameEnumFree), + string(WorkspaceSkuNameEnumLACluster), + string(WorkspaceSkuNameEnumPerGBTwoZeroOneEight), + string(WorkspaceSkuNameEnumPerNode), + string(WorkspaceSkuNameEnumPremium), + string(WorkspaceSkuNameEnumStandalone), + string(WorkspaceSkuNameEnumStandard), + } +} + +func (s *WorkspaceSkuNameEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspaceSkuNameEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspaceSkuNameEnum(input string) (*WorkspaceSkuNameEnum, error) { + vals := map[string]WorkspaceSkuNameEnum{ + "capacityreservation": WorkspaceSkuNameEnumCapacityReservation, + "free": WorkspaceSkuNameEnumFree, + "lacluster": WorkspaceSkuNameEnumLACluster, + "pergb2018": WorkspaceSkuNameEnumPerGBTwoZeroOneEight, + "pernode": WorkspaceSkuNameEnumPerNode, + "premium": WorkspaceSkuNameEnumPremium, + "standalone": WorkspaceSkuNameEnumStandalone, + "standard": WorkspaceSkuNameEnumStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspaceSkuNameEnum(input) + return &out, nil +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway.go new file mode 100644 index 00000000000..ca187d0ee65 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway.go @@ -0,0 +1,139 @@ +package workspaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&GatewayId{}) +} + +var _ resourceids.ResourceId = &GatewayId{} + +// GatewayId is a struct representing the Resource ID for a Gateway +type GatewayId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + GatewayId string +} + +// NewGatewayID returns a new GatewayId struct +func NewGatewayID(subscriptionId string, resourceGroupName string, workspaceName string, gatewayId string) GatewayId { + return GatewayId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + GatewayId: gatewayId, + } +} + +// ParseGatewayID parses 'input' into a GatewayId +func ParseGatewayID(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGatewayIDInsensitively parses 'input' case-insensitively into a GatewayId +// note: this method should only be used for API response data and not user input +func ParseGatewayIDInsensitively(input string) (*GatewayId, error) { + parser := resourceids.NewParserFromResourceIdType(&GatewayId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GatewayId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GatewayId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.GatewayId, ok = input.Parsed["gatewayId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gatewayId", input) + } + + return nil +} + +// ValidateGatewayID checks that 'input' can be parsed as a Gateway ID +func ValidateGatewayID(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 := ParseGatewayID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gateway ID +func (id GatewayId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/gateways/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.GatewayId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gateway ID +func (id GatewayId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticGateways", "gateways", "gateways"), + resourceids.UserSpecifiedSegment("gatewayId", "gatewayId"), + } +} + +// String returns a human-readable description of this Gateway ID +func (id GatewayId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Gateway: %q", id.GatewayId), + } + return fmt.Sprintf("Gateway (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway_test.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway_test.go new file mode 100644 index 00000000000..f74a41b0227 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_gateway_test.go @@ -0,0 +1,327 @@ +package workspaces + +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 = &GatewayId{} + +func TestNewGatewayID(t *testing.T) { + id := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "gatewayId") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.GatewayId != "gatewayId" { + t.Fatalf("Expected %q but got %q for Segment 'GatewayId'", id.GatewayId, "gatewayId") + } +} + +func TestFormatGatewayID(t *testing.T) { + actual := NewGatewayID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "gatewayId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways/gatewayId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGatewayID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways/gatewayId", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + GatewayId: "gatewayId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways/gatewayId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestParseGatewayIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GatewayId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/gAtEwAyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways/gatewayId", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + GatewayId: "gatewayId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/gateways/gatewayId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/gAtEwAyS/gAtEwAyId", + Expected: &GatewayId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + GatewayId: "gAtEwAyId", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/gAtEwAyS/gAtEwAyId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGatewayIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.GatewayId != v.Expected.GatewayId { + t.Fatalf("Expected %q but got %q for GatewayId", v.Expected.GatewayId, actual.GatewayId) + } + + } +} + +func TestSegmentsForGatewayId(t *testing.T) { + segments := GatewayId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GatewayId 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/operationalinsights/2025-02-01/workspaces/id_intelligencepack.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack.go new file mode 100644 index 00000000000..5a01f4d44e0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack.go @@ -0,0 +1,139 @@ +package workspaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&IntelligencePackId{}) +} + +var _ resourceids.ResourceId = &IntelligencePackId{} + +// IntelligencePackId is a struct representing the Resource ID for a Intelligence Pack +type IntelligencePackId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IntelligencePackName string +} + +// NewIntelligencePackID returns a new IntelligencePackId struct +func NewIntelligencePackID(subscriptionId string, resourceGroupName string, workspaceName string, intelligencePackName string) IntelligencePackId { + return IntelligencePackId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IntelligencePackName: intelligencePackName, + } +} + +// ParseIntelligencePackID parses 'input' into a IntelligencePackId +func ParseIntelligencePackID(input string) (*IntelligencePackId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntelligencePackId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntelligencePackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIntelligencePackIDInsensitively parses 'input' case-insensitively into a IntelligencePackId +// note: this method should only be used for API response data and not user input +func ParseIntelligencePackIDInsensitively(input string) (*IntelligencePackId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntelligencePackId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntelligencePackId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IntelligencePackId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IntelligencePackName, ok = input.Parsed["intelligencePackName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "intelligencePackName", input) + } + + return nil +} + +// ValidateIntelligencePackID checks that 'input' can be parsed as a Intelligence Pack ID +func ValidateIntelligencePackID(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 := ParseIntelligencePackID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Intelligence Pack ID +func (id IntelligencePackId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/intelligencePacks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IntelligencePackName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Intelligence Pack ID +func (id IntelligencePackId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticIntelligencePacks", "intelligencePacks", "intelligencePacks"), + resourceids.UserSpecifiedSegment("intelligencePackName", "intelligencePackName"), + } +} + +// String returns a human-readable description of this Intelligence Pack ID +func (id IntelligencePackId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Intelligence Pack Name: %q", id.IntelligencePackName), + } + return fmt.Sprintf("Intelligence Pack (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack_test.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack_test.go new file mode 100644 index 00000000000..12c700c9652 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_intelligencepack_test.go @@ -0,0 +1,327 @@ +package workspaces + +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 = &IntelligencePackId{} + +func TestNewIntelligencePackID(t *testing.T) { + id := NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.IntelligencePackName != "intelligencePackName" { + t.Fatalf("Expected %q but got %q for Segment 'IntelligencePackName'", id.IntelligencePackName, "intelligencePackName") + } +} + +func TestFormatIntelligencePackID(t *testing.T) { + actual := NewIntelligencePackID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "intelligencePackName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIntelligencePackID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntelligencePackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName", + Expected: &IntelligencePackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + IntelligencePackName: "intelligencePackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntelligencePackID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntelligencePackName != v.Expected.IntelligencePackName { + t.Fatalf("Expected %q but got %q for IntelligencePackName", v.Expected.IntelligencePackName, actual.IntelligencePackName) + } + + } +} + +func TestParseIntelligencePackIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntelligencePackId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/iNtElLiGeNcEpAcKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName", + Expected: &IntelligencePackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + IntelligencePackName: "intelligencePackName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/intelligencePacks/intelligencePackName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/iNtElLiGeNcEpAcKs/iNtElLiGeNcEpAcKnAmE", + Expected: &IntelligencePackId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + IntelligencePackName: "iNtElLiGeNcEpAcKnAmE", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/iNtElLiGeNcEpAcKs/iNtElLiGeNcEpAcKnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntelligencePackIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntelligencePackName != v.Expected.IntelligencePackName { + t.Fatalf("Expected %q but got %q for IntelligencePackName", v.Expected.IntelligencePackName, actual.IntelligencePackName) + } + + } +} + +func TestSegmentsForIntelligencePackId(t *testing.T) { + segments := IntelligencePackId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IntelligencePackId 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/operationalinsights/2025-02-01/workspaces/id_operation.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_operation.go new file mode 100644 index 00000000000..4a9ea94f6bb --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_operation.go @@ -0,0 +1,139 @@ +package workspaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PurgeId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(subscriptionId string, resourceGroupName string, workspaceName string, purgeId string) OperationId { + return OperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PurgeId: purgeId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.PurgeId, ok = input.Parsed["purgeId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "purgeId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(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 := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PurgeId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("purgeId", "purgeId"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Purge: %q", id.PurgeId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/id_operation_test.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_operation_test.go new file mode 100644 index 00000000000..17ff4a0877f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_operation_test.go @@ -0,0 +1,327 @@ +package workspaces + +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 = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "purgeId") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } + + if id.PurgeId != "purgeId" { + t.Fatalf("Expected %q but got %q for Segment 'PurgeId'", id.PurgeId, "purgeId") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName", "purgeId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations/purgeId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations/purgeId", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + PurgeId: "purgeId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations/purgeId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PurgeId != v.Expected.PurgeId { + t.Fatalf("Expected %q but got %q for PurgeId", v.Expected.PurgeId, actual.PurgeId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations/purgeId", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + PurgeId: "purgeId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/operations/purgeId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/oPeRaTiOnS/pUrGeId", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + PurgeId: "pUrGeId", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/oPeRaTiOnS/pUrGeId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PurgeId != v.Expected.PurgeId { + t.Fatalf("Expected %q but got %q for PurgeId", v.Expected.PurgeId, actual.PurgeId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId 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/operationalinsights/2025-02-01/workspaces/id_workspace.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace.go new file mode 100644 index 00000000000..9d25173b399 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace.go @@ -0,0 +1,130 @@ +package workspaces + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) 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.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) 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("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceName"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace_test.go b/resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace_test.go new file mode 100644 index 00000000000..8f91e159769 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspaces + +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 = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName") + + 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.WorkspaceName != "workspaceName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceName") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // 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.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeNaMe", + }, + }, + { + // 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.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(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.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId 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/operationalinsights/2025-02-01/workspaces/method_createorupdate.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_createorupdate.go new file mode 100644 index 00000000000..903c8a02530 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_createorupdate.go @@ -0,0 +1,76 @@ +package workspaces + +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 *Workspace +} + +// CreateOrUpdate ... +func (c WorkspacesClient) CreateOrUpdate(ctx context.Context, id WorkspaceId, input Workspace) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 WorkspacesClient) CreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input Workspace) 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/operationalinsights/2025-02-01/workspaces/method_delete.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_delete.go new file mode 100644 index 00000000000..1189ee0127e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_delete.go @@ -0,0 +1,100 @@ +package workspaces + +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 +} + +type DeleteOperationOptions struct { + Force *bool +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Force != nil { + out.Append("force", fmt.Sprintf("%v", *o.Force)) + } + return &out +} + +// Delete ... +func (c WorkspacesClient) Delete(ctx context.Context, id WorkspaceId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + 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 WorkspacesClient) DeleteThenPoll(ctx context.Context, id WorkspaceId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + 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/operationalinsights/2025-02-01/workspaces/method_gatewaysdelete.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_gatewaysdelete.go new file mode 100644 index 00000000000..2566a120d43 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_gatewaysdelete.go @@ -0,0 +1,46 @@ +package workspaces + +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 GatewaysDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GatewaysDelete ... +func (c WorkspacesClient) GatewaysDelete(ctx context.Context, id GatewayId) (result GatewaysDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_get.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_get.go new file mode 100644 index 00000000000..532c4ea30f7 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_get.go @@ -0,0 +1,53 @@ +package workspaces + +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 *Workspace +} + +// Get ... +func (c WorkspacesClient) Get(ctx context.Context, id WorkspaceId) (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 Workspace + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksdisable.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksdisable.go new file mode 100644 index 00000000000..ebf2ccdc377 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksdisable.go @@ -0,0 +1,47 @@ +package workspaces + +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 IntelligencePacksDisableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IntelligencePacksDisable ... +func (c WorkspacesClient) IntelligencePacksDisable(ctx context.Context, id IntelligencePackId) (result IntelligencePacksDisableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksenable.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksenable.go new file mode 100644 index 00000000000..b28e1309455 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepacksenable.go @@ -0,0 +1,47 @@ +package workspaces + +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 IntelligencePacksEnableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IntelligencePacksEnable ... +func (c WorkspacesClient) IntelligencePacksEnable(ctx context.Context, id IntelligencePackId) (result IntelligencePacksEnableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/enable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepackslist.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepackslist.go new file mode 100644 index 00000000000..1e92df537ca --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_intelligencepackslist.go @@ -0,0 +1,54 @@ +package workspaces + +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 IntelligencePacksListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IntelligencePack +} + +// IntelligencePacksList ... +func (c WorkspacesClient) IntelligencePacksList(ctx context.Context, id WorkspaceId) (result IntelligencePacksListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/intelligencePacks", 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 []IntelligencePack + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_list.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_list.go new file mode 100644 index 00000000000..7981337e0f0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_list.go @@ -0,0 +1,55 @@ +package workspaces + +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 *WorkspaceListResult +} + +// List ... +func (c WorkspacesClient) List(ctx context.Context, id commonids.SubscriptionId) (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.OperationalInsights/workspaces", 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 WorkspaceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_listbyresourcegroup.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_listbyresourcegroup.go new file mode 100644 index 00000000000..80e71d20aa0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_listbyresourcegroup.go @@ -0,0 +1,55 @@ +package workspaces + +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 *WorkspaceListResult +} + +// ListByResourceGroup ... +func (c WorkspacesClient) 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.OperationalInsights/workspaces", 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 WorkspaceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_managementgroupslist.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_managementgroupslist.go new file mode 100644 index 00000000000..596c5d1dab1 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_managementgroupslist.go @@ -0,0 +1,54 @@ +package workspaces + +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 ManagementGroupsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceListManagementGroupsResult +} + +// ManagementGroupsList ... +func (c WorkspacesClient) ManagementGroupsList(ctx context.Context, id WorkspaceId) (result ManagementGroupsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/managementGroups", 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 WorkspaceListManagementGroupsResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_schemaget.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_schemaget.go new file mode 100644 index 00000000000..eb7127f39af --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_schemaget.go @@ -0,0 +1,54 @@ +package workspaces + +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 SchemaGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SearchGetSchemaResponse +} + +// SchemaGet ... +func (c WorkspacesClient) SchemaGet(ctx context.Context, id WorkspaceId) (result SchemaGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/schema", 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 SearchGetSchemaResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysgetsharedkeys.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysgetsharedkeys.go new file mode 100644 index 00000000000..91f8d2b6d41 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysgetsharedkeys.go @@ -0,0 +1,54 @@ +package workspaces + +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 SharedKeysGetSharedKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SharedKeys +} + +// SharedKeysGetSharedKeys ... +func (c WorkspacesClient) SharedKeysGetSharedKeys(ctx context.Context, id WorkspaceId) (result SharedKeysGetSharedKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sharedKeys", 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 SharedKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysregenerate.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysregenerate.go new file mode 100644 index 00000000000..df4473f5007 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_sharedkeysregenerate.go @@ -0,0 +1,54 @@ +package workspaces + +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 SharedKeysRegenerateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SharedKeys +} + +// SharedKeysRegenerate ... +func (c WorkspacesClient) SharedKeysRegenerate(ctx context.Context, id WorkspaceId) (result SharedKeysRegenerateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateSharedKey", 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 SharedKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_update.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_update.go new file mode 100644 index 00000000000..cd8c04ff9c2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_update.go @@ -0,0 +1,57 @@ +package workspaces + +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 *Workspace +} + +// Update ... +func (c WorkspacesClient) Update(ctx context.Context, id WorkspaceId, input WorkspacePatch) (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 Workspace + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_usageslist.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_usageslist.go new file mode 100644 index 00000000000..16742cf7284 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_usageslist.go @@ -0,0 +1,54 @@ +package workspaces + +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 UsagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceListUsagesResult +} + +// UsagesList ... +func (c WorkspacesClient) UsagesList(ctx context.Context, id WorkspaceId) (result UsagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/usages", 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 WorkspaceListUsagesResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgegetpurgestatus.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgegetpurgestatus.go new file mode 100644 index 00000000000..223c603de91 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgegetpurgestatus.go @@ -0,0 +1,53 @@ +package workspaces + +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 WorkspacePurgeGetPurgeStatusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspacePurgeStatusResponse +} + +// WorkspacePurgeGetPurgeStatus ... +func (c WorkspacesClient) WorkspacePurgeGetPurgeStatus(ctx context.Context, id OperationId) (result WorkspacePurgeGetPurgeStatusOperationResponse, 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 WorkspacePurgeStatusResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgepurge.go b/resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgepurge.go new file mode 100644 index 00000000000..2899a83661e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/method_workspacepurgepurge.go @@ -0,0 +1,58 @@ +package workspaces + +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 WorkspacePurgePurgeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspacePurgeResponse +} + +// WorkspacePurgePurge ... +func (c WorkspacesClient) WorkspacePurgePurge(ctx context.Context, id WorkspaceId, input WorkspacePurgeBody) (result WorkspacePurgePurgeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/purge", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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 WorkspacePurgeResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_coresummary.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_coresummary.go new file mode 100644 index 00000000000..df29cb10b50 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_coresummary.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CoreSummary struct { + NumberOfDocuments int64 `json:"numberOfDocuments"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_intelligencepack.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_intelligencepack.go new file mode 100644 index 00000000000..813f158bed6 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_intelligencepack.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntelligencePack struct { + DisplayName *string `json:"displayName,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroup.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroup.go new file mode 100644 index 00000000000..dcb938c5793 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroup.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagementGroup struct { + Properties *ManagementGroupProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroupproperties.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroupproperties.go new file mode 100644 index 00000000000..3d1b0b13e6e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_managementgroupproperties.go @@ -0,0 +1,45 @@ +package workspaces + +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 ManagementGroupProperties struct { + Created *string `json:"created,omitempty"` + DataReceived *string `json:"dataReceived,omitempty"` + Id *string `json:"id,omitempty"` + IsGateway *bool `json:"isGateway,omitempty"` + Name *string `json:"name,omitempty"` + ServerCount *int64 `json:"serverCount,omitempty"` + Sku *string `json:"sku,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ManagementGroupProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagementGroupProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *ManagementGroupProperties) GetDataReceivedAsTime() (*time.Time, error) { + if o.DataReceived == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DataReceived, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagementGroupProperties) SetDataReceivedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DataReceived = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_metricname.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_metricname.go new file mode 100644 index 00000000000..f33cbbc5f5e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_metricname.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_privatelinkscopedresource.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_privatelinkscopedresource.go new file mode 100644 index 00000000000..834d7f3c801 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_privatelinkscopedresource.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkScopedResource struct { + ResourceId *string `json:"resourceId,omitempty"` + ScopeId *string `json:"scopeId,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchgetschemaresponse.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchgetschemaresponse.go new file mode 100644 index 00000000000..5cdb4d9f35d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchgetschemaresponse.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SearchGetSchemaResponse struct { + Metadata *SearchMetadata `json:"metadata,omitempty"` + Value *[]SearchSchemaValue `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadata.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadata.go new file mode 100644 index 00000000000..0929b2438d0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadata.go @@ -0,0 +1,54 @@ +package workspaces + +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 SearchMetadata struct { + AggregatedGroupingFields *string `json:"aggregatedGroupingFields,omitempty"` + AggregatedValueField *string `json:"aggregatedValueField,omitempty"` + CoreSummaries *[]CoreSummary `json:"coreSummaries,omitempty"` + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + LastUpdated *string `json:"lastUpdated,omitempty"` + Max *int64 `json:"max,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestTime *int64 `json:"requestTime,omitempty"` + ResultType *string `json:"resultType,omitempty"` + Schema *SearchMetadataSchema `json:"schema,omitempty"` + Sort *[]SearchSort `json:"sort,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + Sum *int64 `json:"sum,omitempty"` + Top *int64 `json:"top,omitempty"` + Total *int64 `json:"total,omitempty"` +} + +func (o *SearchMetadata) GetLastUpdatedAsTime() (*time.Time, error) { + if o.LastUpdated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SearchMetadata) SetLastUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdated = &formatted +} + +func (o *SearchMetadata) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SearchMetadata) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadataschema.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadataschema.go new file mode 100644 index 00000000000..0e39da0d0e0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchmetadataschema.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SearchMetadataSchema struct { + Name *string `json:"name,omitempty"` + Version *int64 `json:"version,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchschemavalue.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchschemavalue.go new file mode 100644 index 00000000000..86826b00b37 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchschemavalue.go @@ -0,0 +1,14 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SearchSchemaValue struct { + DisplayName *string `json:"displayName,omitempty"` + Facet bool `json:"facet"` + Indexed bool `json:"indexed"` + Name *string `json:"name,omitempty"` + OwnerType *[]string `json:"ownerType,omitempty"` + Stored bool `json:"stored"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchsort.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchsort.go new file mode 100644 index 00000000000..a7740dc9365 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_searchsort.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SearchSort struct { + Name *string `json:"name,omitempty"` + Order *SearchSortEnum `json:"order,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_sharedkeys.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_sharedkeys.go new file mode 100644 index 00000000000..c11550ea99e --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_sharedkeys.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedKeys struct { + PrimarySharedKey *string `json:"primarySharedKey,omitempty"` + SecondarySharedKey *string `json:"secondarySharedKey,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_usagemetric.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_usagemetric.go new file mode 100644 index 00000000000..c2fb1de1937 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_usagemetric.go @@ -0,0 +1,31 @@ +package workspaces + +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 UsageMetric struct { + CurrentValue *float64 `json:"currentValue,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Name *MetricName `json:"name,omitempty"` + NextResetTime *string `json:"nextResetTime,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +func (o *UsageMetric) GetNextResetTimeAsTime() (*time.Time, error) { + if o.NextResetTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NextResetTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *UsageMetric) SetNextResetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NextResetTime = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspace.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspace.go new file mode 100644 index 00000000000..ed7840dfcdc --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspace.go @@ -0,0 +1,21 @@ +package workspaces + +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 Workspace struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemOrUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *WorkspaceProperties `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/operationalinsights/2025-02-01/workspaces/model_workspacecapping.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacecapping.go new file mode 100644 index 00000000000..8a654ab52f0 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacecapping.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceCapping struct { + DailyQuotaGb *float64 `json:"dailyQuotaGb,omitempty"` + DataIngestionStatus *DataIngestionStatus `json:"dataIngestionStatus,omitempty"` + QuotaNextResetTime *string `json:"quotaNextResetTime,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefailoverproperties.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefailoverproperties.go new file mode 100644 index 00000000000..6bb03ed582f --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefailoverproperties.go @@ -0,0 +1,27 @@ +package workspaces + +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 WorkspaceFailoverProperties struct { + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + State *WorkspaceFailoverState `json:"state,omitempty"` +} + +func (o *WorkspaceFailoverProperties) GetLastModifiedDateAsTime() (*time.Time, error) { + if o.LastModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceFailoverProperties) SetLastModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefeatures.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefeatures.go new file mode 100644 index 00000000000..822e7701391 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacefeatures.go @@ -0,0 +1,13 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceFeatures struct { + ClusterResourceId *string `json:"clusterResourceId,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + EnableDataExport *bool `json:"enableDataExport,omitempty"` + EnableLogAccessUsingOnlyResourcePermissions *bool `json:"enableLogAccessUsingOnlyResourcePermissions,omitempty"` + ImmediatePurgeDataOn30Days *bool `json:"immediatePurgeDataOn30Days,omitempty"` + UnifiedSentinelBillingOnly *bool `json:"unifiedSentinelBillingOnly,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistmanagementgroupsresult.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistmanagementgroupsresult.go new file mode 100644 index 00000000000..101e18a9b88 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistmanagementgroupsresult.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceListManagementGroupsResult struct { + Value *[]ManagementGroup `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistresult.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistresult.go new file mode 100644 index 00000000000..f3a9c4aa6d8 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistresult.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceListResult struct { + Value *[]Workspace `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistusagesresult.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistusagesresult.go new file mode 100644 index 00000000000..2a0beb349b1 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacelistusagesresult.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceListUsagesResult struct { + Value *[]UsageMetric `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepatch.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepatch.go new file mode 100644 index 00000000000..c123559631d --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepatch.go @@ -0,0 +1,18 @@ +package workspaces + +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 WorkspacePatch struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemOrUserAssignedMap `json:"identity,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkspaceProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspaceproperties.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspaceproperties.go new file mode 100644 index 00000000000..e2ce75df138 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspaceproperties.go @@ -0,0 +1,52 @@ +package workspaces + +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 WorkspaceProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + CustomerId *string `json:"customerId,omitempty"` + DefaultDataCollectionRuleResourceId *string `json:"defaultDataCollectionRuleResourceId,omitempty"` + Failover *WorkspaceFailoverProperties `json:"failover,omitempty"` + Features *WorkspaceFeatures `json:"features,omitempty"` + ForceCmkForQuery *bool `json:"forceCmkForQuery,omitempty"` + ModifiedDate *string `json:"modifiedDate,omitempty"` + PrivateLinkScopedResources *[]PrivateLinkScopedResource `json:"privateLinkScopedResources,omitempty"` + ProvisioningState *WorkspaceEntityStatus `json:"provisioningState,omitempty"` + PublicNetworkAccessForIngestion *PublicNetworkAccessType `json:"publicNetworkAccessForIngestion,omitempty"` + PublicNetworkAccessForQuery *PublicNetworkAccessType `json:"publicNetworkAccessForQuery,omitempty"` + Replication *WorkspaceReplicationProperties `json:"replication,omitempty"` + RetentionInDays *int64 `json:"retentionInDays,omitempty"` + Sku *WorkspaceSku `json:"sku,omitempty"` + WorkspaceCapping *WorkspaceCapping `json:"workspaceCapping,omitempty"` +} + +func (o *WorkspaceProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *WorkspaceProperties) GetModifiedDateAsTime() (*time.Time, error) { + if o.ModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceProperties) SetModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebody.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebody.go new file mode 100644 index 00000000000..338b9dd175c --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebody.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePurgeBody struct { + Filters []WorkspacePurgeBodyFilters `json:"filters"` + Table string `json:"table"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebodyfilters.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebodyfilters.go new file mode 100644 index 00000000000..a9cded5abc2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgebodyfilters.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePurgeBodyFilters struct { + Column *string `json:"column,omitempty"` + Key *string `json:"key,omitempty"` + Operator *string `json:"operator,omitempty"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgeresponse.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgeresponse.go new file mode 100644 index 00000000000..0187a62e139 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgeresponse.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePurgeResponse struct { + OperationId string `json:"operationId"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgestatusresponse.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgestatusresponse.go new file mode 100644 index 00000000000..b4c34494dc2 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacepurgestatusresponse.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePurgeStatusResponse struct { + Status PurgeState `json:"status"` +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacereplicationproperties.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacereplicationproperties.go new file mode 100644 index 00000000000..c862e413558 --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacereplicationproperties.go @@ -0,0 +1,42 @@ +package workspaces + +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 WorkspaceReplicationProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + LastModifiedDate *string `json:"lastModifiedDate,omitempty"` + Location *string `json:"location,omitempty"` + ProvisioningState *WorkspaceReplicationState `json:"provisioningState,omitempty"` +} + +func (o *WorkspaceReplicationProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceReplicationProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *WorkspaceReplicationProperties) GetLastModifiedDateAsTime() (*time.Time, error) { + if o.LastModifiedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceReplicationProperties) SetLastModifiedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedDate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacesku.go b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacesku.go new file mode 100644 index 00000000000..a367ca3f1fb --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/model_workspacesku.go @@ -0,0 +1,28 @@ +package workspaces + +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 WorkspaceSku struct { + CapacityReservationLevel *CapacityReservationLevel `json:"capacityReservationLevel,omitempty"` + LastSkuUpdate *string `json:"lastSkuUpdate,omitempty"` + Name WorkspaceSkuNameEnum `json:"name"` +} + +func (o *WorkspaceSku) GetLastSkuUpdateAsTime() (*time.Time, error) { + if o.LastSkuUpdate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSkuUpdate, "2006-01-02T15:04:05Z07:00") +} + +func (o *WorkspaceSku) SetLastSkuUpdateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSkuUpdate = &formatted +} diff --git a/resource-manager/operationalinsights/2025-02-01/workspaces/version.go b/resource-manager/operationalinsights/2025-02-01/workspaces/version.go new file mode 100644 index 00000000000..65bc2affaec --- /dev/null +++ b/resource-manager/operationalinsights/2025-02-01/workspaces/version.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/workspaces/2025-02-01" +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/README.md b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/README.md new file mode 100644 index 00000000000..8498447bfd2 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments` Documentation + +The `accesspolicyassignments` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2025-04-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments" +``` + + +### Client Initialization + +```go +client := accesspolicyassignments.NewAccessPolicyAssignmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AccessPolicyAssignmentsClient.AccessPolicyAssignmentCreateUpdate` + +```go +ctx := context.TODO() +id := accesspolicyassignments.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +payload := accesspolicyassignments.AccessPolicyAssignment{ + // ... +} + + +if err := client.AccessPolicyAssignmentCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AccessPolicyAssignmentsClient.AccessPolicyAssignmentDelete` + +```go +ctx := context.TODO() +id := accesspolicyassignments.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +if err := client.AccessPolicyAssignmentDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AccessPolicyAssignmentsClient.AccessPolicyAssignmentGet` + +```go +ctx := context.TODO() +id := accesspolicyassignments.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +read, err := client.AccessPolicyAssignmentGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AccessPolicyAssignmentsClient.AccessPolicyAssignmentList` + +```go +ctx := context.TODO() +id := accesspolicyassignments.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +// alternatively `client.AccessPolicyAssignmentList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyAssignmentListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/client.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/client.go new file mode 100644 index 00000000000..7bfe69b6b81 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/client.go @@ -0,0 +1,26 @@ +package accesspolicyassignments + +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 AccessPolicyAssignmentsClient struct { + Client *resourcemanager.Client +} + +func NewAccessPolicyAssignmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*AccessPolicyAssignmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "accesspolicyassignments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AccessPolicyAssignmentsClient: %+v", err) + } + + return &AccessPolicyAssignmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/constants.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/constants.go new file mode 100644 index 00000000000..fa67f195ba9 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/constants.go @@ -0,0 +1,63 @@ +package accesspolicyassignments + +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 ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + 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{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment.go new file mode 100644 index 00000000000..097227421ab --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment.go @@ -0,0 +1,148 @@ +package accesspolicyassignments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyAssignmentId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +// AccessPolicyAssignmentId is a struct representing the Resource ID for a Access Policy Assignment +type AccessPolicyAssignmentId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string + AccessPolicyAssignmentName string +} + +// NewAccessPolicyAssignmentID returns a new AccessPolicyAssignmentId struct +func NewAccessPolicyAssignmentID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string, accessPolicyAssignmentName string) AccessPolicyAssignmentId { + return AccessPolicyAssignmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + AccessPolicyAssignmentName: accessPolicyAssignmentName, + } +} + +// ParseAccessPolicyAssignmentID parses 'input' into a AccessPolicyAssignmentId +func ParseAccessPolicyAssignmentID(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyAssignmentIDInsensitively parses 'input' case-insensitively into a AccessPolicyAssignmentId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyAssignmentIDInsensitively(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyAssignmentId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.AccessPolicyAssignmentName, ok = input.Parsed["accessPolicyAssignmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyAssignmentName", input) + } + + return nil +} + +// ValidateAccessPolicyAssignmentID checks that 'input' can be parsed as a Access Policy Assignment ID +func ValidateAccessPolicyAssignmentID(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 := ParseAccessPolicyAssignmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy Assignment ID +func (id AccessPolicyAssignmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s/accessPolicyAssignments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName, id.AccessPolicyAssignmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticAccessPolicyAssignments", "accessPolicyAssignments", "accessPolicyAssignments"), + resourceids.UserSpecifiedSegment("accessPolicyAssignmentName", "accessPolicyAssignmentName"), + } +} + +// String returns a human-readable description of this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Access Policy Assignment Name: %q", id.AccessPolicyAssignmentName), + } + return fmt.Sprintf("Access Policy Assignment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment_test.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment_test.go new file mode 100644 index 00000000000..44c2ff8fc64 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_accesspolicyassignment_test.go @@ -0,0 +1,372 @@ +package accesspolicyassignments + +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 = &AccessPolicyAssignmentId{} + +func TestNewAccessPolicyAssignmentID(t *testing.T) { + id := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.AccessPolicyAssignmentName != "accessPolicyAssignmentName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyAssignmentName'", id.AccessPolicyAssignmentName, "accessPolicyAssignmentName") + } +} + +func TestFormatAccessPolicyAssignmentID(t *testing.T) { + actual := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyAssignmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestParseAccessPolicyAssignmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + AccessPolicyAssignmentName: "aCcEsSpOlIcYaSsIgNmEnTnAmE", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestSegmentsForAccessPolicyAssignmentId(t *testing.T) { + segments := AccessPolicyAssignmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyAssignmentId 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/redisenterprise/2025-04-01/accesspolicyassignments/id_database.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database.go new file mode 100644 index 00000000000..d76b33a6779 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database.go @@ -0,0 +1,139 @@ +package accesspolicyassignments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseId{}) +} + +var _ resourceids.ResourceId = &DatabaseId{} + +// DatabaseId is a struct representing the Resource ID for a Database +type DatabaseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string +} + +// NewDatabaseID returns a new DatabaseId struct +func NewDatabaseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string) DatabaseId { + return DatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + } +} + +// ParseDatabaseID parses 'input' into a DatabaseId +func ParseDatabaseID(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseIDInsensitively parses 'input' case-insensitively into a DatabaseId +// note: this method should only be used for API response data and not user input +func ParseDatabaseIDInsensitively(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + return nil +} + +// ValidateDatabaseID checks that 'input' can be parsed as a Database ID +func ValidateDatabaseID(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 := ParseDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database ID +func (id DatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database ID +func (id DatabaseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + } +} + +// String returns a human-readable description of this Database ID +func (id DatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + } + return fmt.Sprintf("Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database_test.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database_test.go new file mode 100644 index 00000000000..850b9e7c2bd --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/id_database_test.go @@ -0,0 +1,327 @@ +package accesspolicyassignments + +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 = &DatabaseId{} + +func TestNewDatabaseID(t *testing.T) { + id := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } +} + +func TestFormatDatabaseID(t *testing.T) { + actual := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestParseDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestSegmentsForDatabaseId(t *testing.T) { + segments := DatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseId 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/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentcreateupdate.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentcreateupdate.go new file mode 100644 index 00000000000..f0e29140a9b --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentcreateupdate.go @@ -0,0 +1,75 @@ +package accesspolicyassignments + +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 AccessPolicyAssignmentCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessPolicyAssignment +} + +// AccessPolicyAssignmentCreateUpdate ... +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentCreateUpdate(ctx context.Context, id AccessPolicyAssignmentId, input AccessPolicyAssignment) (result AccessPolicyAssignmentCreateUpdateOperationResponse, 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 +} + +// AccessPolicyAssignmentCreateUpdateThenPoll performs AccessPolicyAssignmentCreateUpdate then polls until it's completed +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentCreateUpdateThenPoll(ctx context.Context, id AccessPolicyAssignmentId, input AccessPolicyAssignment) error { + result, err := c.AccessPolicyAssignmentCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentdelete.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentdelete.go new file mode 100644 index 00000000000..6115d04c9e1 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentdelete.go @@ -0,0 +1,70 @@ +package accesspolicyassignments + +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 AccessPolicyAssignmentDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyAssignmentDelete ... +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentDelete(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentDeleteOperationResponse, 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 +} + +// AccessPolicyAssignmentDeleteThenPoll performs AccessPolicyAssignmentDelete then polls until it's completed +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentDeleteThenPoll(ctx context.Context, id AccessPolicyAssignmentId) error { + result, err := c.AccessPolicyAssignmentDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentget.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentget.go new file mode 100644 index 00000000000..92920238286 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentget.go @@ -0,0 +1,53 @@ +package accesspolicyassignments + +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 AccessPolicyAssignmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessPolicyAssignment +} + +// AccessPolicyAssignmentGet ... +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentGet(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentGetOperationResponse, 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 AccessPolicyAssignment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentlist.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentlist.go new file mode 100644 index 00000000000..638d5a7be88 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/method_accesspolicyassignmentlist.go @@ -0,0 +1,105 @@ +package accesspolicyassignments + +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 AccessPolicyAssignmentListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AccessPolicyAssignment +} + +type AccessPolicyAssignmentListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AccessPolicyAssignment +} + +type AccessPolicyAssignmentListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyAssignmentListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyAssignmentList ... +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentList(ctx context.Context, id DatabaseId) (result AccessPolicyAssignmentListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyAssignmentListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicyAssignments", 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 *[]AccessPolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyAssignmentListComplete retrieves all the results into a single object +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentListComplete(ctx context.Context, id DatabaseId) (AccessPolicyAssignmentListCompleteResult, error) { + return c.AccessPolicyAssignmentListCompleteMatchingPredicate(ctx, id, AccessPolicyAssignmentOperationPredicate{}) +} + +// AccessPolicyAssignmentListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AccessPolicyAssignmentsClient) AccessPolicyAssignmentListCompleteMatchingPredicate(ctx context.Context, id DatabaseId, predicate AccessPolicyAssignmentOperationPredicate) (result AccessPolicyAssignmentListCompleteResult, err error) { + items := make([]AccessPolicyAssignment, 0) + + resp, err := c.AccessPolicyAssignmentList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyAssignmentListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignment.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignment.go new file mode 100644 index 00000000000..6caa7fbc508 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignment.go @@ -0,0 +1,11 @@ +package accesspolicyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AccessPolicyAssignmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentproperties.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentproperties.go new file mode 100644 index 00000000000..4644bd967f5 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentproperties.go @@ -0,0 +1,10 @@ +package accesspolicyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentProperties struct { + AccessPolicyName string `json:"accessPolicyName"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + User AccessPolicyAssignmentPropertiesUser `json:"user"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentpropertiesuser.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentpropertiesuser.go new file mode 100644 index 00000000000..59a7e360d4d --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/model_accesspolicyassignmentpropertiesuser.go @@ -0,0 +1,8 @@ +package accesspolicyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentPropertiesUser struct { + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/predicates.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/predicates.go new file mode 100644 index 00000000000..5026f224768 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/predicates.go @@ -0,0 +1,27 @@ +package accesspolicyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AccessPolicyAssignmentOperationPredicate) Matches(input AccessPolicyAssignment) 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/redisenterprise/2025-04-01/accesspolicyassignments/version.go b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/version.go new file mode 100644 index 00000000000..c94dd795454 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments/version.go @@ -0,0 +1,10 @@ +package accesspolicyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-04-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/accesspolicyassignments/2025-04-01" +} diff --git a/resource-manager/redisenterprise/2025-04-01/client.go b/resource-manager/redisenterprise/2025-04-01/client.go new file mode 100644 index 00000000000..9b09e9172e4 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/client.go @@ -0,0 +1,64 @@ +package v2025_04_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/accesspolicyassignments" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/databases" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/redisenterprise" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AccessPolicyAssignments *accesspolicyassignments.AccessPolicyAssignmentsClient + Databases *databases.DatabasesClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + RedisEnterprise *redisenterprise.RedisEnterpriseClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + accessPolicyAssignmentsClient, err := accesspolicyassignments.NewAccessPolicyAssignmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AccessPolicyAssignments client: %+v", err) + } + configureFunc(accessPolicyAssignmentsClient.Client) + + databasesClient, err := databases.NewDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Databases client: %+v", err) + } + configureFunc(databasesClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + redisEnterpriseClient, err := redisenterprise.NewRedisEnterpriseClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RedisEnterprise client: %+v", err) + } + configureFunc(redisEnterpriseClient.Client) + + return &Client{ + AccessPolicyAssignments: accessPolicyAssignmentsClient, + Databases: databasesClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + RedisEnterprise: redisEnterpriseClient, + }, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/README.md b/resource-manager/redisenterprise/2025-04-01/databases/README.md new file mode 100644 index 00000000000..97abfd1a333 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/README.md @@ -0,0 +1,291 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/databases` Documentation + +The `databases` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2025-04-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/databases" +``` + + +### Client Initialization + +```go +client := databases.NewDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabasesClient.AccessPolicyAssignmentCreateUpdate` + +```go +ctx := context.TODO() +id := databases.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +payload := databases.AccessPolicyAssignment{ + // ... +} + + +if err := client.AccessPolicyAssignmentCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.AccessPolicyAssignmentDelete` + +```go +ctx := context.TODO() +id := databases.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +if err := client.AccessPolicyAssignmentDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.AccessPolicyAssignmentGet` + +```go +ctx := context.TODO() +id := databases.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +read, err := client.AccessPolicyAssignmentGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabasesClient.AccessPolicyAssignmentList` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +// alternatively `client.AccessPolicyAssignmentList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyAssignmentListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DatabasesClient.Create` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.Database{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Delete` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Export` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ExportClusterParameters{ + // ... +} + + +if err := client.ExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Flush` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.FlushParameters{ + // ... +} + + +if err := client.FlushThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ForceLinkToReplicationGroup` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ForceLinkParameters{ + // ... +} + + +if err := client.ForceLinkToReplicationGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ForceUnlink` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ForceUnlinkParameters{ + // ... +} + + +if err := client.ForceUnlinkThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Get` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +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: `DatabasesClient.Import` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ImportClusterParameters{ + // ... +} + + +if err := client.ImportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ListByCluster` + +```go +ctx := context.TODO() +id := databases.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +// 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 +} +``` + + +### Example Usage: `DatabasesClient.ListKeys` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.ListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabasesClient.RegenerateKey` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.RegenerateKeyParameters{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Update` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.DatabaseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.UpgradeDBRedisVersion` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +if err := client.UpgradeDBRedisVersionThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redisenterprise/2025-04-01/databases/client.go b/resource-manager/redisenterprise/2025-04-01/databases/client.go new file mode 100644 index 00000000000..87de2d4fe59 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/client.go @@ -0,0 +1,26 @@ +package databases + +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 DatabasesClient struct { + Client *resourcemanager.Client +} + +func NewDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabasesClient: %+v", err) + } + + return &DatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/constants.go b/resource-manager/redisenterprise/2025-04-01/databases/constants.go new file mode 100644 index 00000000000..b752c0e02dc --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/constants.go @@ -0,0 +1,542 @@ +package databases + +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 AccessKeyType string + +const ( + AccessKeyTypePrimary AccessKeyType = "Primary" + AccessKeyTypeSecondary AccessKeyType = "Secondary" +) + +func PossibleValuesForAccessKeyType() []string { + return []string{ + string(AccessKeyTypePrimary), + string(AccessKeyTypeSecondary), + } +} + +func (s *AccessKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessKeyType(input string) (*AccessKeyType, error) { + vals := map[string]AccessKeyType{ + "primary": AccessKeyTypePrimary, + "secondary": AccessKeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessKeyType(input) + return &out, nil +} + +type AccessKeysAuthentication string + +const ( + AccessKeysAuthenticationDisabled AccessKeysAuthentication = "Disabled" + AccessKeysAuthenticationEnabled AccessKeysAuthentication = "Enabled" +) + +func PossibleValuesForAccessKeysAuthentication() []string { + return []string{ + string(AccessKeysAuthenticationDisabled), + string(AccessKeysAuthenticationEnabled), + } +} + +func (s *AccessKeysAuthentication) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessKeysAuthentication(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessKeysAuthentication(input string) (*AccessKeysAuthentication, error) { + vals := map[string]AccessKeysAuthentication{ + "disabled": AccessKeysAuthenticationDisabled, + "enabled": AccessKeysAuthenticationEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessKeysAuthentication(input) + return &out, nil +} + +type AofFrequency string + +const ( + AofFrequencyAlways AofFrequency = "always" + AofFrequencyOnes AofFrequency = "1s" +) + +func PossibleValuesForAofFrequency() []string { + return []string{ + string(AofFrequencyAlways), + string(AofFrequencyOnes), + } +} + +func (s *AofFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAofFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAofFrequency(input string) (*AofFrequency, error) { + vals := map[string]AofFrequency{ + "always": AofFrequencyAlways, + "1s": AofFrequencyOnes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AofFrequency(input) + return &out, nil +} + +type ClusteringPolicy string + +const ( + ClusteringPolicyEnterpriseCluster ClusteringPolicy = "EnterpriseCluster" + ClusteringPolicyOSSCluster ClusteringPolicy = "OSSCluster" +) + +func PossibleValuesForClusteringPolicy() []string { + return []string{ + string(ClusteringPolicyEnterpriseCluster), + string(ClusteringPolicyOSSCluster), + } +} + +func (s *ClusteringPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusteringPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusteringPolicy(input string) (*ClusteringPolicy, error) { + vals := map[string]ClusteringPolicy{ + "enterprisecluster": ClusteringPolicyEnterpriseCluster, + "osscluster": ClusteringPolicyOSSCluster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusteringPolicy(input) + return &out, nil +} + +type DeferUpgradeSetting string + +const ( + DeferUpgradeSettingDeferred DeferUpgradeSetting = "Deferred" + DeferUpgradeSettingNotDeferred DeferUpgradeSetting = "NotDeferred" +) + +func PossibleValuesForDeferUpgradeSetting() []string { + return []string{ + string(DeferUpgradeSettingDeferred), + string(DeferUpgradeSettingNotDeferred), + } +} + +func (s *DeferUpgradeSetting) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeferUpgradeSetting(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeferUpgradeSetting(input string) (*DeferUpgradeSetting, error) { + vals := map[string]DeferUpgradeSetting{ + "deferred": DeferUpgradeSettingDeferred, + "notdeferred": DeferUpgradeSettingNotDeferred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeferUpgradeSetting(input) + return &out, nil +} + +type EvictionPolicy string + +const ( + EvictionPolicyAllKeysLFU EvictionPolicy = "AllKeysLFU" + EvictionPolicyAllKeysLRU EvictionPolicy = "AllKeysLRU" + EvictionPolicyAllKeysRandom EvictionPolicy = "AllKeysRandom" + EvictionPolicyNoEviction EvictionPolicy = "NoEviction" + EvictionPolicyVolatileLFU EvictionPolicy = "VolatileLFU" + EvictionPolicyVolatileLRU EvictionPolicy = "VolatileLRU" + EvictionPolicyVolatileRandom EvictionPolicy = "VolatileRandom" + EvictionPolicyVolatileTTL EvictionPolicy = "VolatileTTL" +) + +func PossibleValuesForEvictionPolicy() []string { + return []string{ + string(EvictionPolicyAllKeysLFU), + string(EvictionPolicyAllKeysLRU), + string(EvictionPolicyAllKeysRandom), + string(EvictionPolicyNoEviction), + string(EvictionPolicyVolatileLFU), + string(EvictionPolicyVolatileLRU), + string(EvictionPolicyVolatileRandom), + string(EvictionPolicyVolatileTTL), + } +} + +func (s *EvictionPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEvictionPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEvictionPolicy(input string) (*EvictionPolicy, error) { + vals := map[string]EvictionPolicy{ + "allkeyslfu": EvictionPolicyAllKeysLFU, + "allkeyslru": EvictionPolicyAllKeysLRU, + "allkeysrandom": EvictionPolicyAllKeysRandom, + "noeviction": EvictionPolicyNoEviction, + "volatilelfu": EvictionPolicyVolatileLFU, + "volatilelru": EvictionPolicyVolatileLRU, + "volatilerandom": EvictionPolicyVolatileRandom, + "volatilettl": EvictionPolicyVolatileTTL, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EvictionPolicy(input) + return &out, nil +} + +type LinkState string + +const ( + LinkStateLinkFailed LinkState = "LinkFailed" + LinkStateLinked LinkState = "Linked" + LinkStateLinking LinkState = "Linking" + LinkStateUnlinkFailed LinkState = "UnlinkFailed" + LinkStateUnlinking LinkState = "Unlinking" +) + +func PossibleValuesForLinkState() []string { + return []string{ + string(LinkStateLinkFailed), + string(LinkStateLinked), + string(LinkStateLinking), + string(LinkStateUnlinkFailed), + string(LinkStateUnlinking), + } +} + +func (s *LinkState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkState(input string) (*LinkState, error) { + vals := map[string]LinkState{ + "linkfailed": LinkStateLinkFailed, + "linked": LinkStateLinked, + "linking": LinkStateLinking, + "unlinkfailed": LinkStateUnlinkFailed, + "unlinking": LinkStateUnlinking, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkState(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolEncrypted Protocol = "Encrypted" + ProtocolPlaintext Protocol = "Plaintext" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolEncrypted), + string(ProtocolPlaintext), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "encrypted": ProtocolEncrypted, + "plaintext": ProtocolPlaintext, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + 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{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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 RdbFrequency string + +const ( + RdbFrequencyOneTwoh RdbFrequency = "12h" + RdbFrequencyOneh RdbFrequency = "1h" + RdbFrequencySixh RdbFrequency = "6h" +) + +func PossibleValuesForRdbFrequency() []string { + return []string{ + string(RdbFrequencyOneTwoh), + string(RdbFrequencyOneh), + string(RdbFrequencySixh), + } +} + +func (s *RdbFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRdbFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRdbFrequency(input string) (*RdbFrequency, error) { + vals := map[string]RdbFrequency{ + "12h": RdbFrequencyOneTwoh, + "1h": RdbFrequencyOneh, + "6h": RdbFrequencySixh, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RdbFrequency(input) + return &out, nil +} + +type ResourceState string + +const ( + ResourceStateCreateFailed ResourceState = "CreateFailed" + ResourceStateCreating ResourceState = "Creating" + ResourceStateDeleteFailed ResourceState = "DeleteFailed" + ResourceStateDeleting ResourceState = "Deleting" + ResourceStateDisableFailed ResourceState = "DisableFailed" + ResourceStateDisabled ResourceState = "Disabled" + ResourceStateDisabling ResourceState = "Disabling" + ResourceStateEnableFailed ResourceState = "EnableFailed" + ResourceStateEnabling ResourceState = "Enabling" + ResourceStateMoving ResourceState = "Moving" + ResourceStateRunning ResourceState = "Running" + ResourceStateScaling ResourceState = "Scaling" + ResourceStateScalingFailed ResourceState = "ScalingFailed" + ResourceStateUpdateFailed ResourceState = "UpdateFailed" + ResourceStateUpdating ResourceState = "Updating" +) + +func PossibleValuesForResourceState() []string { + return []string{ + string(ResourceStateCreateFailed), + string(ResourceStateCreating), + string(ResourceStateDeleteFailed), + string(ResourceStateDeleting), + string(ResourceStateDisableFailed), + string(ResourceStateDisabled), + string(ResourceStateDisabling), + string(ResourceStateEnableFailed), + string(ResourceStateEnabling), + string(ResourceStateMoving), + string(ResourceStateRunning), + string(ResourceStateScaling), + string(ResourceStateScalingFailed), + string(ResourceStateUpdateFailed), + string(ResourceStateUpdating), + } +} + +func (s *ResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceState(input string) (*ResourceState, error) { + vals := map[string]ResourceState{ + "createfailed": ResourceStateCreateFailed, + "creating": ResourceStateCreating, + "deletefailed": ResourceStateDeleteFailed, + "deleting": ResourceStateDeleting, + "disablefailed": ResourceStateDisableFailed, + "disabled": ResourceStateDisabled, + "disabling": ResourceStateDisabling, + "enablefailed": ResourceStateEnableFailed, + "enabling": ResourceStateEnabling, + "moving": ResourceStateMoving, + "running": ResourceStateRunning, + "scaling": ResourceStateScaling, + "scalingfailed": ResourceStateScalingFailed, + "updatefailed": ResourceStateUpdateFailed, + "updating": ResourceStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceState(input) + return &out, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment.go b/resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment.go new file mode 100644 index 00000000000..af2f6cb8882 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment.go @@ -0,0 +1,148 @@ +package databases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyAssignmentId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +// AccessPolicyAssignmentId is a struct representing the Resource ID for a Access Policy Assignment +type AccessPolicyAssignmentId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string + AccessPolicyAssignmentName string +} + +// NewAccessPolicyAssignmentID returns a new AccessPolicyAssignmentId struct +func NewAccessPolicyAssignmentID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string, accessPolicyAssignmentName string) AccessPolicyAssignmentId { + return AccessPolicyAssignmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + AccessPolicyAssignmentName: accessPolicyAssignmentName, + } +} + +// ParseAccessPolicyAssignmentID parses 'input' into a AccessPolicyAssignmentId +func ParseAccessPolicyAssignmentID(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyAssignmentIDInsensitively parses 'input' case-insensitively into a AccessPolicyAssignmentId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyAssignmentIDInsensitively(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyAssignmentId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.AccessPolicyAssignmentName, ok = input.Parsed["accessPolicyAssignmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyAssignmentName", input) + } + + return nil +} + +// ValidateAccessPolicyAssignmentID checks that 'input' can be parsed as a Access Policy Assignment ID +func ValidateAccessPolicyAssignmentID(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 := ParseAccessPolicyAssignmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy Assignment ID +func (id AccessPolicyAssignmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s/accessPolicyAssignments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName, id.AccessPolicyAssignmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticAccessPolicyAssignments", "accessPolicyAssignments", "accessPolicyAssignments"), + resourceids.UserSpecifiedSegment("accessPolicyAssignmentName", "accessPolicyAssignmentName"), + } +} + +// String returns a human-readable description of this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Access Policy Assignment Name: %q", id.AccessPolicyAssignmentName), + } + return fmt.Sprintf("Access Policy Assignment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment_test.go b/resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment_test.go new file mode 100644 index 00000000000..5764612c5fc --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/id_accesspolicyassignment_test.go @@ -0,0 +1,372 @@ +package databases + +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 = &AccessPolicyAssignmentId{} + +func TestNewAccessPolicyAssignmentID(t *testing.T) { + id := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.AccessPolicyAssignmentName != "accessPolicyAssignmentName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyAssignmentName'", id.AccessPolicyAssignmentName, "accessPolicyAssignmentName") + } +} + +func TestFormatAccessPolicyAssignmentID(t *testing.T) { + actual := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyAssignmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestParseAccessPolicyAssignmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + AccessPolicyAssignmentName: "aCcEsSpOlIcYaSsIgNmEnTnAmE", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestSegmentsForAccessPolicyAssignmentId(t *testing.T) { + segments := AccessPolicyAssignmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyAssignmentId 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/redisenterprise/2025-04-01/databases/id_database.go b/resource-manager/redisenterprise/2025-04-01/databases/id_database.go new file mode 100644 index 00000000000..c2402902641 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/id_database.go @@ -0,0 +1,139 @@ +package databases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseId{}) +} + +var _ resourceids.ResourceId = &DatabaseId{} + +// DatabaseId is a struct representing the Resource ID for a Database +type DatabaseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string +} + +// NewDatabaseID returns a new DatabaseId struct +func NewDatabaseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string) DatabaseId { + return DatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + } +} + +// ParseDatabaseID parses 'input' into a DatabaseId +func ParseDatabaseID(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseIDInsensitively parses 'input' case-insensitively into a DatabaseId +// note: this method should only be used for API response data and not user input +func ParseDatabaseIDInsensitively(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + return nil +} + +// ValidateDatabaseID checks that 'input' can be parsed as a Database ID +func ValidateDatabaseID(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 := ParseDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database ID +func (id DatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database ID +func (id DatabaseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + } +} + +// String returns a human-readable description of this Database ID +func (id DatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + } + return fmt.Sprintf("Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/id_database_test.go b/resource-manager/redisenterprise/2025-04-01/databases/id_database_test.go new file mode 100644 index 00000000000..5dbc49dabaf --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/id_database_test.go @@ -0,0 +1,327 @@ +package databases + +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 = &DatabaseId{} + +func TestNewDatabaseID(t *testing.T) { + id := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } +} + +func TestFormatDatabaseID(t *testing.T) { + actual := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestParseDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestSegmentsForDatabaseId(t *testing.T) { + segments := DatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseId 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/redisenterprise/2025-04-01/databases/id_redisenterprise.go b/resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise.go new file mode 100644 index 00000000000..c872e92eb24 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise.go @@ -0,0 +1,130 @@ +package databases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(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 := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise_test.go b/resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise_test.go new file mode 100644 index 00000000000..06c2b187531 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package databases + +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 = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId 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/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentcreateupdate.go b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentcreateupdate.go new file mode 100644 index 00000000000..b5d2ec870e5 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentcreateupdate.go @@ -0,0 +1,75 @@ +package databases + +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 AccessPolicyAssignmentCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessPolicyAssignment +} + +// AccessPolicyAssignmentCreateUpdate ... +func (c DatabasesClient) AccessPolicyAssignmentCreateUpdate(ctx context.Context, id AccessPolicyAssignmentId, input AccessPolicyAssignment) (result AccessPolicyAssignmentCreateUpdateOperationResponse, 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 +} + +// AccessPolicyAssignmentCreateUpdateThenPoll performs AccessPolicyAssignmentCreateUpdate then polls until it's completed +func (c DatabasesClient) AccessPolicyAssignmentCreateUpdateThenPoll(ctx context.Context, id AccessPolicyAssignmentId, input AccessPolicyAssignment) error { + result, err := c.AccessPolicyAssignmentCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentdelete.go b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentdelete.go new file mode 100644 index 00000000000..0913889e6ad --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentdelete.go @@ -0,0 +1,70 @@ +package databases + +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 AccessPolicyAssignmentDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyAssignmentDelete ... +func (c DatabasesClient) AccessPolicyAssignmentDelete(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentDeleteOperationResponse, 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 +} + +// AccessPolicyAssignmentDeleteThenPoll performs AccessPolicyAssignmentDelete then polls until it's completed +func (c DatabasesClient) AccessPolicyAssignmentDeleteThenPoll(ctx context.Context, id AccessPolicyAssignmentId) error { + result, err := c.AccessPolicyAssignmentDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentget.go b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentget.go new file mode 100644 index 00000000000..fc7610ea931 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentget.go @@ -0,0 +1,53 @@ +package databases + +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 AccessPolicyAssignmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessPolicyAssignment +} + +// AccessPolicyAssignmentGet ... +func (c DatabasesClient) AccessPolicyAssignmentGet(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentGetOperationResponse, 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 AccessPolicyAssignment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentlist.go b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentlist.go new file mode 100644 index 00000000000..240ba0cbedf --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_accesspolicyassignmentlist.go @@ -0,0 +1,105 @@ +package databases + +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 AccessPolicyAssignmentListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AccessPolicyAssignment +} + +type AccessPolicyAssignmentListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AccessPolicyAssignment +} + +type AccessPolicyAssignmentListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyAssignmentListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyAssignmentList ... +func (c DatabasesClient) AccessPolicyAssignmentList(ctx context.Context, id DatabaseId) (result AccessPolicyAssignmentListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyAssignmentListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicyAssignments", 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 *[]AccessPolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyAssignmentListComplete retrieves all the results into a single object +func (c DatabasesClient) AccessPolicyAssignmentListComplete(ctx context.Context, id DatabaseId) (AccessPolicyAssignmentListCompleteResult, error) { + return c.AccessPolicyAssignmentListCompleteMatchingPredicate(ctx, id, AccessPolicyAssignmentOperationPredicate{}) +} + +// AccessPolicyAssignmentListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabasesClient) AccessPolicyAssignmentListCompleteMatchingPredicate(ctx context.Context, id DatabaseId, predicate AccessPolicyAssignmentOperationPredicate) (result AccessPolicyAssignmentListCompleteResult, err error) { + items := make([]AccessPolicyAssignment, 0) + + resp, err := c.AccessPolicyAssignmentList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyAssignmentListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_create.go b/resource-manager/redisenterprise/2025-04-01/databases/method_create.go new file mode 100644 index 00000000000..ef7027e79c5 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_create.go @@ -0,0 +1,75 @@ +package databases + +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 *Database +} + +// Create ... +func (c DatabasesClient) Create(ctx context.Context, id DatabaseId, input Database) (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 DatabasesClient) CreateThenPoll(ctx context.Context, id DatabaseId, input Database) 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/redisenterprise/2025-04-01/databases/method_delete.go b/resource-manager/redisenterprise/2025-04-01/databases/method_delete.go new file mode 100644 index 00000000000..dc03e526611 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_delete.go @@ -0,0 +1,71 @@ +package databases + +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 DatabasesClient) Delete(ctx context.Context, id DatabaseId) (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 DatabasesClient) DeleteThenPoll(ctx context.Context, id DatabaseId) 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/redisenterprise/2025-04-01/databases/method_export.go b/resource-manager/redisenterprise/2025-04-01/databases/method_export.go new file mode 100644 index 00000000000..a35c1aaff53 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_export.go @@ -0,0 +1,74 @@ +package databases + +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 ExportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Export ... +func (c DatabasesClient) Export(ctx context.Context, id DatabaseId, input ExportClusterParameters) (result ExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", 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 +} + +// ExportThenPoll performs Export then polls until it's completed +func (c DatabasesClient) ExportThenPoll(ctx context.Context, id DatabaseId, input ExportClusterParameters) error { + result, err := c.Export(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Export: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Export: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_flush.go b/resource-manager/redisenterprise/2025-04-01/databases/method_flush.go new file mode 100644 index 00000000000..aaf7666fdf0 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_flush.go @@ -0,0 +1,74 @@ +package databases + +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 FlushOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Flush ... +func (c DatabasesClient) Flush(ctx context.Context, id DatabaseId, input FlushParameters) (result FlushOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/flush", 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 +} + +// FlushThenPoll performs Flush then polls until it's completed +func (c DatabasesClient) FlushThenPoll(ctx context.Context, id DatabaseId, input FlushParameters) error { + result, err := c.Flush(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Flush: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Flush: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_forcelinktoreplicationgroup.go b/resource-manager/redisenterprise/2025-04-01/databases/method_forcelinktoreplicationgroup.go new file mode 100644 index 00000000000..020c282d01d --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_forcelinktoreplicationgroup.go @@ -0,0 +1,73 @@ +package databases + +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 ForceLinkToReplicationGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ForceLinkToReplicationGroup ... +func (c DatabasesClient) ForceLinkToReplicationGroup(ctx context.Context, id DatabaseId, input ForceLinkParameters) (result ForceLinkToReplicationGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceLinkToReplicationGroup", 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 +} + +// ForceLinkToReplicationGroupThenPoll performs ForceLinkToReplicationGroup then polls until it's completed +func (c DatabasesClient) ForceLinkToReplicationGroupThenPoll(ctx context.Context, id DatabaseId, input ForceLinkParameters) error { + result, err := c.ForceLinkToReplicationGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ForceLinkToReplicationGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ForceLinkToReplicationGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_forceunlink.go b/resource-manager/redisenterprise/2025-04-01/databases/method_forceunlink.go new file mode 100644 index 00000000000..bc8f9b988c8 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_forceunlink.go @@ -0,0 +1,74 @@ +package databases + +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 ForceUnlinkOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ForceUnlink ... +func (c DatabasesClient) ForceUnlink(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) (result ForceUnlinkOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceUnlink", 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 +} + +// ForceUnlinkThenPoll performs ForceUnlink then polls until it's completed +func (c DatabasesClient) ForceUnlinkThenPoll(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) error { + result, err := c.ForceUnlink(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ForceUnlink: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ForceUnlink: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_get.go b/resource-manager/redisenterprise/2025-04-01/databases/method_get.go new file mode 100644 index 00000000000..df1a873b818 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_get.go @@ -0,0 +1,53 @@ +package databases + +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 *Database +} + +// Get ... +func (c DatabasesClient) Get(ctx context.Context, id DatabaseId) (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 Database + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_import.go b/resource-manager/redisenterprise/2025-04-01/databases/method_import.go new file mode 100644 index 00000000000..39022d59c43 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_import.go @@ -0,0 +1,74 @@ +package databases + +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 ImportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Import ... +func (c DatabasesClient) Import(ctx context.Context, id DatabaseId, input ImportClusterParameters) (result ImportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/import", 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 +} + +// ImportThenPoll performs Import then polls until it's completed +func (c DatabasesClient) ImportThenPoll(ctx context.Context, id DatabaseId, input ImportClusterParameters) error { + result, err := c.Import(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Import: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Import: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_listbycluster.go b/resource-manager/redisenterprise/2025-04-01/databases/method_listbycluster.go new file mode 100644 index 00000000000..c98456fed45 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_listbycluster.go @@ -0,0 +1,105 @@ +package databases + +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 *[]Database +} + +type ListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type ListByClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByCluster ... +func (c DatabasesClient) ListByCluster(ctx context.Context, id RedisEnterpriseId) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByClusterCustomPager{}, + Path: fmt.Sprintf("%s/databases", 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 *[]Database `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 DatabasesClient) ListByClusterComplete(ctx context.Context, id RedisEnterpriseId) (ListByClusterCompleteResult, error) { + return c.ListByClusterCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// ListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabasesClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id RedisEnterpriseId, predicate DatabaseOperationPredicate) (result ListByClusterCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.ListByCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_listkeys.go b/resource-manager/redisenterprise/2025-04-01/databases/method_listkeys.go new file mode 100644 index 00000000000..147674d8dcf --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_listkeys.go @@ -0,0 +1,54 @@ +package databases + +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 ListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// ListKeys ... +func (c DatabasesClient) ListKeys(ctx context.Context, id DatabaseId) (result ListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", 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 AccessKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_regeneratekey.go b/resource-manager/redisenterprise/2025-04-01/databases/method_regeneratekey.go new file mode 100644 index 00000000000..f745c705aba --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_regeneratekey.go @@ -0,0 +1,75 @@ +package databases + +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 RegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// RegenerateKey ... +func (c DatabasesClient) RegenerateKey(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", 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 +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c DatabasesClient) RegenerateKeyThenPoll(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/method_update.go b/resource-manager/redisenterprise/2025-04-01/databases/method_update.go new file mode 100644 index 00000000000..21a9006463c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_update.go @@ -0,0 +1,75 @@ +package databases + +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 *Database +} + +// Update ... +func (c DatabasesClient) Update(ctx context.Context, id DatabaseId, input DatabaseUpdate) (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 DatabasesClient) UpdateThenPoll(ctx context.Context, id DatabaseId, input DatabaseUpdate) 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/redisenterprise/2025-04-01/databases/method_upgradedbredisversion.go b/resource-manager/redisenterprise/2025-04-01/databases/method_upgradedbredisversion.go new file mode 100644 index 00000000000..ad7e756b1dc --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/method_upgradedbredisversion.go @@ -0,0 +1,69 @@ +package databases + +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 UpgradeDBRedisVersionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// UpgradeDBRedisVersion ... +func (c DatabasesClient) UpgradeDBRedisVersion(ctx context.Context, id DatabaseId) (result UpgradeDBRedisVersionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgradeDBRedisVersion", 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 +} + +// UpgradeDBRedisVersionThenPoll performs UpgradeDBRedisVersion then polls until it's completed +func (c DatabasesClient) UpgradeDBRedisVersionThenPoll(ctx context.Context, id DatabaseId) error { + result, err := c.UpgradeDBRedisVersion(ctx, id) + if err != nil { + return fmt.Errorf("performing UpgradeDBRedisVersion: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpgradeDBRedisVersion: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_accesskeys.go b/resource-manager/redisenterprise/2025-04-01/databases/model_accesskeys.go new file mode 100644 index 00000000000..d2c730f7d54 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_accesskeys.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessKeys struct { + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignment.go b/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignment.go new file mode 100644 index 00000000000..fd4718ad413 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignment.go @@ -0,0 +1,11 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AccessPolicyAssignmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentproperties.go b/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentproperties.go new file mode 100644 index 00000000000..3994edd04fb --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentproperties.go @@ -0,0 +1,10 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentProperties struct { + AccessPolicyName string `json:"accessPolicyName"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + User AccessPolicyAssignmentPropertiesUser `json:"user"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentpropertiesuser.go b/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentpropertiesuser.go new file mode 100644 index 00000000000..234cc2ca236 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_accesspolicyassignmentpropertiesuser.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentPropertiesUser struct { + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_database.go b/resource-manager/redisenterprise/2025-04-01/databases/model_database.go new file mode 100644 index 00000000000..a9880a7432b --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_database.go @@ -0,0 +1,11 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Database struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_databaseproperties.go b/resource-manager/redisenterprise/2025-04-01/databases/model_databaseproperties.go new file mode 100644 index 00000000000..070b33feb46 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_databaseproperties.go @@ -0,0 +1,19 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseProperties struct { + AccessKeysAuthentication *AccessKeysAuthentication `json:"accessKeysAuthentication,omitempty"` + ClientProtocol *Protocol `json:"clientProtocol,omitempty"` + ClusteringPolicy *ClusteringPolicy `json:"clusteringPolicy,omitempty"` + DeferUpgrade *DeferUpgradeSetting `json:"deferUpgrade,omitempty"` + EvictionPolicy *EvictionPolicy `json:"evictionPolicy,omitempty"` + GeoReplication *DatabasePropertiesGeoReplication `json:"geoReplication,omitempty"` + Modules *[]Module `json:"modules,omitempty"` + Persistence *Persistence `json:"persistence,omitempty"` + Port *int64 `json:"port,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + ResourceState *ResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_databasepropertiesgeoreplication.go b/resource-manager/redisenterprise/2025-04-01/databases/model_databasepropertiesgeoreplication.go new file mode 100644 index 00000000000..1aa0445a637 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_databasepropertiesgeoreplication.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasePropertiesGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_databaseupdate.go b/resource-manager/redisenterprise/2025-04-01/databases/model_databaseupdate.go new file mode 100644 index 00000000000..038f991ecef --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_databaseupdate.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUpdate struct { + Properties *DatabaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_exportclusterparameters.go b/resource-manager/redisenterprise/2025-04-01/databases/model_exportclusterparameters.go new file mode 100644 index 00000000000..35c3ad5e660 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_exportclusterparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportClusterParameters struct { + SasUri string `json:"sasUri"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_flushparameters.go b/resource-manager/redisenterprise/2025-04-01/databases/model_flushparameters.go new file mode 100644 index 00000000000..7ac8c6633b3 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_flushparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FlushParameters struct { + Ids *[]string `json:"ids,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparameters.go b/resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparameters.go new file mode 100644 index 00000000000..8d9d8518ad1 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParameters struct { + GeoReplication ForceLinkParametersGeoReplication `json:"geoReplication"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparametersgeoreplication.go b/resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparametersgeoreplication.go new file mode 100644 index 00000000000..89772649f89 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_forcelinkparametersgeoreplication.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParametersGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_forceunlinkparameters.go b/resource-manager/redisenterprise/2025-04-01/databases/model_forceunlinkparameters.go new file mode 100644 index 00000000000..f3f97fbc4bf --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_forceunlinkparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceUnlinkParameters struct { + Ids []string `json:"ids"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_importclusterparameters.go b/resource-manager/redisenterprise/2025-04-01/databases/model_importclusterparameters.go new file mode 100644 index 00000000000..fa3be54a50f --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_importclusterparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportClusterParameters struct { + SasUris []string `json:"sasUris"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_linkeddatabase.go b/resource-manager/redisenterprise/2025-04-01/databases/model_linkeddatabase.go new file mode 100644 index 00000000000..215442f62da --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_linkeddatabase.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedDatabase struct { + Id *string `json:"id,omitempty"` + State *LinkState `json:"state,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_module.go b/resource-manager/redisenterprise/2025-04-01/databases/model_module.go new file mode 100644 index 00000000000..bde6a3ad4d4 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_module.go @@ -0,0 +1,10 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Module struct { + Args *string `json:"args,omitempty"` + Name string `json:"name"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_persistence.go b/resource-manager/redisenterprise/2025-04-01/databases/model_persistence.go new file mode 100644 index 00000000000..fd1e748a3dd --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_persistence.go @@ -0,0 +1,11 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Persistence struct { + AofEnabled *bool `json:"aofEnabled,omitempty"` + AofFrequency *AofFrequency `json:"aofFrequency,omitempty"` + RdbEnabled *bool `json:"rdbEnabled,omitempty"` + RdbFrequency *RdbFrequency `json:"rdbFrequency,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/model_regeneratekeyparameters.go b/resource-manager/redisenterprise/2025-04-01/databases/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..fa84cc54ad5 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyType AccessKeyType `json:"keyType"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/databases/predicates.go b/resource-manager/redisenterprise/2025-04-01/databases/predicates.go new file mode 100644 index 00000000000..2807e5e11fc --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/predicates.go @@ -0,0 +1,50 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AccessPolicyAssignmentOperationPredicate) Matches(input AccessPolicyAssignment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type DatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseOperationPredicate) Matches(input Database) 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/redisenterprise/2025-04-01/databases/version.go b/resource-manager/redisenterprise/2025-04-01/databases/version.go new file mode 100644 index 00000000000..037600529af --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/databases/version.go @@ -0,0 +1,10 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-04-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databases/2025-04-01" +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/README.md b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..2b5fce0e4e1 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2025-04-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Put` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.PutThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/client.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/constants.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c5850609650 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..26ef2c08058 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..6361371497e --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise.go new file mode 100644 index 00000000000..6449511cb2f --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(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 := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise_test.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise_test.go new file mode 100644 index 00000000000..d5ce5afd6e9 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +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 = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId 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/redisenterprise/2025-04-01/privateendpointconnections/method_delete.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package privateendpointconnections + +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 PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_get.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..351242746d4 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_list.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_list.go new file mode 100644 index 00000000000..fbc4f5b3c1c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_list.go @@ -0,0 +1,54 @@ +package privateendpointconnections + +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 *PrivateEndpointConnectionListResult +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id RedisEnterpriseId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnectionListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_put.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_put.go new file mode 100644 index 00000000000..8f6e3022d15 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/method_put.go @@ -0,0 +1,74 @@ +package privateendpointconnections + +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 PutOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Put ... +func (c PrivateEndpointConnectionsClient) Put(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PutThenPoll performs Put then polls until it's completed +func (c PrivateEndpointConnectionsClient) PutThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.Put(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Put: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Put: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionlistresult.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionlistresult.go new file mode 100644 index 00000000000..92a9ecb105a --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionlistresult.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionListResult struct { + Value *[]PrivateEndpointConnection `json:"value,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..549d255f069 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ec3f7a9f24c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/version.go b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..4975b737870 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-04-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2025-04-01" +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/README.md b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/README.md new file mode 100644 index 00000000000..4e8c7ff1a09 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2025-04-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByCluster` + +```go +ctx := context.TODO() +id := privatelinkresources.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +read, err := client.ListByCluster(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/client.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/client.go new file mode 100644 index 00000000000..28c00b21f03 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise.go new file mode 100644 index 00000000000..b57b6c2bd42 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise.go @@ -0,0 +1,130 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(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 := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise_test.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise_test.go new file mode 100644 index 00000000000..c43caa9e0f6 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +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 = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId 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/redisenterprise/2025-04-01/privatelinkresources/method_listbycluster.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/method_listbycluster.go new file mode 100644 index 00000000000..ab94a7b4ec4 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/method_listbycluster.go @@ -0,0 +1,54 @@ +package privatelinkresources + +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 *PrivateLinkResourceListResult +} + +// ListByCluster ... +func (c PrivateLinkResourcesClient) ListByCluster(ctx context.Context, id RedisEnterpriseId) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResourceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourcelistresult.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourcelistresult.go new file mode 100644 index 00000000000..fa950217c47 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourcelistresult.go @@ -0,0 +1,8 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceListResult struct { + Value *[]PrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/privatelinkresources/version.go b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/version.go new file mode 100644 index 00000000000..3ff5793be0d --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/privatelinkresources/version.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-04-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresources/2025-04-01" +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/README.md b/resource-manager/redisenterprise/2025-04-01/redisenterprise/README.md new file mode 100644 index 00000000000..cf29d1051a8 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/README.md @@ -0,0 +1,388 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/redisenterprise` Documentation + +The `redisenterprise` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2025-04-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2025-04-01/redisenterprise" +``` + + +### Client Initialization + +```go +client := redisenterprise.NewRedisEnterpriseClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RedisEnterpriseClient.AccessPolicyAssignmentCreateUpdate` + +```go +ctx := context.TODO() +id := redisenterprise.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +payload := redisenterprise.AccessPolicyAssignment{ + // ... +} + + +if err := client.AccessPolicyAssignmentCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.AccessPolicyAssignmentDelete` + +```go +ctx := context.TODO() +id := redisenterprise.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +if err := client.AccessPolicyAssignmentDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.AccessPolicyAssignmentGet` + +```go +ctx := context.TODO() +id := redisenterprise.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + +read, err := client.AccessPolicyAssignmentGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisEnterpriseClient.AccessPolicyAssignmentList` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +// alternatively `client.AccessPolicyAssignmentList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyAssignmentListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisEnterpriseClient.Create` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +payload := redisenterprise.Cluster{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesCreate` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.Database{ + // ... +} + + +if err := client.DatabasesCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesDelete` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +if err := client.DatabasesDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesExport` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ExportClusterParameters{ + // ... +} + + +if err := client.DatabasesExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesFlush` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.FlushParameters{ + // ... +} + + +if err := client.DatabasesFlushThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesForceLinkToReplicationGroup` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ForceLinkParameters{ + // ... +} + + +if err := client.DatabasesForceLinkToReplicationGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesForceUnlink` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ForceUnlinkParameters{ + // ... +} + + +if err := client.DatabasesForceUnlinkThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesGet` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.DatabasesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesImport` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ImportClusterParameters{ + // ... +} + + +if err := client.DatabasesImportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesListByCluster` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +// alternatively `client.DatabasesListByCluster(ctx, id)` can be used to do batched pagination +items, err := client.DatabasesListByClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesListKeys` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.DatabasesListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesRegenerateKey` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.RegenerateKeyParameters{ + // ... +} + + +if err := client.DatabasesRegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesUpdate` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.DatabaseUpdate{ + // ... +} + + +if err := client.DatabasesUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesUpgradeDBRedisVersion` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +if err := client.DatabasesUpgradeDBRedisVersionThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.Delete` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.Get` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +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: `RedisEnterpriseClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `RedisEnterpriseClient.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: `RedisEnterpriseClient.Update` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +payload := redisenterprise.ClusterUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/client.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/client.go new file mode 100644 index 00000000000..08640dfb307 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/client.go @@ -0,0 +1,26 @@ +package redisenterprise + +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 RedisEnterpriseClient struct { + Client *resourcemanager.Client +} + +func NewRedisEnterpriseClientWithBaseURI(sdkApi sdkEnv.Api) (*RedisEnterpriseClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "redisenterprise", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RedisEnterpriseClient: %+v", err) + } + + return &RedisEnterpriseClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/constants.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/constants.go new file mode 100644 index 00000000000..21973a6f71b --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/constants.go @@ -0,0 +1,1044 @@ +package redisenterprise + +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 AccessKeyType string + +const ( + AccessKeyTypePrimary AccessKeyType = "Primary" + AccessKeyTypeSecondary AccessKeyType = "Secondary" +) + +func PossibleValuesForAccessKeyType() []string { + return []string{ + string(AccessKeyTypePrimary), + string(AccessKeyTypeSecondary), + } +} + +func (s *AccessKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessKeyType(input string) (*AccessKeyType, error) { + vals := map[string]AccessKeyType{ + "primary": AccessKeyTypePrimary, + "secondary": AccessKeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessKeyType(input) + return &out, nil +} + +type AccessKeysAuthentication string + +const ( + AccessKeysAuthenticationDisabled AccessKeysAuthentication = "Disabled" + AccessKeysAuthenticationEnabled AccessKeysAuthentication = "Enabled" +) + +func PossibleValuesForAccessKeysAuthentication() []string { + return []string{ + string(AccessKeysAuthenticationDisabled), + string(AccessKeysAuthenticationEnabled), + } +} + +func (s *AccessKeysAuthentication) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessKeysAuthentication(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessKeysAuthentication(input string) (*AccessKeysAuthentication, error) { + vals := map[string]AccessKeysAuthentication{ + "disabled": AccessKeysAuthenticationDisabled, + "enabled": AccessKeysAuthenticationEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessKeysAuthentication(input) + return &out, nil +} + +type AofFrequency string + +const ( + AofFrequencyAlways AofFrequency = "always" + AofFrequencyOnes AofFrequency = "1s" +) + +func PossibleValuesForAofFrequency() []string { + return []string{ + string(AofFrequencyAlways), + string(AofFrequencyOnes), + } +} + +func (s *AofFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAofFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAofFrequency(input string) (*AofFrequency, error) { + vals := map[string]AofFrequency{ + "always": AofFrequencyAlways, + "1s": AofFrequencyOnes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AofFrequency(input) + return &out, nil +} + +type ClusteringPolicy string + +const ( + ClusteringPolicyEnterpriseCluster ClusteringPolicy = "EnterpriseCluster" + ClusteringPolicyOSSCluster ClusteringPolicy = "OSSCluster" +) + +func PossibleValuesForClusteringPolicy() []string { + return []string{ + string(ClusteringPolicyEnterpriseCluster), + string(ClusteringPolicyOSSCluster), + } +} + +func (s *ClusteringPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusteringPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusteringPolicy(input string) (*ClusteringPolicy, error) { + vals := map[string]ClusteringPolicy{ + "enterprisecluster": ClusteringPolicyEnterpriseCluster, + "osscluster": ClusteringPolicyOSSCluster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusteringPolicy(input) + return &out, nil +} + +type CmkIdentityType string + +const ( + CmkIdentityTypeSystemAssignedIdentity CmkIdentityType = "systemAssignedIdentity" + CmkIdentityTypeUserAssignedIdentity CmkIdentityType = "userAssignedIdentity" +) + +func PossibleValuesForCmkIdentityType() []string { + return []string{ + string(CmkIdentityTypeSystemAssignedIdentity), + string(CmkIdentityTypeUserAssignedIdentity), + } +} + +func (s *CmkIdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCmkIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCmkIdentityType(input string) (*CmkIdentityType, error) { + vals := map[string]CmkIdentityType{ + "systemassignedidentity": CmkIdentityTypeSystemAssignedIdentity, + "userassignedidentity": CmkIdentityTypeUserAssignedIdentity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CmkIdentityType(input) + return &out, nil +} + +type DeferUpgradeSetting string + +const ( + DeferUpgradeSettingDeferred DeferUpgradeSetting = "Deferred" + DeferUpgradeSettingNotDeferred DeferUpgradeSetting = "NotDeferred" +) + +func PossibleValuesForDeferUpgradeSetting() []string { + return []string{ + string(DeferUpgradeSettingDeferred), + string(DeferUpgradeSettingNotDeferred), + } +} + +func (s *DeferUpgradeSetting) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeferUpgradeSetting(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeferUpgradeSetting(input string) (*DeferUpgradeSetting, error) { + vals := map[string]DeferUpgradeSetting{ + "deferred": DeferUpgradeSettingDeferred, + "notdeferred": DeferUpgradeSettingNotDeferred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeferUpgradeSetting(input) + return &out, nil +} + +type EvictionPolicy string + +const ( + EvictionPolicyAllKeysLFU EvictionPolicy = "AllKeysLFU" + EvictionPolicyAllKeysLRU EvictionPolicy = "AllKeysLRU" + EvictionPolicyAllKeysRandom EvictionPolicy = "AllKeysRandom" + EvictionPolicyNoEviction EvictionPolicy = "NoEviction" + EvictionPolicyVolatileLFU EvictionPolicy = "VolatileLFU" + EvictionPolicyVolatileLRU EvictionPolicy = "VolatileLRU" + EvictionPolicyVolatileRandom EvictionPolicy = "VolatileRandom" + EvictionPolicyVolatileTTL EvictionPolicy = "VolatileTTL" +) + +func PossibleValuesForEvictionPolicy() []string { + return []string{ + string(EvictionPolicyAllKeysLFU), + string(EvictionPolicyAllKeysLRU), + string(EvictionPolicyAllKeysRandom), + string(EvictionPolicyNoEviction), + string(EvictionPolicyVolatileLFU), + string(EvictionPolicyVolatileLRU), + string(EvictionPolicyVolatileRandom), + string(EvictionPolicyVolatileTTL), + } +} + +func (s *EvictionPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEvictionPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEvictionPolicy(input string) (*EvictionPolicy, error) { + vals := map[string]EvictionPolicy{ + "allkeyslfu": EvictionPolicyAllKeysLFU, + "allkeyslru": EvictionPolicyAllKeysLRU, + "allkeysrandom": EvictionPolicyAllKeysRandom, + "noeviction": EvictionPolicyNoEviction, + "volatilelfu": EvictionPolicyVolatileLFU, + "volatilelru": EvictionPolicyVolatileLRU, + "volatilerandom": EvictionPolicyVolatileRandom, + "volatilettl": EvictionPolicyVolatileTTL, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EvictionPolicy(input) + return &out, nil +} + +type HighAvailability string + +const ( + HighAvailabilityDisabled HighAvailability = "Disabled" + HighAvailabilityEnabled HighAvailability = "Enabled" +) + +func PossibleValuesForHighAvailability() []string { + return []string{ + string(HighAvailabilityDisabled), + string(HighAvailabilityEnabled), + } +} + +func (s *HighAvailability) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHighAvailability(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHighAvailability(input string) (*HighAvailability, error) { + vals := map[string]HighAvailability{ + "disabled": HighAvailabilityDisabled, + "enabled": HighAvailabilityEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HighAvailability(input) + return &out, nil +} + +type Kind string + +const ( + KindVOne Kind = "v1" + KindVTwo Kind = "v2" +) + +func PossibleValuesForKind() []string { + return []string{ + string(KindVOne), + string(KindVTwo), + } +} + +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKind(input string) (*Kind, error) { + vals := map[string]Kind{ + "v1": KindVOne, + "v2": KindVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Kind(input) + return &out, nil +} + +type LinkState string + +const ( + LinkStateLinkFailed LinkState = "LinkFailed" + LinkStateLinked LinkState = "Linked" + LinkStateLinking LinkState = "Linking" + LinkStateUnlinkFailed LinkState = "UnlinkFailed" + LinkStateUnlinking LinkState = "Unlinking" +) + +func PossibleValuesForLinkState() []string { + return []string{ + string(LinkStateLinkFailed), + string(LinkStateLinked), + string(LinkStateLinking), + string(LinkStateUnlinkFailed), + string(LinkStateUnlinking), + } +} + +func (s *LinkState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkState(input string) (*LinkState, error) { + vals := map[string]LinkState{ + "linkfailed": LinkStateLinkFailed, + "linked": LinkStateLinked, + "linking": LinkStateLinking, + "unlinkfailed": LinkStateUnlinkFailed, + "unlinking": LinkStateUnlinking, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkState(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolEncrypted Protocol = "Encrypted" + ProtocolPlaintext Protocol = "Plaintext" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolEncrypted), + string(ProtocolPlaintext), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "encrypted": ProtocolEncrypted, + "plaintext": ProtocolPlaintext, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + 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{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "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 RdbFrequency string + +const ( + RdbFrequencyOneTwoh RdbFrequency = "12h" + RdbFrequencyOneh RdbFrequency = "1h" + RdbFrequencySixh RdbFrequency = "6h" +) + +func PossibleValuesForRdbFrequency() []string { + return []string{ + string(RdbFrequencyOneTwoh), + string(RdbFrequencyOneh), + string(RdbFrequencySixh), + } +} + +func (s *RdbFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRdbFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRdbFrequency(input string) (*RdbFrequency, error) { + vals := map[string]RdbFrequency{ + "12h": RdbFrequencyOneTwoh, + "1h": RdbFrequencyOneh, + "6h": RdbFrequencySixh, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RdbFrequency(input) + return &out, nil +} + +type RedundancyMode string + +const ( + RedundancyModeLR RedundancyMode = "LR" + RedundancyModeNone RedundancyMode = "None" + RedundancyModeZR RedundancyMode = "ZR" +) + +func PossibleValuesForRedundancyMode() []string { + return []string{ + string(RedundancyModeLR), + string(RedundancyModeNone), + string(RedundancyModeZR), + } +} + +func (s *RedundancyMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRedundancyMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRedundancyMode(input string) (*RedundancyMode, error) { + vals := map[string]RedundancyMode{ + "lr": RedundancyModeLR, + "none": RedundancyModeNone, + "zr": RedundancyModeZR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RedundancyMode(input) + return &out, nil +} + +type ResourceState string + +const ( + ResourceStateCreateFailed ResourceState = "CreateFailed" + ResourceStateCreating ResourceState = "Creating" + ResourceStateDeleteFailed ResourceState = "DeleteFailed" + ResourceStateDeleting ResourceState = "Deleting" + ResourceStateDisableFailed ResourceState = "DisableFailed" + ResourceStateDisabled ResourceState = "Disabled" + ResourceStateDisabling ResourceState = "Disabling" + ResourceStateEnableFailed ResourceState = "EnableFailed" + ResourceStateEnabling ResourceState = "Enabling" + ResourceStateMoving ResourceState = "Moving" + ResourceStateRunning ResourceState = "Running" + ResourceStateScaling ResourceState = "Scaling" + ResourceStateScalingFailed ResourceState = "ScalingFailed" + ResourceStateUpdateFailed ResourceState = "UpdateFailed" + ResourceStateUpdating ResourceState = "Updating" +) + +func PossibleValuesForResourceState() []string { + return []string{ + string(ResourceStateCreateFailed), + string(ResourceStateCreating), + string(ResourceStateDeleteFailed), + string(ResourceStateDeleting), + string(ResourceStateDisableFailed), + string(ResourceStateDisabled), + string(ResourceStateDisabling), + string(ResourceStateEnableFailed), + string(ResourceStateEnabling), + string(ResourceStateMoving), + string(ResourceStateRunning), + string(ResourceStateScaling), + string(ResourceStateScalingFailed), + string(ResourceStateUpdateFailed), + string(ResourceStateUpdating), + } +} + +func (s *ResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceState(input string) (*ResourceState, error) { + vals := map[string]ResourceState{ + "createfailed": ResourceStateCreateFailed, + "creating": ResourceStateCreating, + "deletefailed": ResourceStateDeleteFailed, + "deleting": ResourceStateDeleting, + "disablefailed": ResourceStateDisableFailed, + "disabled": ResourceStateDisabled, + "disabling": ResourceStateDisabling, + "enablefailed": ResourceStateEnableFailed, + "enabling": ResourceStateEnabling, + "moving": ResourceStateMoving, + "running": ResourceStateRunning, + "scaling": ResourceStateScaling, + "scalingfailed": ResourceStateScalingFailed, + "updatefailed": ResourceStateUpdateFailed, + "updating": ResourceStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceState(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameBalancedBFive SkuName = "Balanced_B5" + SkuNameBalancedBFiveHundred SkuName = "Balanced_B500" + SkuNameBalancedBFiveZero SkuName = "Balanced_B50" + SkuNameBalancedBOne SkuName = "Balanced_B1" + SkuNameBalancedBOneFiveZero SkuName = "Balanced_B150" + SkuNameBalancedBOneHundred SkuName = "Balanced_B100" + SkuNameBalancedBOneThousand SkuName = "Balanced_B1000" + SkuNameBalancedBOneZero SkuName = "Balanced_B10" + SkuNameBalancedBSevenHundred SkuName = "Balanced_B700" + SkuNameBalancedBThree SkuName = "Balanced_B3" + SkuNameBalancedBThreeFiveZero SkuName = "Balanced_B350" + SkuNameBalancedBTwoFiveZero SkuName = "Balanced_B250" + SkuNameBalancedBTwoZero SkuName = "Balanced_B20" + SkuNameBalancedBZero SkuName = "Balanced_B0" + SkuNameComputeOptimizedXFive SkuName = "ComputeOptimized_X5" + SkuNameComputeOptimizedXFiveHundred SkuName = "ComputeOptimized_X500" + SkuNameComputeOptimizedXFiveZero SkuName = "ComputeOptimized_X50" + SkuNameComputeOptimizedXOneFiveZero SkuName = "ComputeOptimized_X150" + SkuNameComputeOptimizedXOneHundred SkuName = "ComputeOptimized_X100" + SkuNameComputeOptimizedXOneZero SkuName = "ComputeOptimized_X10" + SkuNameComputeOptimizedXSevenHundred SkuName = "ComputeOptimized_X700" + SkuNameComputeOptimizedXThree SkuName = "ComputeOptimized_X3" + SkuNameComputeOptimizedXThreeFiveZero SkuName = "ComputeOptimized_X350" + SkuNameComputeOptimizedXTwoFiveZero SkuName = "ComputeOptimized_X250" + SkuNameComputeOptimizedXTwoZero SkuName = "ComputeOptimized_X20" + SkuNameEnterpriseEFive SkuName = "Enterprise_E5" + SkuNameEnterpriseEFiveZero SkuName = "Enterprise_E50" + SkuNameEnterpriseEFourHundred SkuName = "Enterprise_E400" + SkuNameEnterpriseEOne SkuName = "Enterprise_E1" + SkuNameEnterpriseEOneHundred SkuName = "Enterprise_E100" + SkuNameEnterpriseEOneZero SkuName = "Enterprise_E10" + SkuNameEnterpriseETwoHundred SkuName = "Enterprise_E200" + SkuNameEnterpriseETwoZero SkuName = "Enterprise_E20" + SkuNameEnterpriseFlashFOneFiveHundred SkuName = "EnterpriseFlash_F1500" + SkuNameEnterpriseFlashFSevenHundred SkuName = "EnterpriseFlash_F700" + SkuNameEnterpriseFlashFThreeHundred SkuName = "EnterpriseFlash_F300" + SkuNameFlashOptimizedAFiveHundred SkuName = "FlashOptimized_A500" + SkuNameFlashOptimizedAFourFiveHundred SkuName = "FlashOptimized_A4500" + SkuNameFlashOptimizedAOneFiveHundred SkuName = "FlashOptimized_A1500" + SkuNameFlashOptimizedAOneThousand SkuName = "FlashOptimized_A1000" + SkuNameFlashOptimizedASevenHundred SkuName = "FlashOptimized_A700" + SkuNameFlashOptimizedATwoFiveZero SkuName = "FlashOptimized_A250" + SkuNameFlashOptimizedATwoThousand SkuName = "FlashOptimized_A2000" + SkuNameMemoryOptimizedMFiveHundred SkuName = "MemoryOptimized_M500" + SkuNameMemoryOptimizedMFiveZero SkuName = "MemoryOptimized_M50" + SkuNameMemoryOptimizedMOneFiveHundred SkuName = "MemoryOptimized_M1500" + SkuNameMemoryOptimizedMOneFiveZero SkuName = "MemoryOptimized_M150" + SkuNameMemoryOptimizedMOneHundred SkuName = "MemoryOptimized_M100" + SkuNameMemoryOptimizedMOneThousand SkuName = "MemoryOptimized_M1000" + SkuNameMemoryOptimizedMOneZero SkuName = "MemoryOptimized_M10" + SkuNameMemoryOptimizedMSevenHundred SkuName = "MemoryOptimized_M700" + SkuNameMemoryOptimizedMThreeFiveZero SkuName = "MemoryOptimized_M350" + SkuNameMemoryOptimizedMTwoFiveZero SkuName = "MemoryOptimized_M250" + SkuNameMemoryOptimizedMTwoThousand SkuName = "MemoryOptimized_M2000" + SkuNameMemoryOptimizedMTwoZero SkuName = "MemoryOptimized_M20" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameBalancedBFive), + string(SkuNameBalancedBFiveHundred), + string(SkuNameBalancedBFiveZero), + string(SkuNameBalancedBOne), + string(SkuNameBalancedBOneFiveZero), + string(SkuNameBalancedBOneHundred), + string(SkuNameBalancedBOneThousand), + string(SkuNameBalancedBOneZero), + string(SkuNameBalancedBSevenHundred), + string(SkuNameBalancedBThree), + string(SkuNameBalancedBThreeFiveZero), + string(SkuNameBalancedBTwoFiveZero), + string(SkuNameBalancedBTwoZero), + string(SkuNameBalancedBZero), + string(SkuNameComputeOptimizedXFive), + string(SkuNameComputeOptimizedXFiveHundred), + string(SkuNameComputeOptimizedXFiveZero), + string(SkuNameComputeOptimizedXOneFiveZero), + string(SkuNameComputeOptimizedXOneHundred), + string(SkuNameComputeOptimizedXOneZero), + string(SkuNameComputeOptimizedXSevenHundred), + string(SkuNameComputeOptimizedXThree), + string(SkuNameComputeOptimizedXThreeFiveZero), + string(SkuNameComputeOptimizedXTwoFiveZero), + string(SkuNameComputeOptimizedXTwoZero), + string(SkuNameEnterpriseEFive), + string(SkuNameEnterpriseEFiveZero), + string(SkuNameEnterpriseEFourHundred), + string(SkuNameEnterpriseEOne), + string(SkuNameEnterpriseEOneHundred), + string(SkuNameEnterpriseEOneZero), + string(SkuNameEnterpriseETwoHundred), + string(SkuNameEnterpriseETwoZero), + string(SkuNameEnterpriseFlashFOneFiveHundred), + string(SkuNameEnterpriseFlashFSevenHundred), + string(SkuNameEnterpriseFlashFThreeHundred), + string(SkuNameFlashOptimizedAFiveHundred), + string(SkuNameFlashOptimizedAFourFiveHundred), + string(SkuNameFlashOptimizedAOneFiveHundred), + string(SkuNameFlashOptimizedAOneThousand), + string(SkuNameFlashOptimizedASevenHundred), + string(SkuNameFlashOptimizedATwoFiveZero), + string(SkuNameFlashOptimizedATwoThousand), + string(SkuNameMemoryOptimizedMFiveHundred), + string(SkuNameMemoryOptimizedMFiveZero), + string(SkuNameMemoryOptimizedMOneFiveHundred), + string(SkuNameMemoryOptimizedMOneFiveZero), + string(SkuNameMemoryOptimizedMOneHundred), + string(SkuNameMemoryOptimizedMOneThousand), + string(SkuNameMemoryOptimizedMOneZero), + string(SkuNameMemoryOptimizedMSevenHundred), + string(SkuNameMemoryOptimizedMThreeFiveZero), + string(SkuNameMemoryOptimizedMTwoFiveZero), + string(SkuNameMemoryOptimizedMTwoThousand), + string(SkuNameMemoryOptimizedMTwoZero), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "balanced_b5": SkuNameBalancedBFive, + "balanced_b500": SkuNameBalancedBFiveHundred, + "balanced_b50": SkuNameBalancedBFiveZero, + "balanced_b1": SkuNameBalancedBOne, + "balanced_b150": SkuNameBalancedBOneFiveZero, + "balanced_b100": SkuNameBalancedBOneHundred, + "balanced_b1000": SkuNameBalancedBOneThousand, + "balanced_b10": SkuNameBalancedBOneZero, + "balanced_b700": SkuNameBalancedBSevenHundred, + "balanced_b3": SkuNameBalancedBThree, + "balanced_b350": SkuNameBalancedBThreeFiveZero, + "balanced_b250": SkuNameBalancedBTwoFiveZero, + "balanced_b20": SkuNameBalancedBTwoZero, + "balanced_b0": SkuNameBalancedBZero, + "computeoptimized_x5": SkuNameComputeOptimizedXFive, + "computeoptimized_x500": SkuNameComputeOptimizedXFiveHundred, + "computeoptimized_x50": SkuNameComputeOptimizedXFiveZero, + "computeoptimized_x150": SkuNameComputeOptimizedXOneFiveZero, + "computeoptimized_x100": SkuNameComputeOptimizedXOneHundred, + "computeoptimized_x10": SkuNameComputeOptimizedXOneZero, + "computeoptimized_x700": SkuNameComputeOptimizedXSevenHundred, + "computeoptimized_x3": SkuNameComputeOptimizedXThree, + "computeoptimized_x350": SkuNameComputeOptimizedXThreeFiveZero, + "computeoptimized_x250": SkuNameComputeOptimizedXTwoFiveZero, + "computeoptimized_x20": SkuNameComputeOptimizedXTwoZero, + "enterprise_e5": SkuNameEnterpriseEFive, + "enterprise_e50": SkuNameEnterpriseEFiveZero, + "enterprise_e400": SkuNameEnterpriseEFourHundred, + "enterprise_e1": SkuNameEnterpriseEOne, + "enterprise_e100": SkuNameEnterpriseEOneHundred, + "enterprise_e10": SkuNameEnterpriseEOneZero, + "enterprise_e200": SkuNameEnterpriseETwoHundred, + "enterprise_e20": SkuNameEnterpriseETwoZero, + "enterpriseflash_f1500": SkuNameEnterpriseFlashFOneFiveHundred, + "enterpriseflash_f700": SkuNameEnterpriseFlashFSevenHundred, + "enterpriseflash_f300": SkuNameEnterpriseFlashFThreeHundred, + "flashoptimized_a500": SkuNameFlashOptimizedAFiveHundred, + "flashoptimized_a4500": SkuNameFlashOptimizedAFourFiveHundred, + "flashoptimized_a1500": SkuNameFlashOptimizedAOneFiveHundred, + "flashoptimized_a1000": SkuNameFlashOptimizedAOneThousand, + "flashoptimized_a700": SkuNameFlashOptimizedASevenHundred, + "flashoptimized_a250": SkuNameFlashOptimizedATwoFiveZero, + "flashoptimized_a2000": SkuNameFlashOptimizedATwoThousand, + "memoryoptimized_m500": SkuNameMemoryOptimizedMFiveHundred, + "memoryoptimized_m50": SkuNameMemoryOptimizedMFiveZero, + "memoryoptimized_m1500": SkuNameMemoryOptimizedMOneFiveHundred, + "memoryoptimized_m150": SkuNameMemoryOptimizedMOneFiveZero, + "memoryoptimized_m100": SkuNameMemoryOptimizedMOneHundred, + "memoryoptimized_m1000": SkuNameMemoryOptimizedMOneThousand, + "memoryoptimized_m10": SkuNameMemoryOptimizedMOneZero, + "memoryoptimized_m700": SkuNameMemoryOptimizedMSevenHundred, + "memoryoptimized_m350": SkuNameMemoryOptimizedMThreeFiveZero, + "memoryoptimized_m250": SkuNameMemoryOptimizedMTwoFiveZero, + "memoryoptimized_m2000": SkuNameMemoryOptimizedMTwoThousand, + "memoryoptimized_m20": SkuNameMemoryOptimizedMTwoZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment.go new file mode 100644 index 00000000000..5e8e6bb4f4c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment.go @@ -0,0 +1,148 @@ +package redisenterprise + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyAssignmentId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +// AccessPolicyAssignmentId is a struct representing the Resource ID for a Access Policy Assignment +type AccessPolicyAssignmentId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string + AccessPolicyAssignmentName string +} + +// NewAccessPolicyAssignmentID returns a new AccessPolicyAssignmentId struct +func NewAccessPolicyAssignmentID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string, accessPolicyAssignmentName string) AccessPolicyAssignmentId { + return AccessPolicyAssignmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + AccessPolicyAssignmentName: accessPolicyAssignmentName, + } +} + +// ParseAccessPolicyAssignmentID parses 'input' into a AccessPolicyAssignmentId +func ParseAccessPolicyAssignmentID(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyAssignmentIDInsensitively parses 'input' case-insensitively into a AccessPolicyAssignmentId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyAssignmentIDInsensitively(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyAssignmentId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.AccessPolicyAssignmentName, ok = input.Parsed["accessPolicyAssignmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyAssignmentName", input) + } + + return nil +} + +// ValidateAccessPolicyAssignmentID checks that 'input' can be parsed as a Access Policy Assignment ID +func ValidateAccessPolicyAssignmentID(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 := ParseAccessPolicyAssignmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy Assignment ID +func (id AccessPolicyAssignmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s/accessPolicyAssignments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName, id.AccessPolicyAssignmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticAccessPolicyAssignments", "accessPolicyAssignments", "accessPolicyAssignments"), + resourceids.UserSpecifiedSegment("accessPolicyAssignmentName", "accessPolicyAssignmentName"), + } +} + +// String returns a human-readable description of this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Access Policy Assignment Name: %q", id.AccessPolicyAssignmentName), + } + return fmt.Sprintf("Access Policy Assignment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment_test.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment_test.go new file mode 100644 index 00000000000..397b9f0c66d --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_accesspolicyassignment_test.go @@ -0,0 +1,372 @@ +package redisenterprise + +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 = &AccessPolicyAssignmentId{} + +func TestNewAccessPolicyAssignmentID(t *testing.T) { + id := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.AccessPolicyAssignmentName != "accessPolicyAssignmentName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyAssignmentName'", id.AccessPolicyAssignmentName, "accessPolicyAssignmentName") + } +} + +func TestFormatAccessPolicyAssignmentID(t *testing.T) { + actual := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName", "accessPolicyAssignmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyAssignmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestParseAccessPolicyAssignmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + AccessPolicyAssignmentName: "aCcEsSpOlIcYaSsIgNmEnTnAmE", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestSegmentsForAccessPolicyAssignmentId(t *testing.T) { + segments := AccessPolicyAssignmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyAssignmentId 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/redisenterprise/2025-04-01/redisenterprise/id_database.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database.go new file mode 100644 index 00000000000..f7352ec7d89 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database.go @@ -0,0 +1,139 @@ +package redisenterprise + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseId{}) +} + +var _ resourceids.ResourceId = &DatabaseId{} + +// DatabaseId is a struct representing the Resource ID for a Database +type DatabaseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string +} + +// NewDatabaseID returns a new DatabaseId struct +func NewDatabaseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string) DatabaseId { + return DatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + } +} + +// ParseDatabaseID parses 'input' into a DatabaseId +func ParseDatabaseID(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseIDInsensitively parses 'input' case-insensitively into a DatabaseId +// note: this method should only be used for API response data and not user input +func ParseDatabaseIDInsensitively(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + return nil +} + +// ValidateDatabaseID checks that 'input' can be parsed as a Database ID +func ValidateDatabaseID(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 := ParseDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database ID +func (id DatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database ID +func (id DatabaseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + } +} + +// String returns a human-readable description of this Database ID +func (id DatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + } + return fmt.Sprintf("Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database_test.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database_test.go new file mode 100644 index 00000000000..ec9168fdb8c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_database_test.go @@ -0,0 +1,327 @@ +package redisenterprise + +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 = &DatabaseId{} + +func TestNewDatabaseID(t *testing.T) { + id := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } +} + +func TestFormatDatabaseID(t *testing.T) { + actual := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestParseDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestSegmentsForDatabaseId(t *testing.T) { + segments := DatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseId 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/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise.go new file mode 100644 index 00000000000..de1d9d9bef2 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise.go @@ -0,0 +1,130 @@ +package redisenterprise + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) 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.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(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 := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise_test.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise_test.go new file mode 100644 index 00000000000..8676cc8523e --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package redisenterprise + +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 = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + 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.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // 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.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(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.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId 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/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentcreateupdate.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentcreateupdate.go new file mode 100644 index 00000000000..41586117882 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentcreateupdate.go @@ -0,0 +1,75 @@ +package redisenterprise + +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 AccessPolicyAssignmentCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessPolicyAssignment +} + +// AccessPolicyAssignmentCreateUpdate ... +func (c RedisEnterpriseClient) AccessPolicyAssignmentCreateUpdate(ctx context.Context, id AccessPolicyAssignmentId, input AccessPolicyAssignment) (result AccessPolicyAssignmentCreateUpdateOperationResponse, 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 +} + +// AccessPolicyAssignmentCreateUpdateThenPoll performs AccessPolicyAssignmentCreateUpdate then polls until it's completed +func (c RedisEnterpriseClient) AccessPolicyAssignmentCreateUpdateThenPoll(ctx context.Context, id AccessPolicyAssignmentId, input AccessPolicyAssignment) error { + result, err := c.AccessPolicyAssignmentCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentdelete.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentdelete.go new file mode 100644 index 00000000000..fd53ae3692a --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentdelete.go @@ -0,0 +1,70 @@ +package redisenterprise + +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 AccessPolicyAssignmentDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyAssignmentDelete ... +func (c RedisEnterpriseClient) AccessPolicyAssignmentDelete(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentDeleteOperationResponse, 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 +} + +// AccessPolicyAssignmentDeleteThenPoll performs AccessPolicyAssignmentDelete then polls until it's completed +func (c RedisEnterpriseClient) AccessPolicyAssignmentDeleteThenPoll(ctx context.Context, id AccessPolicyAssignmentId) error { + result, err := c.AccessPolicyAssignmentDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentget.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentget.go new file mode 100644 index 00000000000..b1bc0f706d7 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentget.go @@ -0,0 +1,53 @@ +package redisenterprise + +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 AccessPolicyAssignmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessPolicyAssignment +} + +// AccessPolicyAssignmentGet ... +func (c RedisEnterpriseClient) AccessPolicyAssignmentGet(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentGetOperationResponse, 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 AccessPolicyAssignment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentlist.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentlist.go new file mode 100644 index 00000000000..7a2b05043bb --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_accesspolicyassignmentlist.go @@ -0,0 +1,105 @@ +package redisenterprise + +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 AccessPolicyAssignmentListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AccessPolicyAssignment +} + +type AccessPolicyAssignmentListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AccessPolicyAssignment +} + +type AccessPolicyAssignmentListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyAssignmentListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyAssignmentList ... +func (c RedisEnterpriseClient) AccessPolicyAssignmentList(ctx context.Context, id DatabaseId) (result AccessPolicyAssignmentListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyAssignmentListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicyAssignments", 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 *[]AccessPolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyAssignmentListComplete retrieves all the results into a single object +func (c RedisEnterpriseClient) AccessPolicyAssignmentListComplete(ctx context.Context, id DatabaseId) (AccessPolicyAssignmentListCompleteResult, error) { + return c.AccessPolicyAssignmentListCompleteMatchingPredicate(ctx, id, AccessPolicyAssignmentOperationPredicate{}) +} + +// AccessPolicyAssignmentListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisEnterpriseClient) AccessPolicyAssignmentListCompleteMatchingPredicate(ctx context.Context, id DatabaseId, predicate AccessPolicyAssignmentOperationPredicate) (result AccessPolicyAssignmentListCompleteResult, err error) { + items := make([]AccessPolicyAssignment, 0) + + resp, err := c.AccessPolicyAssignmentList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyAssignmentListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_create.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_create.go new file mode 100644 index 00000000000..bc1b883cbbb --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_create.go @@ -0,0 +1,75 @@ +package redisenterprise + +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 *Cluster +} + +// Create ... +func (c RedisEnterpriseClient) Create(ctx context.Context, id RedisEnterpriseId, input Cluster) (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 RedisEnterpriseClient) CreateThenPoll(ctx context.Context, id RedisEnterpriseId, input Cluster) 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/redisenterprise/2025-04-01/redisenterprise/method_databasescreate.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasescreate.go new file mode 100644 index 00000000000..76933e8f063 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasescreate.go @@ -0,0 +1,75 @@ +package redisenterprise + +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 DatabasesCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// DatabasesCreate ... +func (c RedisEnterpriseClient) DatabasesCreate(ctx context.Context, id DatabaseId, input Database) (result DatabasesCreateOperationResponse, 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 +} + +// DatabasesCreateThenPoll performs DatabasesCreate then polls until it's completed +func (c RedisEnterpriseClient) DatabasesCreateThenPoll(ctx context.Context, id DatabaseId, input Database) error { + result, err := c.DatabasesCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesdelete.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesdelete.go new file mode 100644 index 00000000000..a7961442781 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesdelete.go @@ -0,0 +1,71 @@ +package redisenterprise + +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 DatabasesDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesDelete ... +func (c RedisEnterpriseClient) DatabasesDelete(ctx context.Context, id DatabaseId) (result DatabasesDeleteOperationResponse, 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 +} + +// DatabasesDeleteThenPoll performs DatabasesDelete then polls until it's completed +func (c RedisEnterpriseClient) DatabasesDeleteThenPoll(ctx context.Context, id DatabaseId) error { + result, err := c.DatabasesDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing DatabasesDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesexport.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesexport.go new file mode 100644 index 00000000000..8ce4d87e186 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesexport.go @@ -0,0 +1,74 @@ +package redisenterprise + +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 DatabasesExportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesExport ... +func (c RedisEnterpriseClient) DatabasesExport(ctx context.Context, id DatabaseId, input ExportClusterParameters) (result DatabasesExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", 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 +} + +// DatabasesExportThenPoll performs DatabasesExport then polls until it's completed +func (c RedisEnterpriseClient) DatabasesExportThenPoll(ctx context.Context, id DatabaseId, input ExportClusterParameters) error { + result, err := c.DatabasesExport(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesExport: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesExport: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesflush.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesflush.go new file mode 100644 index 00000000000..1a2453ebee2 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesflush.go @@ -0,0 +1,74 @@ +package redisenterprise + +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 DatabasesFlushOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesFlush ... +func (c RedisEnterpriseClient) DatabasesFlush(ctx context.Context, id DatabaseId, input FlushParameters) (result DatabasesFlushOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/flush", 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 +} + +// DatabasesFlushThenPoll performs DatabasesFlush then polls until it's completed +func (c RedisEnterpriseClient) DatabasesFlushThenPoll(ctx context.Context, id DatabaseId, input FlushParameters) error { + result, err := c.DatabasesFlush(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesFlush: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesFlush: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go new file mode 100644 index 00000000000..2a6994912d6 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go @@ -0,0 +1,73 @@ +package redisenterprise + +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 DatabasesForceLinkToReplicationGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesForceLinkToReplicationGroup ... +func (c RedisEnterpriseClient) DatabasesForceLinkToReplicationGroup(ctx context.Context, id DatabaseId, input ForceLinkParameters) (result DatabasesForceLinkToReplicationGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceLinkToReplicationGroup", 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 +} + +// DatabasesForceLinkToReplicationGroupThenPoll performs DatabasesForceLinkToReplicationGroup then polls until it's completed +func (c RedisEnterpriseClient) DatabasesForceLinkToReplicationGroupThenPoll(ctx context.Context, id DatabaseId, input ForceLinkParameters) error { + result, err := c.DatabasesForceLinkToReplicationGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesForceLinkToReplicationGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesForceLinkToReplicationGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforceunlink.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforceunlink.go new file mode 100644 index 00000000000..1fc0801e823 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesforceunlink.go @@ -0,0 +1,74 @@ +package redisenterprise + +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 DatabasesForceUnlinkOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesForceUnlink ... +func (c RedisEnterpriseClient) DatabasesForceUnlink(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) (result DatabasesForceUnlinkOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceUnlink", 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 +} + +// DatabasesForceUnlinkThenPoll performs DatabasesForceUnlink then polls until it's completed +func (c RedisEnterpriseClient) DatabasesForceUnlinkThenPoll(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) error { + result, err := c.DatabasesForceUnlink(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesForceUnlink: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesForceUnlink: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesget.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesget.go new file mode 100644 index 00000000000..f774a726917 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesget.go @@ -0,0 +1,53 @@ +package redisenterprise + +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 DatabasesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// DatabasesGet ... +func (c RedisEnterpriseClient) DatabasesGet(ctx context.Context, id DatabaseId) (result DatabasesGetOperationResponse, 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 Database + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesimport.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesimport.go new file mode 100644 index 00000000000..08fff384eb6 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesimport.go @@ -0,0 +1,74 @@ +package redisenterprise + +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 DatabasesImportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesImport ... +func (c RedisEnterpriseClient) DatabasesImport(ctx context.Context, id DatabaseId, input ImportClusterParameters) (result DatabasesImportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/import", 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 +} + +// DatabasesImportThenPoll performs DatabasesImport then polls until it's completed +func (c RedisEnterpriseClient) DatabasesImportThenPoll(ctx context.Context, id DatabaseId, input ImportClusterParameters) error { + result, err := c.DatabasesImport(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesImport: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesImport: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistbycluster.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistbycluster.go new file mode 100644 index 00000000000..b8af4ecf22a --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistbycluster.go @@ -0,0 +1,105 @@ +package redisenterprise + +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 DatabasesListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Database +} + +type DatabasesListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type DatabasesListByClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DatabasesListByClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DatabasesListByCluster ... +func (c RedisEnterpriseClient) DatabasesListByCluster(ctx context.Context, id RedisEnterpriseId) (result DatabasesListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DatabasesListByClusterCustomPager{}, + Path: fmt.Sprintf("%s/databases", 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 *[]Database `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DatabasesListByClusterComplete retrieves all the results into a single object +func (c RedisEnterpriseClient) DatabasesListByClusterComplete(ctx context.Context, id RedisEnterpriseId) (DatabasesListByClusterCompleteResult, error) { + return c.DatabasesListByClusterCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// DatabasesListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisEnterpriseClient) DatabasesListByClusterCompleteMatchingPredicate(ctx context.Context, id RedisEnterpriseId, predicate DatabaseOperationPredicate) (result DatabasesListByClusterCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.DatabasesListByCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DatabasesListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistkeys.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistkeys.go new file mode 100644 index 00000000000..0232e662380 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databaseslistkeys.go @@ -0,0 +1,54 @@ +package redisenterprise + +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 DatabasesListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// DatabasesListKeys ... +func (c RedisEnterpriseClient) DatabasesListKeys(ctx context.Context, id DatabaseId) (result DatabasesListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", 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 AccessKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesregeneratekey.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesregeneratekey.go new file mode 100644 index 00000000000..62dc26cf6ea --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesregeneratekey.go @@ -0,0 +1,75 @@ +package redisenterprise + +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 DatabasesRegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// DatabasesRegenerateKey ... +func (c RedisEnterpriseClient) DatabasesRegenerateKey(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) (result DatabasesRegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", 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 +} + +// DatabasesRegenerateKeyThenPoll performs DatabasesRegenerateKey then polls until it's completed +func (c RedisEnterpriseClient) DatabasesRegenerateKeyThenPoll(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) error { + result, err := c.DatabasesRegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesRegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesRegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupdate.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupdate.go new file mode 100644 index 00000000000..2b0e7934d93 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupdate.go @@ -0,0 +1,75 @@ +package redisenterprise + +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 DatabasesUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// DatabasesUpdate ... +func (c RedisEnterpriseClient) DatabasesUpdate(ctx context.Context, id DatabaseId, input DatabaseUpdate) (result DatabasesUpdateOperationResponse, 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 +} + +// DatabasesUpdateThenPoll performs DatabasesUpdate then polls until it's completed +func (c RedisEnterpriseClient) DatabasesUpdateThenPoll(ctx context.Context, id DatabaseId, input DatabaseUpdate) error { + result, err := c.DatabasesUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupgradedbredisversion.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupgradedbredisversion.go new file mode 100644 index 00000000000..5c3e29659ac --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_databasesupgradedbredisversion.go @@ -0,0 +1,69 @@ +package redisenterprise + +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 DatabasesUpgradeDBRedisVersionOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesUpgradeDBRedisVersion ... +func (c RedisEnterpriseClient) DatabasesUpgradeDBRedisVersion(ctx context.Context, id DatabaseId) (result DatabasesUpgradeDBRedisVersionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgradeDBRedisVersion", 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 +} + +// DatabasesUpgradeDBRedisVersionThenPoll performs DatabasesUpgradeDBRedisVersion then polls until it's completed +func (c RedisEnterpriseClient) DatabasesUpgradeDBRedisVersionThenPoll(ctx context.Context, id DatabaseId) error { + result, err := c.DatabasesUpgradeDBRedisVersion(ctx, id) + if err != nil { + return fmt.Errorf("performing DatabasesUpgradeDBRedisVersion: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesUpgradeDBRedisVersion: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_delete.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_delete.go new file mode 100644 index 00000000000..d15634da2c0 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_delete.go @@ -0,0 +1,71 @@ +package redisenterprise + +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 RedisEnterpriseClient) Delete(ctx context.Context, id RedisEnterpriseId) (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 RedisEnterpriseClient) DeleteThenPoll(ctx context.Context, id RedisEnterpriseId) 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/redisenterprise/2025-04-01/redisenterprise/method_get.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_get.go new file mode 100644 index 00000000000..c729b30e660 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_get.go @@ -0,0 +1,53 @@ +package redisenterprise + +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 RedisEnterpriseClient) Get(ctx context.Context, id RedisEnterpriseId) (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/redisenterprise/2025-04-01/redisenterprise/method_list.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_list.go new file mode 100644 index 00000000000..b3062bf1802 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_list.go @@ -0,0 +1,106 @@ +package redisenterprise + +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 *[]Cluster +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c RedisEnterpriseClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Cache/redisEnterprise", 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 +} + +// ListComplete retrieves all the results into a single object +func (c RedisEnterpriseClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisEnterpriseClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_listbyresourcegroup.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_listbyresourcegroup.go new file mode 100644 index 00000000000..181676b5089 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package redisenterprise + +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 +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c RedisEnterpriseClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Cache/redisEnterprise", 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 RedisEnterpriseClient) 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 RedisEnterpriseClient) 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 { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_update.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_update.go new file mode 100644 index 00000000000..e23cde29632 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/method_update.go @@ -0,0 +1,75 @@ +package redisenterprise + +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 *Cluster +} + +// Update ... +func (c RedisEnterpriseClient) Update(ctx context.Context, id RedisEnterpriseId, input ClusterUpdate) (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 RedisEnterpriseClient) UpdateThenPoll(ctx context.Context, id RedisEnterpriseId, input ClusterUpdate) 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/redisenterprise/2025-04-01/redisenterprise/model_accesskeys.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesskeys.go new file mode 100644 index 00000000000..79566de711f --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesskeys.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessKeys struct { + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignment.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignment.go new file mode 100644 index 00000000000..0b0a3710006 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignment.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AccessPolicyAssignmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentproperties.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentproperties.go new file mode 100644 index 00000000000..30b569d150a --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentproperties.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentProperties struct { + AccessPolicyName string `json:"accessPolicyName"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + User AccessPolicyAssignmentPropertiesUser `json:"user"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentpropertiesuser.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentpropertiesuser.go new file mode 100644 index 00000000000..9e3ea3ec6fb --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_accesspolicyassignmentpropertiesuser.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentPropertiesUser struct { + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_cluster.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_cluster.go new file mode 100644 index 00000000000..86351282680 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_cluster.go @@ -0,0 +1,22 @@ +package redisenterprise + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// 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"` + Kind *Kind `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ClusterProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterproperties.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterproperties.go new file mode 100644 index 00000000000..bc536132c2e --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterproperties.go @@ -0,0 +1,16 @@ +package redisenterprise + +// 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 { + Encryption *ClusterPropertiesEncryption `json:"encryption,omitempty"` + HighAvailability *HighAvailability `json:"highAvailability,omitempty"` + HostName *string `json:"hostName,omitempty"` + MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + RedundancyMode *RedundancyMode `json:"redundancyMode,omitempty"` + ResourceState *ResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryption.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryption.go new file mode 100644 index 00000000000..253b894977f --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryption.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesEncryption struct { + CustomerManagedKeyEncryption *ClusterPropertiesEncryptionCustomerManagedKeyEncryption `json:"customerManagedKeyEncryption,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go new file mode 100644 index 00000000000..8c3ddebdaca --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesEncryptionCustomerManagedKeyEncryption struct { + KeyEncryptionKeyIdentity *ClusterPropertiesEncryptionCustomerManagedKeyEncryptionKeyEncryptionKeyIdentity `json:"keyEncryptionKeyIdentity,omitempty"` + KeyEncryptionKeyURL *string `json:"keyEncryptionKeyUrl,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go new file mode 100644 index 00000000000..e99632be68c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesEncryptionCustomerManagedKeyEncryptionKeyEncryptionKeyIdentity struct { + IdentityType *CmkIdentityType `json:"identityType,omitempty"` + UserAssignedIdentityResourceId *string `json:"userAssignedIdentityResourceId,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterupdate.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterupdate.go new file mode 100644 index 00000000000..b5489a543df --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_clusterupdate.go @@ -0,0 +1,15 @@ +package redisenterprise + +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 ClusterUpdate struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ClusterProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_database.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_database.go new file mode 100644 index 00000000000..dd20d0b355a --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_database.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Database struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseproperties.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseproperties.go new file mode 100644 index 00000000000..196a6705bc9 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseproperties.go @@ -0,0 +1,19 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseProperties struct { + AccessKeysAuthentication *AccessKeysAuthentication `json:"accessKeysAuthentication,omitempty"` + ClientProtocol *Protocol `json:"clientProtocol,omitempty"` + ClusteringPolicy *ClusteringPolicy `json:"clusteringPolicy,omitempty"` + DeferUpgrade *DeferUpgradeSetting `json:"deferUpgrade,omitempty"` + EvictionPolicy *EvictionPolicy `json:"evictionPolicy,omitempty"` + GeoReplication *DatabasePropertiesGeoReplication `json:"geoReplication,omitempty"` + Modules *[]Module `json:"modules,omitempty"` + Persistence *Persistence `json:"persistence,omitempty"` + Port *int64 `json:"port,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + ResourceState *ResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databasepropertiesgeoreplication.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databasepropertiesgeoreplication.go new file mode 100644 index 00000000000..3244185bf85 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databasepropertiesgeoreplication.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasePropertiesGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseupdate.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseupdate.go new file mode 100644 index 00000000000..aff0488e608 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_databaseupdate.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUpdate struct { + Properties *DatabaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_exportclusterparameters.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_exportclusterparameters.go new file mode 100644 index 00000000000..d6ba54aa230 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_exportclusterparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportClusterParameters struct { + SasUri string `json:"sasUri"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_flushparameters.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_flushparameters.go new file mode 100644 index 00000000000..9d3358ea741 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_flushparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FlushParameters struct { + Ids *[]string `json:"ids,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparameters.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparameters.go new file mode 100644 index 00000000000..b80b6aaf76b --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParameters struct { + GeoReplication ForceLinkParametersGeoReplication `json:"geoReplication"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparametersgeoreplication.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparametersgeoreplication.go new file mode 100644 index 00000000000..53242cf971b --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forcelinkparametersgeoreplication.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParametersGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forceunlinkparameters.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forceunlinkparameters.go new file mode 100644 index 00000000000..7bf82a13709 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_forceunlinkparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceUnlinkParameters struct { + Ids []string `json:"ids"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_importclusterparameters.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_importclusterparameters.go new file mode 100644 index 00000000000..11e13cd4dc4 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_importclusterparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportClusterParameters struct { + SasUris []string `json:"sasUris"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_linkeddatabase.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_linkeddatabase.go new file mode 100644 index 00000000000..02abc0422ce --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_linkeddatabase.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedDatabase struct { + Id *string `json:"id,omitempty"` + State *LinkState `json:"state,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_module.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_module.go new file mode 100644 index 00000000000..99bd8473a0f --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_module.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Module struct { + Args *string `json:"args,omitempty"` + Name string `json:"name"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_persistence.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_persistence.go new file mode 100644 index 00000000000..3b7b30f2fb9 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_persistence.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Persistence struct { + AofEnabled *bool `json:"aofEnabled,omitempty"` + AofFrequency *AofFrequency `json:"aofFrequency,omitempty"` + RdbEnabled *bool `json:"rdbEnabled,omitempty"` + RdbFrequency *RdbFrequency `json:"rdbFrequency,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpoint.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpoint.go new file mode 100644 index 00000000000..e15699fe1d1 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpoint.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnection.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnection.go new file mode 100644 index 00000000000..5da2f77534d --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnectionproperties.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..9ebfbe2d3c2 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privatelinkserviceconnectionstate.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..abb658aee84 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_regeneratekeyparameters.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..2d44026dd91 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyType AccessKeyType `json:"keyType"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_sku.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_sku.go new file mode 100644 index 00000000000..740c3615e0c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/model_sku.go @@ -0,0 +1,9 @@ +package redisenterprise + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Name SkuName `json:"name"` +} diff --git a/resource-manager/redisenterprise/2025-04-01/redisenterprise/predicates.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/predicates.go new file mode 100644 index 00000000000..ae97e32ba4c --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/predicates.go @@ -0,0 +1,78 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AccessPolicyAssignmentOperationPredicate) Matches(input AccessPolicyAssignment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type 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 +} + +type DatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseOperationPredicate) Matches(input Database) 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/redisenterprise/2025-04-01/redisenterprise/version.go b/resource-manager/redisenterprise/2025-04-01/redisenterprise/version.go new file mode 100644 index 00000000000..1b7d1117fa9 --- /dev/null +++ b/resource-manager/redisenterprise/2025-04-01/redisenterprise/version.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-04-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/redisenterprise/2025-04-01" +} diff --git a/resource-manager/resources/2025-03-01/client.go b/resource-manager/resources/2025-03-01/client.go index 10c026567b4..9c98f07d25f 100644 --- a/resource-manager/resources/2025-03-01/client.go +++ b/resource-manager/resources/2025-03-01/client.go @@ -6,26 +6,50 @@ package v2025_03_01 import ( "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/deploymentoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/deployments" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/policyassignments" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/policydefinitions" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/policydefinitionversions" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/policysetdefinitions" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/policysetdefinitionversions" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/policytokens" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/providers" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/resourcegroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/resources" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/tags" "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { + DeploymentOperations *deploymentoperations.DeploymentOperationsClient + Deployments *deployments.DeploymentsClient PolicyAssignments *policyassignments.PolicyAssignmentsClient PolicyDefinitionVersions *policydefinitionversions.PolicyDefinitionVersionsClient PolicyDefinitions *policydefinitions.PolicyDefinitionsClient PolicySetDefinitionVersions *policysetdefinitionversions.PolicySetDefinitionVersionsClient PolicySetDefinitions *policysetdefinitions.PolicySetDefinitionsClient PolicyTokens *policytokens.PolicyTokensClient + Providers *providers.ProvidersClient + ResourceGroups *resourcegroups.ResourceGroupsClient + Resources *resources.ResourcesClient + Tags *tags.TagsClient } func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + deploymentOperationsClient, err := deploymentoperations.NewDeploymentOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeploymentOperations client: %+v", err) + } + configureFunc(deploymentOperationsClient.Client) + + deploymentsClient, err := deployments.NewDeploymentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Deployments client: %+v", err) + } + configureFunc(deploymentsClient.Client) + policyAssignmentsClient, err := policyassignments.NewPolicyAssignmentsClientWithBaseURI(sdkApi) if err != nil { return nil, fmt.Errorf("building PolicyAssignments client: %+v", err) @@ -62,12 +86,42 @@ func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanag } configureFunc(policyTokensClient.Client) + providersClient, err := providers.NewProvidersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Providers client: %+v", err) + } + configureFunc(providersClient.Client) + + resourceGroupsClient, err := resourcegroups.NewResourceGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ResourceGroups client: %+v", err) + } + configureFunc(resourceGroupsClient.Client) + + resourcesClient, err := resources.NewResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Resources client: %+v", err) + } + configureFunc(resourcesClient.Client) + + tagsClient, err := tags.NewTagsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Tags client: %+v", err) + } + configureFunc(tagsClient.Client) + return &Client{ + DeploymentOperations: deploymentOperationsClient, + Deployments: deploymentsClient, PolicyAssignments: policyAssignmentsClient, PolicyDefinitionVersions: policyDefinitionVersionsClient, PolicyDefinitions: policyDefinitionsClient, PolicySetDefinitionVersions: policySetDefinitionVersionsClient, PolicySetDefinitions: policySetDefinitionsClient, PolicyTokens: policyTokensClient, + Providers: providersClient, + ResourceGroups: resourceGroupsClient, + Resources: resourcesClient, + Tags: tagsClient, }, nil } diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/README.md b/resource-manager/resources/2025-03-01/deploymentoperations/README.md new file mode 100644 index 00000000000..1b1d539f4e2 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/README.md @@ -0,0 +1,185 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/deploymentoperations` Documentation + +The `deploymentoperations` SDK allows for interaction with Azure Resource Manager `resources` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/deploymentoperations" +``` + + +### Client Initialization + +```go +client := deploymentoperations.NewDeploymentOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeploymentOperationsClient.Get` + +```go +ctx := context.TODO() +id := deploymentoperations.NewResourceGroupDeploymentOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName", "operationId") + +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: `DeploymentOperationsClient.GetAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewProviders2DeploymentOperationID("groupId", "deploymentName", "operationId") + +read, err := client.GetAtManagementGroupScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentOperationsClient.GetAtScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewScopedOperationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName", "operationId") + +read, err := client.GetAtScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentOperationsClient.GetAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewDeploymentOperationID("12345678-1234-9876-4563-123456789012", "deploymentName", "operationId") + +read, err := client.GetAtSubscriptionScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentOperationsClient.GetAtTenantScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewOperationID("deploymentName", "operationId") + +read, err := client.GetAtTenantScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentOperationsClient.List` + +```go +ctx := context.TODO() +id := deploymentoperations.NewResourceGroupDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +// alternatively `client.List(ctx, id, deploymentoperations.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, deploymentoperations.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentOperationsClient.ListAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewProviders2DeploymentID("groupId", "deploymentName") + +// alternatively `client.ListAtManagementGroupScope(ctx, id, deploymentoperations.DefaultListAtManagementGroupScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtManagementGroupScopeComplete(ctx, id, deploymentoperations.DefaultListAtManagementGroupScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentOperationsClient.ListAtScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +// alternatively `client.ListAtScope(ctx, id, deploymentoperations.DefaultListAtScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtScopeComplete(ctx, id, deploymentoperations.DefaultListAtScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentOperationsClient.ListAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +// alternatively `client.ListAtSubscriptionScope(ctx, id, deploymentoperations.DefaultListAtSubscriptionScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtSubscriptionScopeComplete(ctx, id, deploymentoperations.DefaultListAtSubscriptionScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentOperationsClient.ListAtTenantScope` + +```go +ctx := context.TODO() +id := deploymentoperations.NewDeploymentID("deploymentName") + +// alternatively `client.ListAtTenantScope(ctx, id, deploymentoperations.DefaultListAtTenantScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtTenantScopeComplete(ctx, id, deploymentoperations.DefaultListAtTenantScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/client.go b/resource-manager/resources/2025-03-01/deploymentoperations/client.go new file mode 100644 index 00000000000..3943f7aa725 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/client.go @@ -0,0 +1,26 @@ +package deploymentoperations + +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 DeploymentOperationsClient struct { + Client *resourcemanager.Client +} + +func NewDeploymentOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*DeploymentOperationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "deploymentoperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeploymentOperationsClient: %+v", err) + } + + return &DeploymentOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/constants.go b/resource-manager/resources/2025-03-01/deploymentoperations/constants.go new file mode 100644 index 00000000000..a39f9ed2431 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/constants.go @@ -0,0 +1,131 @@ +package deploymentoperations + +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 ExtensionConfigPropertyType string + +const ( + ExtensionConfigPropertyTypeArray ExtensionConfigPropertyType = "Array" + ExtensionConfigPropertyTypeBool ExtensionConfigPropertyType = "Bool" + ExtensionConfigPropertyTypeInt ExtensionConfigPropertyType = "Int" + ExtensionConfigPropertyTypeObject ExtensionConfigPropertyType = "Object" + ExtensionConfigPropertyTypeSecureObject ExtensionConfigPropertyType = "SecureObject" + ExtensionConfigPropertyTypeSecureString ExtensionConfigPropertyType = "SecureString" + ExtensionConfigPropertyTypeString ExtensionConfigPropertyType = "String" +) + +func PossibleValuesForExtensionConfigPropertyType() []string { + return []string{ + string(ExtensionConfigPropertyTypeArray), + string(ExtensionConfigPropertyTypeBool), + string(ExtensionConfigPropertyTypeInt), + string(ExtensionConfigPropertyTypeObject), + string(ExtensionConfigPropertyTypeSecureObject), + string(ExtensionConfigPropertyTypeSecureString), + string(ExtensionConfigPropertyTypeString), + } +} + +func (s *ExtensionConfigPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtensionConfigPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtensionConfigPropertyType(input string) (*ExtensionConfigPropertyType, error) { + vals := map[string]ExtensionConfigPropertyType{ + "array": ExtensionConfigPropertyTypeArray, + "bool": ExtensionConfigPropertyTypeBool, + "int": ExtensionConfigPropertyTypeInt, + "object": ExtensionConfigPropertyTypeObject, + "secureobject": ExtensionConfigPropertyTypeSecureObject, + "securestring": ExtensionConfigPropertyTypeSecureString, + "string": ExtensionConfigPropertyTypeString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtensionConfigPropertyType(input) + return &out, nil +} + +type ProvisioningOperation string + +const ( + ProvisioningOperationAction ProvisioningOperation = "Action" + ProvisioningOperationAzureAsyncOperationWaiting ProvisioningOperation = "AzureAsyncOperationWaiting" + ProvisioningOperationCreate ProvisioningOperation = "Create" + ProvisioningOperationDelete ProvisioningOperation = "Delete" + ProvisioningOperationDeploymentCleanup ProvisioningOperation = "DeploymentCleanup" + ProvisioningOperationEvaluateDeploymentOutput ProvisioningOperation = "EvaluateDeploymentOutput" + ProvisioningOperationNotSpecified ProvisioningOperation = "NotSpecified" + ProvisioningOperationRead ProvisioningOperation = "Read" + ProvisioningOperationResourceCacheWaiting ProvisioningOperation = "ResourceCacheWaiting" + ProvisioningOperationWaiting ProvisioningOperation = "Waiting" +) + +func PossibleValuesForProvisioningOperation() []string { + return []string{ + string(ProvisioningOperationAction), + string(ProvisioningOperationAzureAsyncOperationWaiting), + string(ProvisioningOperationCreate), + string(ProvisioningOperationDelete), + string(ProvisioningOperationDeploymentCleanup), + string(ProvisioningOperationEvaluateDeploymentOutput), + string(ProvisioningOperationNotSpecified), + string(ProvisioningOperationRead), + string(ProvisioningOperationResourceCacheWaiting), + string(ProvisioningOperationWaiting), + } +} + +func (s *ProvisioningOperation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningOperation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningOperation(input string) (*ProvisioningOperation, error) { + vals := map[string]ProvisioningOperation{ + "action": ProvisioningOperationAction, + "azureasyncoperationwaiting": ProvisioningOperationAzureAsyncOperationWaiting, + "create": ProvisioningOperationCreate, + "delete": ProvisioningOperationDelete, + "deploymentcleanup": ProvisioningOperationDeploymentCleanup, + "evaluatedeploymentoutput": ProvisioningOperationEvaluateDeploymentOutput, + "notspecified": ProvisioningOperationNotSpecified, + "read": ProvisioningOperationRead, + "resourcecachewaiting": ProvisioningOperationResourceCacheWaiting, + "waiting": ProvisioningOperationWaiting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningOperation(input) + return &out, nil +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_deployment.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_deployment.go new file mode 100644 index 00000000000..f6909aabf21 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_deployment.go @@ -0,0 +1,112 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeploymentId{}) +} + +var _ resourceids.ResourceId = &DeploymentId{} + +// DeploymentId is a struct representing the Resource ID for a Deployment +type DeploymentId struct { + DeploymentName string +} + +// NewDeploymentID returns a new DeploymentId struct +func NewDeploymentID(deploymentName string) DeploymentId { + return DeploymentId{ + DeploymentName: deploymentName, + } +} + +// ParseDeploymentID parses 'input' into a DeploymentId +func ParseDeploymentID(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeploymentIDInsensitively parses 'input' case-insensitively into a DeploymentId +// note: this method should only be used for API response data and not user input +func ParseDeploymentIDInsensitively(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateDeploymentID checks that 'input' can be parsed as a Deployment ID +func ValidateDeploymentID(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 := ParseDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deployment ID +func (id DeploymentId) ID() string { + fmtString := "/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deployment ID +func (id DeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Deployment ID +func (id DeploymentId) String() string { + components := []string{ + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_deployment_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_deployment_test.go new file mode 100644 index 00000000000..e3c7f559838 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_deployment_test.go @@ -0,0 +1,192 @@ +package deploymentoperations + +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 = &DeploymentId{} + +func TestNewDeploymentID(t *testing.T) { + id := NewDeploymentID("deploymentName") + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatDeploymentID(t *testing.T) { + actual := NewDeploymentID("deploymentName").ID() + expected := "/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &DeploymentId{ + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &DeploymentId{ + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &DeploymentId{ + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForDeploymentId(t *testing.T) { + segments := DeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeploymentId 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/resources/2025-03-01/deploymentoperations/id_deploymentoperation.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation.go new file mode 100644 index 00000000000..dc168b253cf --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation.go @@ -0,0 +1,130 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeploymentOperationId{}) +} + +var _ resourceids.ResourceId = &DeploymentOperationId{} + +// DeploymentOperationId is a struct representing the Resource ID for a Deployment Operation +type DeploymentOperationId struct { + SubscriptionId string + DeploymentName string + OperationId string +} + +// NewDeploymentOperationID returns a new DeploymentOperationId struct +func NewDeploymentOperationID(subscriptionId string, deploymentName string, operationId string) DeploymentOperationId { + return DeploymentOperationId{ + SubscriptionId: subscriptionId, + DeploymentName: deploymentName, + OperationId: operationId, + } +} + +// ParseDeploymentOperationID parses 'input' into a DeploymentOperationId +func ParseDeploymentOperationID(input string) (*DeploymentOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentOperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeploymentOperationIDInsensitively parses 'input' case-insensitively into a DeploymentOperationId +// note: this method should only be used for API response data and not user input +func ParseDeploymentOperationIDInsensitively(input string) (*DeploymentOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentOperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeploymentOperationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateDeploymentOperationID checks that 'input' can be parsed as a Deployment Operation ID +func ValidateDeploymentOperationID(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 := ParseDeploymentOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deployment Operation ID +func (id DeploymentOperationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Resources/deployments/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.DeploymentName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deployment Operation ID +func (id DeploymentOperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Deployment Operation ID +func (id DeploymentOperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Deployment Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation_test.go new file mode 100644 index 00000000000..3e017547179 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_deploymentoperation_test.go @@ -0,0 +1,282 @@ +package deploymentoperations + +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 = &DeploymentOperationId{} + +func TestNewDeploymentOperationID(t *testing.T) { + id := NewDeploymentOperationID("12345678-1234-9876-4563-123456789012", "deploymentName", "operationId") + + 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.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatDeploymentOperationID(t *testing.T) { + actual := NewDeploymentOperationID("12345678-1234-9876-4563-123456789012", "deploymentName", "operationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeploymentOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &DeploymentOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentOperationID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseDeploymentOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &DeploymentOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId", + Expected: &DeploymentOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "dEpLoYmEnTnAmE", + OperationId: "oPeRaTiOnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentOperationIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForDeploymentOperationId(t *testing.T) { + segments := DeploymentOperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeploymentOperationId 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/resources/2025-03-01/deploymentoperations/id_operation.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_operation.go new file mode 100644 index 00000000000..236182b7020 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_operation.go @@ -0,0 +1,121 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + DeploymentName string + OperationId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(deploymentName string, operationId string) OperationId { + return OperationId{ + DeploymentName: deploymentName, + OperationId: operationId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(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 := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/providers/Microsoft.Resources/deployments/%s/operations/%s" + return fmt.Sprintf(fmtString, id.DeploymentName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_operation_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_operation_test.go new file mode 100644 index 00000000000..0fb33ee2f5d --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_operation_test.go @@ -0,0 +1,237 @@ +package deploymentoperations + +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 = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("deploymentName", "operationId") + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("deploymentName", "operationId").ID() + expected := "/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &OperationId{ + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &OperationId{ + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId", + Expected: &OperationId{ + DeploymentName: "dEpLoYmEnTnAmE", + OperationId: "oPeRaTiOnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId 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/resources/2025-03-01/deploymentoperations/id_providerdeployment.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment.go new file mode 100644 index 00000000000..f05fa07ab48 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment.go @@ -0,0 +1,121 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderDeploymentId{}) +} + +var _ resourceids.ResourceId = &ProviderDeploymentId{} + +// ProviderDeploymentId is a struct representing the Resource ID for a Provider Deployment +type ProviderDeploymentId struct { + SubscriptionId string + DeploymentName string +} + +// NewProviderDeploymentID returns a new ProviderDeploymentId struct +func NewProviderDeploymentID(subscriptionId string, deploymentName string) ProviderDeploymentId { + return ProviderDeploymentId{ + SubscriptionId: subscriptionId, + DeploymentName: deploymentName, + } +} + +// ParseProviderDeploymentID parses 'input' into a ProviderDeploymentId +func ParseProviderDeploymentID(input string) (*ProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderDeploymentIDInsensitively parses 'input' case-insensitively into a ProviderDeploymentId +// note: this method should only be used for API response data and not user input +func ParseProviderDeploymentIDInsensitively(input string) (*ProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderDeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateProviderDeploymentID checks that 'input' can be parsed as a Provider Deployment ID +func ValidateProviderDeploymentID(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 := ParseProviderDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Deployment ID +func (id ProviderDeploymentId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Deployment ID +func (id ProviderDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Provider Deployment ID +func (id ProviderDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Provider Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment_test.go new file mode 100644 index 00000000000..13f7e4172b2 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_providerdeployment_test.go @@ -0,0 +1,237 @@ +package deploymentoperations + +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 = &ProviderDeploymentId{} + +func TestNewProviderDeploymentID(t *testing.T) { + id := NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + + 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.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatProviderDeploymentID(t *testing.T) { + actual := NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderDeploymentID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseProviderDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderDeploymentIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForProviderDeploymentId(t *testing.T) { + segments := ProviderDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderDeploymentId 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/resources/2025-03-01/deploymentoperations/id_providers2deployment.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment.go new file mode 100644 index 00000000000..8f0e5fe2e67 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment.go @@ -0,0 +1,123 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&Providers2DeploymentId{}) +} + +var _ resourceids.ResourceId = &Providers2DeploymentId{} + +// Providers2DeploymentId is a struct representing the Resource ID for a Providers 2 Deployment +type Providers2DeploymentId struct { + GroupId string + DeploymentName string +} + +// NewProviders2DeploymentID returns a new Providers2DeploymentId struct +func NewProviders2DeploymentID(groupId string, deploymentName string) Providers2DeploymentId { + return Providers2DeploymentId{ + GroupId: groupId, + DeploymentName: deploymentName, + } +} + +// ParseProviders2DeploymentID parses 'input' into a Providers2DeploymentId +func ParseProviders2DeploymentID(input string) (*Providers2DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2DeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviders2DeploymentIDInsensitively parses 'input' case-insensitively into a Providers2DeploymentId +// note: this method should only be used for API response data and not user input +func ParseProviders2DeploymentIDInsensitively(input string) (*Providers2DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2DeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *Providers2DeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateProviders2DeploymentID checks that 'input' can be parsed as a Providers 2 Deployment ID +func ValidateProviders2DeploymentID(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 := ParseProviders2DeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Providers 2 Deployment ID +func (id Providers2DeploymentId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.GroupId, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Providers 2 Deployment ID +func (id Providers2DeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("groupId", "groupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Providers 2 Deployment ID +func (id Providers2DeploymentId) String() string { + components := []string{ + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Providers 2 Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment_test.go new file mode 100644 index 00000000000..55271c7ecc4 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deployment_test.go @@ -0,0 +1,267 @@ +package deploymentoperations + +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 = &Providers2DeploymentId{} + +func TestNewProviders2DeploymentID(t *testing.T) { + id := NewProviders2DeploymentID("groupId", "deploymentName") + + if id.GroupId != "groupId" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupId") + } + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatProviders2DeploymentID(t *testing.T) { + actual := NewProviders2DeploymentID("groupId", "deploymentName").ID() + expected := "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviders2DeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &Providers2DeploymentId{ + GroupId: "groupId", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2DeploymentID(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseProviders2DeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &Providers2DeploymentId{ + GroupId: "groupId", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &Providers2DeploymentId{ + GroupId: "gRoUpId", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2DeploymentIDInsensitively(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForProviders2DeploymentId(t *testing.T) { + segments := Providers2DeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("Providers2DeploymentId 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/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation.go new file mode 100644 index 00000000000..4f6e30046ac --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation.go @@ -0,0 +1,132 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&Providers2DeploymentOperationId{}) +} + +var _ resourceids.ResourceId = &Providers2DeploymentOperationId{} + +// Providers2DeploymentOperationId is a struct representing the Resource ID for a Providers 2 Deployment Operation +type Providers2DeploymentOperationId struct { + GroupId string + DeploymentName string + OperationId string +} + +// NewProviders2DeploymentOperationID returns a new Providers2DeploymentOperationId struct +func NewProviders2DeploymentOperationID(groupId string, deploymentName string, operationId string) Providers2DeploymentOperationId { + return Providers2DeploymentOperationId{ + GroupId: groupId, + DeploymentName: deploymentName, + OperationId: operationId, + } +} + +// ParseProviders2DeploymentOperationID parses 'input' into a Providers2DeploymentOperationId +func ParseProviders2DeploymentOperationID(input string) (*Providers2DeploymentOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2DeploymentOperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2DeploymentOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviders2DeploymentOperationIDInsensitively parses 'input' case-insensitively into a Providers2DeploymentOperationId +// note: this method should only be used for API response data and not user input +func ParseProviders2DeploymentOperationIDInsensitively(input string) (*Providers2DeploymentOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2DeploymentOperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2DeploymentOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *Providers2DeploymentOperationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateProviders2DeploymentOperationID checks that 'input' can be parsed as a Providers 2 Deployment Operation ID +func ValidateProviders2DeploymentOperationID(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 := ParseProviders2DeploymentOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Providers 2 Deployment Operation ID +func (id Providers2DeploymentOperationId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Resources/deployments/%s/operations/%s" + return fmt.Sprintf(fmtString, id.GroupId, id.DeploymentName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Providers 2 Deployment Operation ID +func (id Providers2DeploymentOperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("groupId", "groupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Providers 2 Deployment Operation ID +func (id Providers2DeploymentOperationId) String() string { + components := []string{ + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Providers 2 Deployment Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation_test.go new file mode 100644 index 00000000000..bbbdf54551b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_providers2deploymentoperation_test.go @@ -0,0 +1,312 @@ +package deploymentoperations + +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 = &Providers2DeploymentOperationId{} + +func TestNewProviders2DeploymentOperationID(t *testing.T) { + id := NewProviders2DeploymentOperationID("groupId", "deploymentName", "operationId") + + if id.GroupId != "groupId" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupId") + } + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatProviders2DeploymentOperationID(t *testing.T) { + actual := NewProviders2DeploymentOperationID("groupId", "deploymentName", "operationId").ID() + expected := "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviders2DeploymentOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2DeploymentOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &Providers2DeploymentOperationId{ + GroupId: "groupId", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2DeploymentOperationID(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseProviders2DeploymentOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2DeploymentOperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &Providers2DeploymentOperationId{ + GroupId: "groupId", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId", + Expected: &Providers2DeploymentOperationId{ + GroupId: "gRoUpId", + DeploymentName: "dEpLoYmEnTnAmE", + OperationId: "oPeRaTiOnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2DeploymentOperationIDInsensitively(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForProviders2DeploymentOperationId(t *testing.T) { + segments := Providers2DeploymentOperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("Providers2DeploymentOperationId 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/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment.go new file mode 100644 index 00000000000..c070c534431 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment.go @@ -0,0 +1,128 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResourceGroupDeploymentId{}) +} + +var _ resourceids.ResourceId = &ResourceGroupDeploymentId{} + +// ResourceGroupDeploymentId is a struct representing the Resource ID for a Resource Group Deployment +type ResourceGroupDeploymentId struct { + SubscriptionId string + ResourceGroupName string + DeploymentName string +} + +// NewResourceGroupDeploymentID returns a new ResourceGroupDeploymentId struct +func NewResourceGroupDeploymentID(subscriptionId string, resourceGroupName string, deploymentName string) ResourceGroupDeploymentId { + return ResourceGroupDeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DeploymentName: deploymentName, + } +} + +// ParseResourceGroupDeploymentID parses 'input' into a ResourceGroupDeploymentId +func ParseResourceGroupDeploymentID(input string) (*ResourceGroupDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceGroupDeploymentIDInsensitively parses 'input' case-insensitively into a ResourceGroupDeploymentId +// note: this method should only be used for API response data and not user input +func ParseResourceGroupDeploymentIDInsensitively(input string) (*ResourceGroupDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceGroupDeploymentId) 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.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateResourceGroupDeploymentID checks that 'input' can be parsed as a Resource Group Deployment ID +func ValidateResourceGroupDeploymentID(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 := ParseResourceGroupDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Group Deployment ID +func (id ResourceGroupDeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Group Deployment ID +func (id ResourceGroupDeploymentId) 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("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Resource Group Deployment ID +func (id ResourceGroupDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Resource Group Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment_test.go new file mode 100644 index 00000000000..b49f5dcd9aa --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeployment_test.go @@ -0,0 +1,252 @@ +package deploymentoperations + +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 = &ResourceGroupDeploymentId{} + +func TestNewResourceGroupDeploymentID(t *testing.T) { + id := NewResourceGroupDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + + 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.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatResourceGroupDeploymentID(t *testing.T) { + actual := NewResourceGroupDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceGroupDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupDeploymentId + }{ + { + // 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/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName", + Expected: &ResourceGroupDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupDeploymentID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseResourceGroupDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupDeploymentId + }{ + { + // 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/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName", + Expected: &ResourceGroupDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &ResourceGroupDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupDeploymentIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForResourceGroupDeploymentId(t *testing.T) { + segments := ResourceGroupDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceGroupDeploymentId 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/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation.go new file mode 100644 index 00000000000..660e5a4e889 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation.go @@ -0,0 +1,137 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResourceGroupDeploymentOperationId{}) +} + +var _ resourceids.ResourceId = &ResourceGroupDeploymentOperationId{} + +// ResourceGroupDeploymentOperationId is a struct representing the Resource ID for a Resource Group Deployment Operation +type ResourceGroupDeploymentOperationId struct { + SubscriptionId string + ResourceGroupName string + DeploymentName string + OperationId string +} + +// NewResourceGroupDeploymentOperationID returns a new ResourceGroupDeploymentOperationId struct +func NewResourceGroupDeploymentOperationID(subscriptionId string, resourceGroupName string, deploymentName string, operationId string) ResourceGroupDeploymentOperationId { + return ResourceGroupDeploymentOperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DeploymentName: deploymentName, + OperationId: operationId, + } +} + +// ParseResourceGroupDeploymentOperationID parses 'input' into a ResourceGroupDeploymentOperationId +func ParseResourceGroupDeploymentOperationID(input string) (*ResourceGroupDeploymentOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupDeploymentOperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupDeploymentOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceGroupDeploymentOperationIDInsensitively parses 'input' case-insensitively into a ResourceGroupDeploymentOperationId +// note: this method should only be used for API response data and not user input +func ParseResourceGroupDeploymentOperationIDInsensitively(input string) (*ResourceGroupDeploymentOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupDeploymentOperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupDeploymentOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceGroupDeploymentOperationId) 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.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateResourceGroupDeploymentOperationID checks that 'input' can be parsed as a Resource Group Deployment Operation ID +func ValidateResourceGroupDeploymentOperationID(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 := ParseResourceGroupDeploymentOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Group Deployment Operation ID +func (id ResourceGroupDeploymentOperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/deployments/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DeploymentName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Group Deployment Operation ID +func (id ResourceGroupDeploymentOperationId) 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("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Resource Group Deployment Operation ID +func (id ResourceGroupDeploymentOperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Resource Group Deployment Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation_test.go new file mode 100644 index 00000000000..5cd87417002 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_resourcegroupdeploymentoperation_test.go @@ -0,0 +1,297 @@ +package deploymentoperations + +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 = &ResourceGroupDeploymentOperationId{} + +func TestNewResourceGroupDeploymentOperationID(t *testing.T) { + id := NewResourceGroupDeploymentOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName", "operationId") + + 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.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatResourceGroupDeploymentOperationID(t *testing.T) { + actual := NewResourceGroupDeploymentOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName", "operationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceGroupDeploymentOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupDeploymentOperationId + }{ + { + // 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/deployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations/operationId", + Expected: &ResourceGroupDeploymentOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupDeploymentOperationID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseResourceGroupDeploymentOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupDeploymentOperationId + }{ + { + // 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/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations/operationId", + Expected: &ResourceGroupDeploymentOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId", + Expected: &ResourceGroupDeploymentOperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeploymentName: "dEpLoYmEnTnAmE", + OperationId: "oPeRaTiOnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupDeploymentOperationIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForResourceGroupDeploymentOperationId(t *testing.T) { + segments := ResourceGroupDeploymentOperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceGroupDeploymentOperationId 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/resources/2025-03-01/deploymentoperations/id_scopeddeployment.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment.go new file mode 100644 index 00000000000..66d250f880e --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment.go @@ -0,0 +1,120 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedDeploymentId{}) +} + +var _ resourceids.ResourceId = &ScopedDeploymentId{} + +// ScopedDeploymentId is a struct representing the Resource ID for a Scoped Deployment +type ScopedDeploymentId struct { + Scope string + DeploymentName string +} + +// NewScopedDeploymentID returns a new ScopedDeploymentId struct +func NewScopedDeploymentID(scope string, deploymentName string) ScopedDeploymentId { + return ScopedDeploymentId{ + Scope: scope, + DeploymentName: deploymentName, + } +} + +// ParseScopedDeploymentID parses 'input' into a ScopedDeploymentId +func ParseScopedDeploymentID(input string) (*ScopedDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedDeploymentIDInsensitively parses 'input' case-insensitively into a ScopedDeploymentId +// note: this method should only be used for API response data and not user input +func ParseScopedDeploymentIDInsensitively(input string) (*ScopedDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedDeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateScopedDeploymentID checks that 'input' can be parsed as a Scoped Deployment ID +func ValidateScopedDeploymentID(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 := ParseScopedDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Deployment ID +func (id ScopedDeploymentId) ID() string { + fmtString := "/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Deployment ID +func (id ScopedDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Scoped Deployment ID +func (id ScopedDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Scoped Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment_test.go new file mode 100644 index 00000000000..b12dbcd14ff --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopeddeployment_test.go @@ -0,0 +1,222 @@ +package deploymentoperations + +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 = &ScopedDeploymentId{} + +func TestNewScopedDeploymentID(t *testing.T) { + id := NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatScopedDeploymentID(t *testing.T) { + actual := NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedDeploymentId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ScopedDeploymentId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseScopedDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedDeploymentId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ScopedDeploymentId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &ScopedDeploymentId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // 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.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForScopedDeploymentId(t *testing.T) { + segments := ScopedDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedDeploymentId 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/resources/2025-03-01/deploymentoperations/id_scopedoperation.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation.go new file mode 100644 index 00000000000..0b343215686 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation.go @@ -0,0 +1,129 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedOperationId{}) +} + +var _ resourceids.ResourceId = &ScopedOperationId{} + +// ScopedOperationId is a struct representing the Resource ID for a Scoped Operation +type ScopedOperationId struct { + Scope string + DeploymentName string + OperationId string +} + +// NewScopedOperationID returns a new ScopedOperationId struct +func NewScopedOperationID(scope string, deploymentName string, operationId string) ScopedOperationId { + return ScopedOperationId{ + Scope: scope, + DeploymentName: deploymentName, + OperationId: operationId, + } +} + +// ParseScopedOperationID parses 'input' into a ScopedOperationId +func ParseScopedOperationID(input string) (*ScopedOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedOperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedOperationIDInsensitively parses 'input' case-insensitively into a ScopedOperationId +// note: this method should only be used for API response data and not user input +func ParseScopedOperationIDInsensitively(input string) (*ScopedOperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedOperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedOperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedOperationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateScopedOperationID checks that 'input' can be parsed as a Scoped Operation ID +func ValidateScopedOperationID(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 := ParseScopedOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Operation ID +func (id ScopedOperationId) ID() string { + fmtString := "/%s/providers/Microsoft.Resources/deployments/%s/operations/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.DeploymentName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Operation ID +func (id ScopedOperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Scoped Operation ID +func (id ScopedOperationId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Scoped Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation_test.go b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation_test.go new file mode 100644 index 00000000000..b296f291306 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/id_scopedoperation_test.go @@ -0,0 +1,267 @@ +package deploymentoperations + +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 = &ScopedOperationId{} + +func TestNewScopedOperationID(t *testing.T) { + id := NewScopedOperationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName", "operationId") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatScopedOperationID(t *testing.T) { + actual := NewScopedOperationID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName", "operationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedOperationId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &ScopedOperationId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseScopedOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedOperationId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId", + Expected: &ScopedOperationId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + DeploymentName: "deploymentName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId", + Expected: &ScopedOperationId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + DeploymentName: "dEpLoYmEnTnAmE", + OperationId: "oPeRaTiOnId", + }, + }, + { + // 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.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForScopedOperationId(t *testing.T) { + segments := ScopedOperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedOperationId 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/resources/2025-03-01/deploymentoperations/method_get.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_get.go new file mode 100644 index 00000000000..df47d1fffdc --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_get.go @@ -0,0 +1,53 @@ +package deploymentoperations + +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 *DeploymentOperation +} + +// Get ... +func (c DeploymentOperationsClient) Get(ctx context.Context, id ResourceGroupDeploymentOperationId) (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 DeploymentOperation + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_getatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_getatmanagementgroupscope.go new file mode 100644 index 00000000000..fcff3ccc385 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_getatmanagementgroupscope.go @@ -0,0 +1,53 @@ +package deploymentoperations + +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 GetAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentOperation +} + +// GetAtManagementGroupScope ... +func (c DeploymentOperationsClient) GetAtManagementGroupScope(ctx context.Context, id Providers2DeploymentOperationId) (result GetAtManagementGroupScopeOperationResponse, 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 DeploymentOperation + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_getatscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_getatscope.go new file mode 100644 index 00000000000..cdacd32c8ce --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_getatscope.go @@ -0,0 +1,53 @@ +package deploymentoperations + +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 GetAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentOperation +} + +// GetAtScope ... +func (c DeploymentOperationsClient) GetAtScope(ctx context.Context, id ScopedOperationId) (result GetAtScopeOperationResponse, 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 DeploymentOperation + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_getatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_getatsubscriptionscope.go new file mode 100644 index 00000000000..3182049acbb --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_getatsubscriptionscope.go @@ -0,0 +1,53 @@ +package deploymentoperations + +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 GetAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentOperation +} + +// GetAtSubscriptionScope ... +func (c DeploymentOperationsClient) GetAtSubscriptionScope(ctx context.Context, id DeploymentOperationId) (result GetAtSubscriptionScopeOperationResponse, 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 DeploymentOperation + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_getattenantscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_getattenantscope.go new file mode 100644 index 00000000000..be3409b87cc --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_getattenantscope.go @@ -0,0 +1,53 @@ +package deploymentoperations + +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 GetAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentOperation +} + +// GetAtTenantScope ... +func (c DeploymentOperationsClient) GetAtTenantScope(ctx context.Context, id OperationId) (result GetAtTenantScopeOperationResponse, 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 DeploymentOperation + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_list.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_list.go new file mode 100644 index 00000000000..5f009bc0e62 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_list.go @@ -0,0 +1,134 @@ +package deploymentoperations + +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 *[]DeploymentOperation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentOperation +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c DeploymentOperationsClient) List(ctx context.Context, id ResourceGroupDeploymentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]DeploymentOperation `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 DeploymentOperationsClient) ListComplete(ctx context.Context, id ResourceGroupDeploymentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, DeploymentOperationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentOperationsClient) ListCompleteMatchingPredicate(ctx context.Context, id ResourceGroupDeploymentId, options ListOperationOptions, predicate DeploymentOperationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DeploymentOperation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_listatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_listatmanagementgroupscope.go new file mode 100644 index 00000000000..4cf1c58a63a --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_listatmanagementgroupscope.go @@ -0,0 +1,134 @@ +package deploymentoperations + +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 ListAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentOperation +} + +type ListAtManagementGroupScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentOperation +} + +type ListAtManagementGroupScopeOperationOptions struct { + Top *int64 +} + +func DefaultListAtManagementGroupScopeOperationOptions() ListAtManagementGroupScopeOperationOptions { + return ListAtManagementGroupScopeOperationOptions{} +} + +func (o ListAtManagementGroupScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtManagementGroupScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtManagementGroupScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtManagementGroupScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtManagementGroupScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtManagementGroupScope ... +func (c DeploymentOperationsClient) ListAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId, options ListAtManagementGroupScopeOperationOptions) (result ListAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtManagementGroupScopeCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]DeploymentOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtManagementGroupScopeComplete retrieves all the results into a single object +func (c DeploymentOperationsClient) ListAtManagementGroupScopeComplete(ctx context.Context, id Providers2DeploymentId, options ListAtManagementGroupScopeOperationOptions) (ListAtManagementGroupScopeCompleteResult, error) { + return c.ListAtManagementGroupScopeCompleteMatchingPredicate(ctx, id, options, DeploymentOperationOperationPredicate{}) +} + +// ListAtManagementGroupScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentOperationsClient) ListAtManagementGroupScopeCompleteMatchingPredicate(ctx context.Context, id Providers2DeploymentId, options ListAtManagementGroupScopeOperationOptions, predicate DeploymentOperationOperationPredicate) (result ListAtManagementGroupScopeCompleteResult, err error) { + items := make([]DeploymentOperation, 0) + + resp, err := c.ListAtManagementGroupScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtManagementGroupScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_listatscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_listatscope.go new file mode 100644 index 00000000000..f9b99167f0c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_listatscope.go @@ -0,0 +1,134 @@ +package deploymentoperations + +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 ListAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentOperation +} + +type ListAtScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentOperation +} + +type ListAtScopeOperationOptions struct { + Top *int64 +} + +func DefaultListAtScopeOperationOptions() ListAtScopeOperationOptions { + return ListAtScopeOperationOptions{} +} + +func (o ListAtScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtScope ... +func (c DeploymentOperationsClient) ListAtScope(ctx context.Context, id ScopedDeploymentId, options ListAtScopeOperationOptions) (result ListAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtScopeCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]DeploymentOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtScopeComplete retrieves all the results into a single object +func (c DeploymentOperationsClient) ListAtScopeComplete(ctx context.Context, id ScopedDeploymentId, options ListAtScopeOperationOptions) (ListAtScopeCompleteResult, error) { + return c.ListAtScopeCompleteMatchingPredicate(ctx, id, options, DeploymentOperationOperationPredicate{}) +} + +// ListAtScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentOperationsClient) ListAtScopeCompleteMatchingPredicate(ctx context.Context, id ScopedDeploymentId, options ListAtScopeOperationOptions, predicate DeploymentOperationOperationPredicate) (result ListAtScopeCompleteResult, err error) { + items := make([]DeploymentOperation, 0) + + resp, err := c.ListAtScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_listatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_listatsubscriptionscope.go new file mode 100644 index 00000000000..1465515c921 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_listatsubscriptionscope.go @@ -0,0 +1,134 @@ +package deploymentoperations + +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 ListAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentOperation +} + +type ListAtSubscriptionScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentOperation +} + +type ListAtSubscriptionScopeOperationOptions struct { + Top *int64 +} + +func DefaultListAtSubscriptionScopeOperationOptions() ListAtSubscriptionScopeOperationOptions { + return ListAtSubscriptionScopeOperationOptions{} +} + +func (o ListAtSubscriptionScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtSubscriptionScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtSubscriptionScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtSubscriptionScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtSubscriptionScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtSubscriptionScope ... +func (c DeploymentOperationsClient) ListAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId, options ListAtSubscriptionScopeOperationOptions) (result ListAtSubscriptionScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtSubscriptionScopeCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]DeploymentOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtSubscriptionScopeComplete retrieves all the results into a single object +func (c DeploymentOperationsClient) ListAtSubscriptionScopeComplete(ctx context.Context, id ProviderDeploymentId, options ListAtSubscriptionScopeOperationOptions) (ListAtSubscriptionScopeCompleteResult, error) { + return c.ListAtSubscriptionScopeCompleteMatchingPredicate(ctx, id, options, DeploymentOperationOperationPredicate{}) +} + +// ListAtSubscriptionScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentOperationsClient) ListAtSubscriptionScopeCompleteMatchingPredicate(ctx context.Context, id ProviderDeploymentId, options ListAtSubscriptionScopeOperationOptions, predicate DeploymentOperationOperationPredicate) (result ListAtSubscriptionScopeCompleteResult, err error) { + items := make([]DeploymentOperation, 0) + + resp, err := c.ListAtSubscriptionScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtSubscriptionScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/method_listattenantscope.go b/resource-manager/resources/2025-03-01/deploymentoperations/method_listattenantscope.go new file mode 100644 index 00000000000..e9a41bc9f54 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/method_listattenantscope.go @@ -0,0 +1,134 @@ +package deploymentoperations + +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 ListAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentOperation +} + +type ListAtTenantScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentOperation +} + +type ListAtTenantScopeOperationOptions struct { + Top *int64 +} + +func DefaultListAtTenantScopeOperationOptions() ListAtTenantScopeOperationOptions { + return ListAtTenantScopeOperationOptions{} +} + +func (o ListAtTenantScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtTenantScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtTenantScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtTenantScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtTenantScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtTenantScope ... +func (c DeploymentOperationsClient) ListAtTenantScope(ctx context.Context, id DeploymentId, options ListAtTenantScopeOperationOptions) (result ListAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtTenantScopeCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]DeploymentOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtTenantScopeComplete retrieves all the results into a single object +func (c DeploymentOperationsClient) ListAtTenantScopeComplete(ctx context.Context, id DeploymentId, options ListAtTenantScopeOperationOptions) (ListAtTenantScopeCompleteResult, error) { + return c.ListAtTenantScopeCompleteMatchingPredicate(ctx, id, options, DeploymentOperationOperationPredicate{}) +} + +// ListAtTenantScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentOperationsClient) ListAtTenantScopeCompleteMatchingPredicate(ctx context.Context, id DeploymentId, options ListAtTenantScopeOperationOptions, predicate DeploymentOperationOperationPredicate) (result ListAtTenantScopeCompleteResult, err error) { + items := make([]DeploymentOperation, 0) + + resp, err := c.ListAtTenantScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtTenantScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensionconfigitem.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensionconfigitem.go new file mode 100644 index 00000000000..1c6021ca489 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensionconfigitem.go @@ -0,0 +1,10 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtensionConfigItem struct { + KeyVaultReference *KeyVaultParameterReference `json:"keyVaultReference,omitempty"` + Type *ExtensionConfigPropertyType `json:"type,omitempty"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensiondefinition.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensiondefinition.go new file mode 100644 index 00000000000..de28dd2f838 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentextensiondefinition.go @@ -0,0 +1,12 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtensionDefinition struct { + Alias *string `json:"alias,omitempty"` + Config *map[string]DeploymentExtensionConfigItem `json:"config,omitempty"` + ConfigId *string `json:"configId,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperation.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperation.go new file mode 100644 index 00000000000..14a37660832 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperation.go @@ -0,0 +1,10 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentOperation struct { + Id *string `json:"id,omitempty"` + OperationId *string `json:"operationId,omitempty"` + Properties *DeploymentOperationProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperationproperties.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperationproperties.go new file mode 100644 index 00000000000..3266ffd1b6a --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_deploymentoperationproperties.go @@ -0,0 +1,35 @@ +package deploymentoperations + +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 DeploymentOperationProperties struct { + Duration *string `json:"duration,omitempty"` + ProvisioningOperation *ProvisioningOperation `json:"provisioningOperation,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Request *HTTPMessage `json:"request,omitempty"` + Response *HTTPMessage `json:"response,omitempty"` + ServiceRequestId *string `json:"serviceRequestId,omitempty"` + StatusCode *string `json:"statusCode,omitempty"` + StatusMessage *StatusMessage `json:"statusMessage,omitempty"` + TargetResource *TargetResource `json:"targetResource,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *DeploymentOperationProperties) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeploymentOperationProperties) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_erroradditionalinfo.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_erroradditionalinfo.go new file mode 100644 index 00000000000..871d290bf38 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_errorresponse.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_errorresponse.go new file mode 100644 index 00000000000..c092c8e0695 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_errorresponse.go @@ -0,0 +1,12 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorResponse struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorResponse `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_httpmessage.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_httpmessage.go new file mode 100644 index 00000000000..9a7c490a29f --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_httpmessage.go @@ -0,0 +1,8 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HTTPMessage struct { + Content *interface{} `json:"content,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultparameterreference.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultparameterreference.go new file mode 100644 index 00000000000..f58e4e60967 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultparameterreference.go @@ -0,0 +1,10 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultParameterReference struct { + KeyVault KeyVaultReference `json:"keyVault"` + SecretName string `json:"secretName"` + SecretVersion *string `json:"secretVersion,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultreference.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultreference.go new file mode 100644 index 00000000000..451c7944bf3 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_keyvaultreference.go @@ -0,0 +1,8 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultReference struct { + Id string `json:"id"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_statusmessage.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_statusmessage.go new file mode 100644 index 00000000000..54cb94cfb4e --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_statusmessage.go @@ -0,0 +1,9 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StatusMessage struct { + Error *ErrorResponse `json:"error,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/model_targetresource.go b/resource-manager/resources/2025-03-01/deploymentoperations/model_targetresource.go new file mode 100644 index 00000000000..cddd9d20920 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/model_targetresource.go @@ -0,0 +1,14 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetResource struct { + ApiVersion *string `json:"apiVersion,omitempty"` + Extension *DeploymentExtensionDefinition `json:"extension,omitempty"` + Id *string `json:"id,omitempty"` + Identifiers *interface{} `json:"identifiers,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + SymbolicName *string `json:"symbolicName,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/predicates.go b/resource-manager/resources/2025-03-01/deploymentoperations/predicates.go new file mode 100644 index 00000000000..8481a87fa68 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/predicates.go @@ -0,0 +1,22 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentOperationOperationPredicate struct { + Id *string + OperationId *string +} + +func (p DeploymentOperationOperationPredicate) Matches(input DeploymentOperation) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.OperationId != nil && (input.OperationId == nil || *p.OperationId != *input.OperationId) { + return false + } + + return true +} diff --git a/resource-manager/resources/2025-03-01/deploymentoperations/version.go b/resource-manager/resources/2025-03-01/deploymentoperations/version.go new file mode 100644 index 00000000000..4ebb9521768 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deploymentoperations/version.go @@ -0,0 +1,10 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/deploymentoperations/2025-03-01" +} diff --git a/resource-manager/resources/2025-03-01/deployments/README.md b/resource-manager/resources/2025-03-01/deployments/README.md new file mode 100644 index 00000000000..87f0eae41e0 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/README.md @@ -0,0 +1,740 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/deployments` Documentation + +The `deployments` SDK allows for interaction with Azure Resource Manager `resources` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/deployments" +``` + + +### Client Initialization + +```go +client := deployments.NewDeploymentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeploymentsClient.CalculateTemplateHash` + +```go +ctx := context.TODO() +var payload interface{} + +read, err := client.CalculateTemplateHash(ctx, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.Cancel` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +read, err := client.Cancel(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CancelAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +read, err := client.CancelAtManagementGroupScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CancelAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +read, err := client.CancelAtScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CancelAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +read, err := client.CancelAtSubscriptionScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CancelAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +read, err := client.CancelAtTenantScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CheckExistence` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +read, err := client.CheckExistence(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CheckExistenceAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +read, err := client.CheckExistenceAtManagementGroupScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CheckExistenceAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +read, err := client.CheckExistenceAtScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CheckExistenceAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +read, err := client.CheckExistenceAtSubscriptionScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CheckExistenceAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +read, err := client.CheckExistenceAtTenantScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdateAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +payload := deployments.ScopedDeployment{ + // ... +} + + +if err := client.CreateOrUpdateAtManagementGroupScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdateAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.CreateOrUpdateAtScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdateAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.CreateOrUpdateAtSubscriptionScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdateAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +payload := deployments.ScopedDeployment{ + // ... +} + + +if err := client.CreateOrUpdateAtTenantScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.Delete` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.DeleteAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +if err := client.DeleteAtManagementGroupScopeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.DeleteAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +if err := client.DeleteAtScopeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.DeleteAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +if err := client.DeleteAtSubscriptionScopeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.DeleteAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +if err := client.DeleteAtTenantScopeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.ExportTemplate` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +read, err := client.ExportTemplate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.ExportTemplateAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +read, err := client.ExportTemplateAtManagementGroupScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.ExportTemplateAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +read, err := client.ExportTemplateAtScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.ExportTemplateAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +read, err := client.ExportTemplateAtSubscriptionScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.ExportTemplateAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +read, err := client.ExportTemplateAtTenantScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.Get` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +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: `DeploymentsClient.GetAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +read, err := client.GetAtManagementGroupScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.GetAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +read, err := client.GetAtScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.GetAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +read, err := client.GetAtSubscriptionScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.GetAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +read, err := client.GetAtTenantScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.ListAtManagementGroupScope` + +```go +ctx := context.TODO() +id := commonids.NewManagementGroupID("groupId") + +// alternatively `client.ListAtManagementGroupScope(ctx, id, deployments.DefaultListAtManagementGroupScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtManagementGroupScopeComplete(ctx, id, deployments.DefaultListAtManagementGroupScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.ListAtScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListAtScope(ctx, id, deployments.DefaultListAtScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtScopeComplete(ctx, id, deployments.DefaultListAtScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.ListAtSubscriptionScope` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListAtSubscriptionScope(ctx, id, deployments.DefaultListAtSubscriptionScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtSubscriptionScopeComplete(ctx, id, deployments.DefaultListAtSubscriptionScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.ListAtTenantScope` + +```go +ctx := context.TODO() + + +// alternatively `client.ListAtTenantScope(ctx, deployments.DefaultListAtTenantScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtTenantScopeComplete(ctx, deployments.DefaultListAtTenantScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, deployments.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, deployments.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.Validate` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.ValidateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.ValidateAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +payload := deployments.ScopedDeployment{ + // ... +} + + +if err := client.ValidateAtManagementGroupScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.ValidateAtScope` + +```go +ctx := context.TODO() +id := deployments.NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.ValidateAtScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.ValidateAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.ValidateAtSubscriptionScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.ValidateAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +payload := deployments.ScopedDeployment{ + // ... +} + + +if err := client.ValidateAtTenantScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.WhatIf` + +```go +ctx := context.TODO() +id := deployments.NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + +payload := deployments.DeploymentWhatIf{ + // ... +} + + +if err := client.WhatIfThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.WhatIfAtManagementGroupScope` + +```go +ctx := context.TODO() +id := deployments.NewProviders2DeploymentID("groupId", "deploymentName") + +payload := deployments.ScopedDeploymentWhatIf{ + // ... +} + + +if err := client.WhatIfAtManagementGroupScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.WhatIfAtSubscriptionScope` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + +payload := deployments.DeploymentWhatIf{ + // ... +} + + +if err := client.WhatIfAtSubscriptionScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.WhatIfAtTenantScope` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("deploymentName") + +payload := deployments.ScopedDeploymentWhatIf{ + // ... +} + + +if err := client.WhatIfAtTenantScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/resources/2025-03-01/deployments/client.go b/resource-manager/resources/2025-03-01/deployments/client.go new file mode 100644 index 00000000000..a0f7b24cdd0 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/client.go @@ -0,0 +1,26 @@ +package deployments + +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 DeploymentsClient struct { + Client *resourcemanager.Client +} + +func NewDeploymentsClientWithBaseURI(sdkApi sdkEnv.Api) (*DeploymentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "deployments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeploymentsClient: %+v", err) + } + + return &DeploymentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/constants.go b/resource-manager/resources/2025-03-01/deployments/constants.go new file mode 100644 index 00000000000..ce87a511003 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/constants.go @@ -0,0 +1,730 @@ +package deployments + +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 AliasPathAttributes string + +const ( + AliasPathAttributesModifiable AliasPathAttributes = "Modifiable" + AliasPathAttributesNone AliasPathAttributes = "None" +) + +func PossibleValuesForAliasPathAttributes() []string { + return []string{ + string(AliasPathAttributesModifiable), + string(AliasPathAttributesNone), + } +} + +func (s *AliasPathAttributes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasPathAttributes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasPathAttributes(input string) (*AliasPathAttributes, error) { + vals := map[string]AliasPathAttributes{ + "modifiable": AliasPathAttributesModifiable, + "none": AliasPathAttributesNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasPathAttributes(input) + return &out, nil +} + +type AliasPathTokenType string + +const ( + AliasPathTokenTypeAny AliasPathTokenType = "Any" + AliasPathTokenTypeArray AliasPathTokenType = "Array" + AliasPathTokenTypeBoolean AliasPathTokenType = "Boolean" + AliasPathTokenTypeInteger AliasPathTokenType = "Integer" + AliasPathTokenTypeNotSpecified AliasPathTokenType = "NotSpecified" + AliasPathTokenTypeNumber AliasPathTokenType = "Number" + AliasPathTokenTypeObject AliasPathTokenType = "Object" + AliasPathTokenTypeString AliasPathTokenType = "String" +) + +func PossibleValuesForAliasPathTokenType() []string { + return []string{ + string(AliasPathTokenTypeAny), + string(AliasPathTokenTypeArray), + string(AliasPathTokenTypeBoolean), + string(AliasPathTokenTypeInteger), + string(AliasPathTokenTypeNotSpecified), + string(AliasPathTokenTypeNumber), + string(AliasPathTokenTypeObject), + string(AliasPathTokenTypeString), + } +} + +func (s *AliasPathTokenType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasPathTokenType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasPathTokenType(input string) (*AliasPathTokenType, error) { + vals := map[string]AliasPathTokenType{ + "any": AliasPathTokenTypeAny, + "array": AliasPathTokenTypeArray, + "boolean": AliasPathTokenTypeBoolean, + "integer": AliasPathTokenTypeInteger, + "notspecified": AliasPathTokenTypeNotSpecified, + "number": AliasPathTokenTypeNumber, + "object": AliasPathTokenTypeObject, + "string": AliasPathTokenTypeString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasPathTokenType(input) + return &out, nil +} + +type AliasPatternType string + +const ( + AliasPatternTypeExtract AliasPatternType = "Extract" + AliasPatternTypeNotSpecified AliasPatternType = "NotSpecified" +) + +func PossibleValuesForAliasPatternType() []string { + return []string{ + string(AliasPatternTypeExtract), + string(AliasPatternTypeNotSpecified), + } +} + +func (s *AliasPatternType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasPatternType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasPatternType(input string) (*AliasPatternType, error) { + vals := map[string]AliasPatternType{ + "extract": AliasPatternTypeExtract, + "notspecified": AliasPatternTypeNotSpecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasPatternType(input) + return &out, nil +} + +type AliasType string + +const ( + AliasTypeMask AliasType = "Mask" + AliasTypeNotSpecified AliasType = "NotSpecified" + AliasTypePlainText AliasType = "PlainText" +) + +func PossibleValuesForAliasType() []string { + return []string{ + string(AliasTypeMask), + string(AliasTypeNotSpecified), + string(AliasTypePlainText), + } +} + +func (s *AliasType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasType(input string) (*AliasType, error) { + vals := map[string]AliasType{ + "mask": AliasTypeMask, + "notspecified": AliasTypeNotSpecified, + "plaintext": AliasTypePlainText, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasType(input) + return &out, nil +} + +type ChangeType string + +const ( + ChangeTypeCreate ChangeType = "Create" + ChangeTypeDelete ChangeType = "Delete" + ChangeTypeDeploy ChangeType = "Deploy" + ChangeTypeIgnore ChangeType = "Ignore" + ChangeTypeModify ChangeType = "Modify" + ChangeTypeNoChange ChangeType = "NoChange" + ChangeTypeUnsupported ChangeType = "Unsupported" +) + +func PossibleValuesForChangeType() []string { + return []string{ + string(ChangeTypeCreate), + string(ChangeTypeDelete), + string(ChangeTypeDeploy), + string(ChangeTypeIgnore), + string(ChangeTypeModify), + string(ChangeTypeNoChange), + string(ChangeTypeUnsupported), + } +} + +func (s *ChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseChangeType(input string) (*ChangeType, error) { + vals := map[string]ChangeType{ + "create": ChangeTypeCreate, + "delete": ChangeTypeDelete, + "deploy": ChangeTypeDeploy, + "ignore": ChangeTypeIgnore, + "modify": ChangeTypeModify, + "nochange": ChangeTypeNoChange, + "unsupported": ChangeTypeUnsupported, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ChangeType(input) + return &out, nil +} + +type DeploymentMode string + +const ( + DeploymentModeComplete DeploymentMode = "Complete" + DeploymentModeIncremental DeploymentMode = "Incremental" +) + +func PossibleValuesForDeploymentMode() []string { + return []string{ + string(DeploymentModeComplete), + string(DeploymentModeIncremental), + } +} + +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{ + "complete": DeploymentModeComplete, + "incremental": DeploymentModeIncremental, + } + 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 ExpressionEvaluationOptionsScopeType string + +const ( + ExpressionEvaluationOptionsScopeTypeInner ExpressionEvaluationOptionsScopeType = "Inner" + ExpressionEvaluationOptionsScopeTypeNotSpecified ExpressionEvaluationOptionsScopeType = "NotSpecified" + ExpressionEvaluationOptionsScopeTypeOuter ExpressionEvaluationOptionsScopeType = "Outer" +) + +func PossibleValuesForExpressionEvaluationOptionsScopeType() []string { + return []string{ + string(ExpressionEvaluationOptionsScopeTypeInner), + string(ExpressionEvaluationOptionsScopeTypeNotSpecified), + string(ExpressionEvaluationOptionsScopeTypeOuter), + } +} + +func (s *ExpressionEvaluationOptionsScopeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExpressionEvaluationOptionsScopeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExpressionEvaluationOptionsScopeType(input string) (*ExpressionEvaluationOptionsScopeType, error) { + vals := map[string]ExpressionEvaluationOptionsScopeType{ + "inner": ExpressionEvaluationOptionsScopeTypeInner, + "notspecified": ExpressionEvaluationOptionsScopeTypeNotSpecified, + "outer": ExpressionEvaluationOptionsScopeTypeOuter, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExpressionEvaluationOptionsScopeType(input) + return &out, nil +} + +type ExtensionConfigPropertyType string + +const ( + ExtensionConfigPropertyTypeArray ExtensionConfigPropertyType = "Array" + ExtensionConfigPropertyTypeBool ExtensionConfigPropertyType = "Bool" + ExtensionConfigPropertyTypeInt ExtensionConfigPropertyType = "Int" + ExtensionConfigPropertyTypeObject ExtensionConfigPropertyType = "Object" + ExtensionConfigPropertyTypeSecureObject ExtensionConfigPropertyType = "SecureObject" + ExtensionConfigPropertyTypeSecureString ExtensionConfigPropertyType = "SecureString" + ExtensionConfigPropertyTypeString ExtensionConfigPropertyType = "String" +) + +func PossibleValuesForExtensionConfigPropertyType() []string { + return []string{ + string(ExtensionConfigPropertyTypeArray), + string(ExtensionConfigPropertyTypeBool), + string(ExtensionConfigPropertyTypeInt), + string(ExtensionConfigPropertyTypeObject), + string(ExtensionConfigPropertyTypeSecureObject), + string(ExtensionConfigPropertyTypeSecureString), + string(ExtensionConfigPropertyTypeString), + } +} + +func (s *ExtensionConfigPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExtensionConfigPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExtensionConfigPropertyType(input string) (*ExtensionConfigPropertyType, error) { + vals := map[string]ExtensionConfigPropertyType{ + "array": ExtensionConfigPropertyTypeArray, + "bool": ExtensionConfigPropertyTypeBool, + "int": ExtensionConfigPropertyTypeInt, + "object": ExtensionConfigPropertyTypeObject, + "secureobject": ExtensionConfigPropertyTypeSecureObject, + "securestring": ExtensionConfigPropertyTypeSecureString, + "string": ExtensionConfigPropertyTypeString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExtensionConfigPropertyType(input) + return &out, nil +} + +type Level string + +const ( + LevelError Level = "Error" + LevelInfo Level = "Info" + LevelWarning Level = "Warning" +) + +func PossibleValuesForLevel() []string { + return []string{ + string(LevelError), + string(LevelInfo), + string(LevelWarning), + } +} + +func (s *Level) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLevel(input string) (*Level, error) { + vals := map[string]Level{ + "error": LevelError, + "info": LevelInfo, + "warning": LevelWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Level(input) + return &out, nil +} + +type OnErrorDeploymentType string + +const ( + OnErrorDeploymentTypeLastSuccessful OnErrorDeploymentType = "LastSuccessful" + OnErrorDeploymentTypeSpecificDeployment OnErrorDeploymentType = "SpecificDeployment" +) + +func PossibleValuesForOnErrorDeploymentType() []string { + return []string{ + string(OnErrorDeploymentTypeLastSuccessful), + string(OnErrorDeploymentTypeSpecificDeployment), + } +} + +func (s *OnErrorDeploymentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOnErrorDeploymentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOnErrorDeploymentType(input string) (*OnErrorDeploymentType, error) { + vals := map[string]OnErrorDeploymentType{ + "lastsuccessful": OnErrorDeploymentTypeLastSuccessful, + "specificdeployment": OnErrorDeploymentTypeSpecificDeployment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OnErrorDeploymentType(input) + return &out, nil +} + +type PropertyChangeType string + +const ( + PropertyChangeTypeArray PropertyChangeType = "Array" + PropertyChangeTypeCreate PropertyChangeType = "Create" + PropertyChangeTypeDelete PropertyChangeType = "Delete" + PropertyChangeTypeModify PropertyChangeType = "Modify" + PropertyChangeTypeNoEffect PropertyChangeType = "NoEffect" +) + +func PossibleValuesForPropertyChangeType() []string { + return []string{ + string(PropertyChangeTypeArray), + string(PropertyChangeTypeCreate), + string(PropertyChangeTypeDelete), + string(PropertyChangeTypeModify), + string(PropertyChangeTypeNoEffect), + } +} + +func (s *PropertyChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePropertyChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePropertyChangeType(input string) (*PropertyChangeType, error) { + vals := map[string]PropertyChangeType{ + "array": PropertyChangeTypeArray, + "create": PropertyChangeTypeCreate, + "delete": PropertyChangeTypeDelete, + "modify": PropertyChangeTypeModify, + "noeffect": PropertyChangeTypeNoEffect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PropertyChangeType(input) + return &out, nil +} + +type ProviderAuthorizationConsentState string + +const ( + ProviderAuthorizationConsentStateConsented ProviderAuthorizationConsentState = "Consented" + ProviderAuthorizationConsentStateNotRequired ProviderAuthorizationConsentState = "NotRequired" + ProviderAuthorizationConsentStateNotSpecified ProviderAuthorizationConsentState = "NotSpecified" + ProviderAuthorizationConsentStateRequired ProviderAuthorizationConsentState = "Required" +) + +func PossibleValuesForProviderAuthorizationConsentState() []string { + return []string{ + string(ProviderAuthorizationConsentStateConsented), + string(ProviderAuthorizationConsentStateNotRequired), + string(ProviderAuthorizationConsentStateNotSpecified), + string(ProviderAuthorizationConsentStateRequired), + } +} + +func (s *ProviderAuthorizationConsentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProviderAuthorizationConsentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProviderAuthorizationConsentState(input string) (*ProviderAuthorizationConsentState, error) { + vals := map[string]ProviderAuthorizationConsentState{ + "consented": ProviderAuthorizationConsentStateConsented, + "notrequired": ProviderAuthorizationConsentStateNotRequired, + "notspecified": ProviderAuthorizationConsentStateNotSpecified, + "required": ProviderAuthorizationConsentStateRequired, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProviderAuthorizationConsentState(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateReady ProvisioningState = "Ready" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateReady), + string(ProvisioningStateRunning), + 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, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "ready": ProvisioningStateReady, + "running": ProvisioningStateRunning, + "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 ValidationLevel string + +const ( + ValidationLevelProvider ValidationLevel = "Provider" + ValidationLevelProviderNoRbac ValidationLevel = "ProviderNoRbac" + ValidationLevelTemplate ValidationLevel = "Template" +) + +func PossibleValuesForValidationLevel() []string { + return []string{ + string(ValidationLevelProvider), + string(ValidationLevelProviderNoRbac), + string(ValidationLevelTemplate), + } +} + +func (s *ValidationLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseValidationLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseValidationLevel(input string) (*ValidationLevel, error) { + vals := map[string]ValidationLevel{ + "provider": ValidationLevelProvider, + "providernorbac": ValidationLevelProviderNoRbac, + "template": ValidationLevelTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ValidationLevel(input) + return &out, nil +} + +type WhatIfResultFormat string + +const ( + WhatIfResultFormatFullResourcePayloads WhatIfResultFormat = "FullResourcePayloads" + WhatIfResultFormatResourceIdOnly WhatIfResultFormat = "ResourceIdOnly" +) + +func PossibleValuesForWhatIfResultFormat() []string { + return []string{ + string(WhatIfResultFormatFullResourcePayloads), + string(WhatIfResultFormatResourceIdOnly), + } +} + +func (s *WhatIfResultFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWhatIfResultFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWhatIfResultFormat(input string) (*WhatIfResultFormat, error) { + vals := map[string]WhatIfResultFormat{ + "fullresourcepayloads": WhatIfResultFormatFullResourcePayloads, + "resourceidonly": WhatIfResultFormatResourceIdOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WhatIfResultFormat(input) + return &out, nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/id_deployment.go b/resource-manager/resources/2025-03-01/deployments/id_deployment.go new file mode 100644 index 00000000000..db858c484e5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_deployment.go @@ -0,0 +1,112 @@ +package deployments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeploymentId{}) +} + +var _ resourceids.ResourceId = &DeploymentId{} + +// DeploymentId is a struct representing the Resource ID for a Deployment +type DeploymentId struct { + DeploymentName string +} + +// NewDeploymentID returns a new DeploymentId struct +func NewDeploymentID(deploymentName string) DeploymentId { + return DeploymentId{ + DeploymentName: deploymentName, + } +} + +// ParseDeploymentID parses 'input' into a DeploymentId +func ParseDeploymentID(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeploymentIDInsensitively parses 'input' case-insensitively into a DeploymentId +// note: this method should only be used for API response data and not user input +func ParseDeploymentIDInsensitively(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateDeploymentID checks that 'input' can be parsed as a Deployment ID +func ValidateDeploymentID(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 := ParseDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deployment ID +func (id DeploymentId) ID() string { + fmtString := "/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deployment ID +func (id DeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Deployment ID +func (id DeploymentId) String() string { + components := []string{ + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deployments/id_deployment_test.go b/resource-manager/resources/2025-03-01/deployments/id_deployment_test.go new file mode 100644 index 00000000000..e2a4b7d8fef --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_deployment_test.go @@ -0,0 +1,192 @@ +package deployments + +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 = &DeploymentId{} + +func TestNewDeploymentID(t *testing.T) { + id := NewDeploymentID("deploymentName") + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatDeploymentID(t *testing.T) { + actual := NewDeploymentID("deploymentName").ID() + expected := "/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &DeploymentId{ + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &DeploymentId{ + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &DeploymentId{ + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForDeploymentId(t *testing.T) { + segments := DeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeploymentId 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/resources/2025-03-01/deployments/id_providerdeployment.go b/resource-manager/resources/2025-03-01/deployments/id_providerdeployment.go new file mode 100644 index 00000000000..0ed4ef20c86 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_providerdeployment.go @@ -0,0 +1,121 @@ +package deployments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderDeploymentId{}) +} + +var _ resourceids.ResourceId = &ProviderDeploymentId{} + +// ProviderDeploymentId is a struct representing the Resource ID for a Provider Deployment +type ProviderDeploymentId struct { + SubscriptionId string + DeploymentName string +} + +// NewProviderDeploymentID returns a new ProviderDeploymentId struct +func NewProviderDeploymentID(subscriptionId string, deploymentName string) ProviderDeploymentId { + return ProviderDeploymentId{ + SubscriptionId: subscriptionId, + DeploymentName: deploymentName, + } +} + +// ParseProviderDeploymentID parses 'input' into a ProviderDeploymentId +func ParseProviderDeploymentID(input string) (*ProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderDeploymentIDInsensitively parses 'input' case-insensitively into a ProviderDeploymentId +// note: this method should only be used for API response data and not user input +func ParseProviderDeploymentIDInsensitively(input string) (*ProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderDeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateProviderDeploymentID checks that 'input' can be parsed as a Provider Deployment ID +func ValidateProviderDeploymentID(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 := ParseProviderDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Deployment ID +func (id ProviderDeploymentId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Deployment ID +func (id ProviderDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Provider Deployment ID +func (id ProviderDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Provider Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deployments/id_providerdeployment_test.go b/resource-manager/resources/2025-03-01/deployments/id_providerdeployment_test.go new file mode 100644 index 00000000000..3b08c1ccbef --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_providerdeployment_test.go @@ -0,0 +1,237 @@ +package deployments + +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 = &ProviderDeploymentId{} + +func TestNewProviderDeploymentID(t *testing.T) { + id := NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName") + + 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.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatProviderDeploymentID(t *testing.T) { + actual := NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "deploymentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderDeploymentID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseProviderDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderDeploymentIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForProviderDeploymentId(t *testing.T) { + segments := ProviderDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderDeploymentId 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/resources/2025-03-01/deployments/id_providers2deployment.go b/resource-manager/resources/2025-03-01/deployments/id_providers2deployment.go new file mode 100644 index 00000000000..ddbb3f3807b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_providers2deployment.go @@ -0,0 +1,123 @@ +package deployments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&Providers2DeploymentId{}) +} + +var _ resourceids.ResourceId = &Providers2DeploymentId{} + +// Providers2DeploymentId is a struct representing the Resource ID for a Providers 2 Deployment +type Providers2DeploymentId struct { + GroupId string + DeploymentName string +} + +// NewProviders2DeploymentID returns a new Providers2DeploymentId struct +func NewProviders2DeploymentID(groupId string, deploymentName string) Providers2DeploymentId { + return Providers2DeploymentId{ + GroupId: groupId, + DeploymentName: deploymentName, + } +} + +// ParseProviders2DeploymentID parses 'input' into a Providers2DeploymentId +func ParseProviders2DeploymentID(input string) (*Providers2DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2DeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviders2DeploymentIDInsensitively parses 'input' case-insensitively into a Providers2DeploymentId +// note: this method should only be used for API response data and not user input +func ParseProviders2DeploymentIDInsensitively(input string) (*Providers2DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2DeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2DeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *Providers2DeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateProviders2DeploymentID checks that 'input' can be parsed as a Providers 2 Deployment ID +func ValidateProviders2DeploymentID(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 := ParseProviders2DeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Providers 2 Deployment ID +func (id Providers2DeploymentId) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.GroupId, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Providers 2 Deployment ID +func (id Providers2DeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("groupId", "groupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Providers 2 Deployment ID +func (id Providers2DeploymentId) String() string { + components := []string{ + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Providers 2 Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deployments/id_providers2deployment_test.go b/resource-manager/resources/2025-03-01/deployments/id_providers2deployment_test.go new file mode 100644 index 00000000000..422a3d522c5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_providers2deployment_test.go @@ -0,0 +1,267 @@ +package deployments + +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 = &Providers2DeploymentId{} + +func TestNewProviders2DeploymentID(t *testing.T) { + id := NewProviders2DeploymentID("groupId", "deploymentName") + + if id.GroupId != "groupId" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupId") + } + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatProviders2DeploymentID(t *testing.T) { + actual := NewProviders2DeploymentID("groupId", "deploymentName").ID() + expected := "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviders2DeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &Providers2DeploymentId{ + GroupId: "groupId", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2DeploymentID(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseProviders2DeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &Providers2DeploymentId{ + GroupId: "groupId", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &Providers2DeploymentId{ + GroupId: "gRoUpId", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2DeploymentIDInsensitively(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForProviders2DeploymentId(t *testing.T) { + segments := Providers2DeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("Providers2DeploymentId 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/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment.go b/resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment.go new file mode 100644 index 00000000000..9e434816dcd --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment.go @@ -0,0 +1,130 @@ +package deployments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ResourceGroupProviderDeploymentId{}) +} + +var _ resourceids.ResourceId = &ResourceGroupProviderDeploymentId{} + +// ResourceGroupProviderDeploymentId is a struct representing the Resource ID for a Resource Group Provider Deployment +type ResourceGroupProviderDeploymentId struct { + SubscriptionId string + ResourceGroupName string + DeploymentName string +} + +// NewResourceGroupProviderDeploymentID returns a new ResourceGroupProviderDeploymentId struct +func NewResourceGroupProviderDeploymentID(subscriptionId string, resourceGroupName string, deploymentName string) ResourceGroupProviderDeploymentId { + return ResourceGroupProviderDeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DeploymentName: deploymentName, + } +} + +// ParseResourceGroupProviderDeploymentID parses 'input' into a ResourceGroupProviderDeploymentId +func ParseResourceGroupProviderDeploymentID(input string) (*ResourceGroupProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupProviderDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupProviderDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseResourceGroupProviderDeploymentIDInsensitively parses 'input' case-insensitively into a ResourceGroupProviderDeploymentId +// note: this method should only be used for API response data and not user input +func ParseResourceGroupProviderDeploymentIDInsensitively(input string) (*ResourceGroupProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ResourceGroupProviderDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ResourceGroupProviderDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ResourceGroupProviderDeploymentId) 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.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateResourceGroupProviderDeploymentID checks that 'input' can be parsed as a Resource Group Provider Deployment ID +func ValidateResourceGroupProviderDeploymentID(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 := ParseResourceGroupProviderDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Group Provider Deployment ID +func (id ResourceGroupProviderDeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Resource Group Provider Deployment ID +func (id ResourceGroupProviderDeploymentId) 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("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Resource Group Provider Deployment ID +func (id ResourceGroupProviderDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Resource Group Provider Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment_test.go b/resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment_test.go new file mode 100644 index 00000000000..f3c9f5abbe3 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_resourcegroupproviderdeployment_test.go @@ -0,0 +1,282 @@ +package deployments + +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 = &ResourceGroupProviderDeploymentId{} + +func TestNewResourceGroupProviderDeploymentID(t *testing.T) { + id := NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName") + + 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.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatResourceGroupProviderDeploymentID(t *testing.T) { + actual := NewResourceGroupProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseResourceGroupProviderDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupProviderDeploymentId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ResourceGroupProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupProviderDeploymentID(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseResourceGroupProviderDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ResourceGroupProviderDeploymentId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ResourceGroupProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &ResourceGroupProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // 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.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseResourceGroupProviderDeploymentIDInsensitively(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.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForResourceGroupProviderDeploymentId(t *testing.T) { + segments := ResourceGroupProviderDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ResourceGroupProviderDeploymentId 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/resources/2025-03-01/deployments/id_scopeddeployment.go b/resource-manager/resources/2025-03-01/deployments/id_scopeddeployment.go new file mode 100644 index 00000000000..66d461f7a2c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_scopeddeployment.go @@ -0,0 +1,120 @@ +package deployments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedDeploymentId{}) +} + +var _ resourceids.ResourceId = &ScopedDeploymentId{} + +// ScopedDeploymentId is a struct representing the Resource ID for a Scoped Deployment +type ScopedDeploymentId struct { + Scope string + DeploymentName string +} + +// NewScopedDeploymentID returns a new ScopedDeploymentId struct +func NewScopedDeploymentID(scope string, deploymentName string) ScopedDeploymentId { + return ScopedDeploymentId{ + Scope: scope, + DeploymentName: deploymentName, + } +} + +// ParseScopedDeploymentID parses 'input' into a ScopedDeploymentId +func ParseScopedDeploymentID(input string) (*ScopedDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedDeploymentIDInsensitively parses 'input' case-insensitively into a ScopedDeploymentId +// note: this method should only be used for API response data and not user input +func ParseScopedDeploymentIDInsensitively(input string) (*ScopedDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedDeploymentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedDeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateScopedDeploymentID checks that 'input' can be parsed as a Scoped Deployment ID +func ValidateScopedDeploymentID(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 := ParseScopedDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Deployment ID +func (id ScopedDeploymentId) ID() string { + fmtString := "/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Deployment ID +func (id ScopedDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentName"), + } +} + +// String returns a human-readable description of this Scoped Deployment ID +func (id ScopedDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Scoped Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/deployments/id_scopeddeployment_test.go b/resource-manager/resources/2025-03-01/deployments/id_scopeddeployment_test.go new file mode 100644 index 00000000000..717b9cf0f05 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/id_scopeddeployment_test.go @@ -0,0 +1,222 @@ +package deployments + +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 = &ScopedDeploymentId{} + +func TestNewScopedDeploymentID(t *testing.T) { + id := NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.DeploymentName != "deploymentName" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentName") + } +} + +func TestFormatScopedDeploymentID(t *testing.T) { + actual := NewScopedDeploymentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "deploymentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedDeploymentId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ScopedDeploymentId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseScopedDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedDeploymentId + }{ + { + // 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.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName", + Expected: &ScopedDeploymentId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + DeploymentName: "deploymentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Resources/deployments/deploymentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE", + Expected: &ScopedDeploymentId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + DeploymentName: "dEpLoYmEnTnAmE", + }, + }, + { + // 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.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForScopedDeploymentId(t *testing.T) { + segments := ScopedDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedDeploymentId 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/resources/2025-03-01/deployments/method_calculatetemplatehash.go b/resource-manager/resources/2025-03-01/deployments/method_calculatetemplatehash.go new file mode 100644 index 00000000000..f3c114f9dbc --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_calculatetemplatehash.go @@ -0,0 +1,57 @@ +package deployments + +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 CalculateTemplateHashOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TemplateHashResult +} + +// CalculateTemplateHash ... +func (c DeploymentsClient) CalculateTemplateHash(ctx context.Context, input interface{}) (result CalculateTemplateHashOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: "/providers/Microsoft.Resources/calculateTemplateHash", + } + + 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 TemplateHashResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_cancel.go b/resource-manager/resources/2025-03-01/deployments/method_cancel.go new file mode 100644 index 00000000000..42b67075342 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_cancel.go @@ -0,0 +1,47 @@ +package deployments + +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 CancelOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Cancel ... +func (c DeploymentsClient) Cancel(ctx context.Context, id ResourceGroupProviderDeploymentId) (result CancelOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_cancelatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_cancelatmanagementgroupscope.go new file mode 100644 index 00000000000..d8d8f007044 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_cancelatmanagementgroupscope.go @@ -0,0 +1,47 @@ +package deployments + +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 CancelAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CancelAtManagementGroupScope ... +func (c DeploymentsClient) CancelAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId) (result CancelAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_cancelatscope.go b/resource-manager/resources/2025-03-01/deployments/method_cancelatscope.go new file mode 100644 index 00000000000..9c9ec3b47e5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_cancelatscope.go @@ -0,0 +1,47 @@ +package deployments + +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 CancelAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CancelAtScope ... +func (c DeploymentsClient) CancelAtScope(ctx context.Context, id ScopedDeploymentId) (result CancelAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_cancelatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_cancelatsubscriptionscope.go new file mode 100644 index 00000000000..9c69e1bb6c7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_cancelatsubscriptionscope.go @@ -0,0 +1,47 @@ +package deployments + +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 CancelAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CancelAtSubscriptionScope ... +func (c DeploymentsClient) CancelAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId) (result CancelAtSubscriptionScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_cancelattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_cancelattenantscope.go new file mode 100644 index 00000000000..4343e507af5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_cancelattenantscope.go @@ -0,0 +1,47 @@ +package deployments + +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 CancelAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CancelAtTenantScope ... +func (c DeploymentsClient) CancelAtTenantScope(ctx context.Context, id DeploymentId) (result CancelAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_checkexistence.go b/resource-manager/resources/2025-03-01/deployments/method_checkexistence.go new file mode 100644 index 00000000000..c05a1cbcf26 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_checkexistence.go @@ -0,0 +1,46 @@ +package deployments + +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 CheckExistenceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistence ... +func (c DeploymentsClient) CheckExistence(ctx context.Context, id ResourceGroupProviderDeploymentId) (result CheckExistenceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatmanagementgroupscope.go new file mode 100644 index 00000000000..423b149c6ee --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatmanagementgroupscope.go @@ -0,0 +1,46 @@ +package deployments + +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 CheckExistenceAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistenceAtManagementGroupScope ... +func (c DeploymentsClient) CheckExistenceAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId) (result CheckExistenceAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatscope.go b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatscope.go new file mode 100644 index 00000000000..ae5d6a3b147 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatscope.go @@ -0,0 +1,46 @@ +package deployments + +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 CheckExistenceAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistenceAtScope ... +func (c DeploymentsClient) CheckExistenceAtScope(ctx context.Context, id ScopedDeploymentId) (result CheckExistenceAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatsubscriptionscope.go new file mode 100644 index 00000000000..cdd0f124b31 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceatsubscriptionscope.go @@ -0,0 +1,46 @@ +package deployments + +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 CheckExistenceAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistenceAtSubscriptionScope ... +func (c DeploymentsClient) CheckExistenceAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId) (result CheckExistenceAtSubscriptionScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_checkexistenceattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceattenantscope.go new file mode 100644 index 00000000000..6313c717a07 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_checkexistenceattenantscope.go @@ -0,0 +1,46 @@ +package deployments + +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 CheckExistenceAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistenceAtTenantScope ... +func (c DeploymentsClient) CheckExistenceAtTenantScope(ctx context.Context, id DeploymentId) (result CheckExistenceAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_createorupdate.go b/resource-manager/resources/2025-03-01/deployments/method_createorupdate.go new file mode 100644 index 00000000000..4c4d11e4cd4 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_createorupdate.go @@ -0,0 +1,75 @@ +package deployments + +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 *DeploymentExtended +} + +// CreateOrUpdate ... +func (c DeploymentsClient) CreateOrUpdate(ctx context.Context, id ResourceGroupProviderDeploymentId, input Deployment) (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 DeploymentsClient) CreateOrUpdateThenPoll(ctx context.Context, id ResourceGroupProviderDeploymentId, input Deployment) 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/resources/2025-03-01/deployments/method_createorupdateatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_createorupdateatmanagementgroupscope.go new file mode 100644 index 00000000000..7eed5ff8495 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_createorupdateatmanagementgroupscope.go @@ -0,0 +1,75 @@ +package deployments + +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 CreateOrUpdateAtManagementGroupScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// CreateOrUpdateAtManagementGroupScope ... +func (c DeploymentsClient) CreateOrUpdateAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId, input ScopedDeployment) (result CreateOrUpdateAtManagementGroupScopeOperationResponse, 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 +} + +// CreateOrUpdateAtManagementGroupScopeThenPoll performs CreateOrUpdateAtManagementGroupScope then polls until it's completed +func (c DeploymentsClient) CreateOrUpdateAtManagementGroupScopeThenPoll(ctx context.Context, id Providers2DeploymentId, input ScopedDeployment) error { + result, err := c.CreateOrUpdateAtManagementGroupScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateAtManagementGroupScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateAtManagementGroupScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_createorupdateatscope.go b/resource-manager/resources/2025-03-01/deployments/method_createorupdateatscope.go new file mode 100644 index 00000000000..8b2f4e3f79a --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_createorupdateatscope.go @@ -0,0 +1,75 @@ +package deployments + +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 CreateOrUpdateAtScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// CreateOrUpdateAtScope ... +func (c DeploymentsClient) CreateOrUpdateAtScope(ctx context.Context, id ScopedDeploymentId, input Deployment) (result CreateOrUpdateAtScopeOperationResponse, 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 +} + +// CreateOrUpdateAtScopeThenPoll performs CreateOrUpdateAtScope then polls until it's completed +func (c DeploymentsClient) CreateOrUpdateAtScopeThenPoll(ctx context.Context, id ScopedDeploymentId, input Deployment) error { + result, err := c.CreateOrUpdateAtScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateAtScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateAtScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_createorupdateatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_createorupdateatsubscriptionscope.go new file mode 100644 index 00000000000..98b8254b41d --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_createorupdateatsubscriptionscope.go @@ -0,0 +1,75 @@ +package deployments + +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 CreateOrUpdateAtSubscriptionScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// CreateOrUpdateAtSubscriptionScope ... +func (c DeploymentsClient) CreateOrUpdateAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId, input Deployment) (result CreateOrUpdateAtSubscriptionScopeOperationResponse, 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 +} + +// CreateOrUpdateAtSubscriptionScopeThenPoll performs CreateOrUpdateAtSubscriptionScope then polls until it's completed +func (c DeploymentsClient) CreateOrUpdateAtSubscriptionScopeThenPoll(ctx context.Context, id ProviderDeploymentId, input Deployment) error { + result, err := c.CreateOrUpdateAtSubscriptionScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateAtSubscriptionScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateAtSubscriptionScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_createorupdateattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_createorupdateattenantscope.go new file mode 100644 index 00000000000..877c825eced --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_createorupdateattenantscope.go @@ -0,0 +1,75 @@ +package deployments + +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 CreateOrUpdateAtTenantScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// CreateOrUpdateAtTenantScope ... +func (c DeploymentsClient) CreateOrUpdateAtTenantScope(ctx context.Context, id DeploymentId, input ScopedDeployment) (result CreateOrUpdateAtTenantScopeOperationResponse, 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 +} + +// CreateOrUpdateAtTenantScopeThenPoll performs CreateOrUpdateAtTenantScope then polls until it's completed +func (c DeploymentsClient) CreateOrUpdateAtTenantScopeThenPoll(ctx context.Context, id DeploymentId, input ScopedDeployment) error { + result, err := c.CreateOrUpdateAtTenantScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateAtTenantScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateAtTenantScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_delete.go b/resource-manager/resources/2025-03-01/deployments/method_delete.go new file mode 100644 index 00000000000..0e259131aa8 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_delete.go @@ -0,0 +1,70 @@ +package deployments + +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 DeploymentsClient) Delete(ctx context.Context, id ResourceGroupProviderDeploymentId) (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 DeploymentsClient) DeleteThenPoll(ctx context.Context, id ResourceGroupProviderDeploymentId) 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/resources/2025-03-01/deployments/method_deleteatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_deleteatmanagementgroupscope.go new file mode 100644 index 00000000000..e9e4770cd69 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_deleteatmanagementgroupscope.go @@ -0,0 +1,70 @@ +package deployments + +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 DeleteAtManagementGroupScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteAtManagementGroupScope ... +func (c DeploymentsClient) DeleteAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId) (result DeleteAtManagementGroupScopeOperationResponse, 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 +} + +// DeleteAtManagementGroupScopeThenPoll performs DeleteAtManagementGroupScope then polls until it's completed +func (c DeploymentsClient) DeleteAtManagementGroupScopeThenPoll(ctx context.Context, id Providers2DeploymentId) error { + result, err := c.DeleteAtManagementGroupScope(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteAtManagementGroupScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteAtManagementGroupScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_deleteatscope.go b/resource-manager/resources/2025-03-01/deployments/method_deleteatscope.go new file mode 100644 index 00000000000..b6078ea8f62 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_deleteatscope.go @@ -0,0 +1,70 @@ +package deployments + +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 DeleteAtScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteAtScope ... +func (c DeploymentsClient) DeleteAtScope(ctx context.Context, id ScopedDeploymentId) (result DeleteAtScopeOperationResponse, 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 +} + +// DeleteAtScopeThenPoll performs DeleteAtScope then polls until it's completed +func (c DeploymentsClient) DeleteAtScopeThenPoll(ctx context.Context, id ScopedDeploymentId) error { + result, err := c.DeleteAtScope(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteAtScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteAtScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_deleteatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_deleteatsubscriptionscope.go new file mode 100644 index 00000000000..3a45d157fd8 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_deleteatsubscriptionscope.go @@ -0,0 +1,70 @@ +package deployments + +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 DeleteAtSubscriptionScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteAtSubscriptionScope ... +func (c DeploymentsClient) DeleteAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId) (result DeleteAtSubscriptionScopeOperationResponse, 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 +} + +// DeleteAtSubscriptionScopeThenPoll performs DeleteAtSubscriptionScope then polls until it's completed +func (c DeploymentsClient) DeleteAtSubscriptionScopeThenPoll(ctx context.Context, id ProviderDeploymentId) error { + result, err := c.DeleteAtSubscriptionScope(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteAtSubscriptionScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteAtSubscriptionScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_deleteattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_deleteattenantscope.go new file mode 100644 index 00000000000..eb392b14813 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_deleteattenantscope.go @@ -0,0 +1,70 @@ +package deployments + +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 DeleteAtTenantScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteAtTenantScope ... +func (c DeploymentsClient) DeleteAtTenantScope(ctx context.Context, id DeploymentId) (result DeleteAtTenantScopeOperationResponse, 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 +} + +// DeleteAtTenantScopeThenPoll performs DeleteAtTenantScope then polls until it's completed +func (c DeploymentsClient) DeleteAtTenantScopeThenPoll(ctx context.Context, id DeploymentId) error { + result, err := c.DeleteAtTenantScope(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteAtTenantScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteAtTenantScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_exporttemplate.go b/resource-manager/resources/2025-03-01/deployments/method_exporttemplate.go new file mode 100644 index 00000000000..9cc11aa5c38 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_exporttemplate.go @@ -0,0 +1,54 @@ +package deployments + +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 ExportTemplateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExportResult +} + +// ExportTemplate ... +func (c DeploymentsClient) ExportTemplate(ctx context.Context, id ResourceGroupProviderDeploymentId) (result ExportTemplateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportTemplate", 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 DeploymentExportResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatmanagementgroupscope.go new file mode 100644 index 00000000000..f701608fff0 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatmanagementgroupscope.go @@ -0,0 +1,54 @@ +package deployments + +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 ExportTemplateAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExportResult +} + +// ExportTemplateAtManagementGroupScope ... +func (c DeploymentsClient) ExportTemplateAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId) (result ExportTemplateAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportTemplate", 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 DeploymentExportResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatscope.go b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatscope.go new file mode 100644 index 00000000000..bf51f90942f --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatscope.go @@ -0,0 +1,54 @@ +package deployments + +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 ExportTemplateAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExportResult +} + +// ExportTemplateAtScope ... +func (c DeploymentsClient) ExportTemplateAtScope(ctx context.Context, id ScopedDeploymentId) (result ExportTemplateAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportTemplate", 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 DeploymentExportResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatsubscriptionscope.go new file mode 100644 index 00000000000..d8d454634f7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateatsubscriptionscope.go @@ -0,0 +1,54 @@ +package deployments + +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 ExportTemplateAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExportResult +} + +// ExportTemplateAtSubscriptionScope ... +func (c DeploymentsClient) ExportTemplateAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId) (result ExportTemplateAtSubscriptionScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportTemplate", 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 DeploymentExportResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_exporttemplateattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateattenantscope.go new file mode 100644 index 00000000000..1f18175bf21 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_exporttemplateattenantscope.go @@ -0,0 +1,54 @@ +package deployments + +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 ExportTemplateAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExportResult +} + +// ExportTemplateAtTenantScope ... +func (c DeploymentsClient) ExportTemplateAtTenantScope(ctx context.Context, id DeploymentId) (result ExportTemplateAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportTemplate", 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 DeploymentExportResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_get.go b/resource-manager/resources/2025-03-01/deployments/method_get.go new file mode 100644 index 00000000000..b075492676b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_get.go @@ -0,0 +1,53 @@ +package deployments + +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 *DeploymentExtended +} + +// Get ... +func (c DeploymentsClient) Get(ctx context.Context, id ResourceGroupProviderDeploymentId) (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 DeploymentExtended + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_getatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_getatmanagementgroupscope.go new file mode 100644 index 00000000000..96c3414af4c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_getatmanagementgroupscope.go @@ -0,0 +1,53 @@ +package deployments + +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 GetAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// GetAtManagementGroupScope ... +func (c DeploymentsClient) GetAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId) (result GetAtManagementGroupScopeOperationResponse, 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 DeploymentExtended + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_getatscope.go b/resource-manager/resources/2025-03-01/deployments/method_getatscope.go new file mode 100644 index 00000000000..7a084f6f7ca --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_getatscope.go @@ -0,0 +1,53 @@ +package deployments + +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 GetAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// GetAtScope ... +func (c DeploymentsClient) GetAtScope(ctx context.Context, id ScopedDeploymentId) (result GetAtScopeOperationResponse, 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 DeploymentExtended + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_getatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_getatsubscriptionscope.go new file mode 100644 index 00000000000..92e44fbafca --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_getatsubscriptionscope.go @@ -0,0 +1,53 @@ +package deployments + +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 GetAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// GetAtSubscriptionScope ... +func (c DeploymentsClient) GetAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId) (result GetAtSubscriptionScopeOperationResponse, 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 DeploymentExtended + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_getattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_getattenantscope.go new file mode 100644 index 00000000000..fccae4c0dfa --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_getattenantscope.go @@ -0,0 +1,53 @@ +package deployments + +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 GetAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentExtended +} + +// GetAtTenantScope ... +func (c DeploymentsClient) GetAtTenantScope(ctx context.Context, id DeploymentId) (result GetAtTenantScopeOperationResponse, 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 DeploymentExtended + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_listatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_listatmanagementgroupscope.go new file mode 100644 index 00000000000..c0ebef35406 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_listatmanagementgroupscope.go @@ -0,0 +1,139 @@ +package deployments + +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 ListAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentExtended +} + +type ListAtManagementGroupScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentExtended +} + +type ListAtManagementGroupScopeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListAtManagementGroupScopeOperationOptions() ListAtManagementGroupScopeOperationOptions { + return ListAtManagementGroupScopeOperationOptions{} +} + +func (o ListAtManagementGroupScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtManagementGroupScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtManagementGroupScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtManagementGroupScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtManagementGroupScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtManagementGroupScope ... +func (c DeploymentsClient) ListAtManagementGroupScope(ctx context.Context, id commonids.ManagementGroupId, options ListAtManagementGroupScopeOperationOptions) (result ListAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtManagementGroupScopeCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/deployments", 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 *[]DeploymentExtended `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtManagementGroupScopeComplete retrieves all the results into a single object +func (c DeploymentsClient) ListAtManagementGroupScopeComplete(ctx context.Context, id commonids.ManagementGroupId, options ListAtManagementGroupScopeOperationOptions) (ListAtManagementGroupScopeCompleteResult, error) { + return c.ListAtManagementGroupScopeCompleteMatchingPredicate(ctx, id, options, DeploymentExtendedOperationPredicate{}) +} + +// ListAtManagementGroupScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListAtManagementGroupScopeCompleteMatchingPredicate(ctx context.Context, id commonids.ManagementGroupId, options ListAtManagementGroupScopeOperationOptions, predicate DeploymentExtendedOperationPredicate) (result ListAtManagementGroupScopeCompleteResult, err error) { + items := make([]DeploymentExtended, 0) + + resp, err := c.ListAtManagementGroupScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtManagementGroupScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_listatscope.go b/resource-manager/resources/2025-03-01/deployments/method_listatscope.go new file mode 100644 index 00000000000..40f556a4f8b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_listatscope.go @@ -0,0 +1,139 @@ +package deployments + +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 ListAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentExtended +} + +type ListAtScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentExtended +} + +type ListAtScopeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListAtScopeOperationOptions() ListAtScopeOperationOptions { + return ListAtScopeOperationOptions{} +} + +func (o ListAtScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtScope ... +func (c DeploymentsClient) ListAtScope(ctx context.Context, id commonids.ScopeId, options ListAtScopeOperationOptions) (result ListAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtScopeCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/deployments", 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 *[]DeploymentExtended `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtScopeComplete retrieves all the results into a single object +func (c DeploymentsClient) ListAtScopeComplete(ctx context.Context, id commonids.ScopeId, options ListAtScopeOperationOptions) (ListAtScopeCompleteResult, error) { + return c.ListAtScopeCompleteMatchingPredicate(ctx, id, options, DeploymentExtendedOperationPredicate{}) +} + +// ListAtScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListAtScopeCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListAtScopeOperationOptions, predicate DeploymentExtendedOperationPredicate) (result ListAtScopeCompleteResult, err error) { + items := make([]DeploymentExtended, 0) + + resp, err := c.ListAtScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_listatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_listatsubscriptionscope.go new file mode 100644 index 00000000000..4962151485c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_listatsubscriptionscope.go @@ -0,0 +1,139 @@ +package deployments + +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 ListAtSubscriptionScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentExtended +} + +type ListAtSubscriptionScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentExtended +} + +type ListAtSubscriptionScopeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListAtSubscriptionScopeOperationOptions() ListAtSubscriptionScopeOperationOptions { + return ListAtSubscriptionScopeOperationOptions{} +} + +func (o ListAtSubscriptionScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtSubscriptionScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtSubscriptionScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtSubscriptionScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtSubscriptionScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtSubscriptionScope ... +func (c DeploymentsClient) ListAtSubscriptionScope(ctx context.Context, id commonids.SubscriptionId, options ListAtSubscriptionScopeOperationOptions) (result ListAtSubscriptionScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtSubscriptionScopeCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/deployments", 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 *[]DeploymentExtended `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtSubscriptionScopeComplete retrieves all the results into a single object +func (c DeploymentsClient) ListAtSubscriptionScopeComplete(ctx context.Context, id commonids.SubscriptionId, options ListAtSubscriptionScopeOperationOptions) (ListAtSubscriptionScopeCompleteResult, error) { + return c.ListAtSubscriptionScopeCompleteMatchingPredicate(ctx, id, options, DeploymentExtendedOperationPredicate{}) +} + +// ListAtSubscriptionScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListAtSubscriptionScopeCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListAtSubscriptionScopeOperationOptions, predicate DeploymentExtendedOperationPredicate) (result ListAtSubscriptionScopeCompleteResult, err error) { + items := make([]DeploymentExtended, 0) + + resp, err := c.ListAtSubscriptionScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtSubscriptionScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_listattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_listattenantscope.go new file mode 100644 index 00000000000..09d08be35ac --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_listattenantscope.go @@ -0,0 +1,138 @@ +package deployments + +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 ListAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeploymentExtended +} + +type ListAtTenantScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentExtended +} + +type ListAtTenantScopeOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListAtTenantScopeOperationOptions() ListAtTenantScopeOperationOptions { + return ListAtTenantScopeOperationOptions{} +} + +func (o ListAtTenantScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtTenantScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtTenantScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListAtTenantScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtTenantScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtTenantScope ... +func (c DeploymentsClient) ListAtTenantScope(ctx context.Context, options ListAtTenantScopeOperationOptions) (result ListAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtTenantScopeCustomPager{}, + Path: "/providers/Microsoft.Resources/deployments", + } + + 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 *[]DeploymentExtended `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtTenantScopeComplete retrieves all the results into a single object +func (c DeploymentsClient) ListAtTenantScopeComplete(ctx context.Context, options ListAtTenantScopeOperationOptions) (ListAtTenantScopeCompleteResult, error) { + return c.ListAtTenantScopeCompleteMatchingPredicate(ctx, options, DeploymentExtendedOperationPredicate{}) +} + +// ListAtTenantScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListAtTenantScopeCompleteMatchingPredicate(ctx context.Context, options ListAtTenantScopeOperationOptions, predicate DeploymentExtendedOperationPredicate) (result ListAtTenantScopeCompleteResult, err error) { + items := make([]DeploymentExtended, 0) + + resp, err := c.ListAtTenantScope(ctx, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtTenantScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_listbyresourcegroup.go b/resource-manager/resources/2025-03-01/deployments/method_listbyresourcegroup.go new file mode 100644 index 00000000000..6c592704a15 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_listbyresourcegroup.go @@ -0,0 +1,139 @@ +package deployments + +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 *[]DeploymentExtended +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentExtended +} + +type ListByResourceGroupOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c DeploymentsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/deployments", 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 *[]DeploymentExtended `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 DeploymentsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, DeploymentExtendedOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate DeploymentExtendedOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]DeploymentExtended, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_validate.go b/resource-manager/resources/2025-03-01/deployments/method_validate.go new file mode 100644 index 00000000000..88725bc88db --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_validate.go @@ -0,0 +1,75 @@ +package deployments + +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 *DeploymentValidateResult +} + +// Validate ... +func (c DeploymentsClient) Validate(ctx context.Context, id ResourceGroupProviderDeploymentId, input Deployment) (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 DeploymentsClient) ValidateThenPoll(ctx context.Context, id ResourceGroupProviderDeploymentId, input Deployment) 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/resources/2025-03-01/deployments/method_validateatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_validateatmanagementgroupscope.go new file mode 100644 index 00000000000..883dd5fb12e --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_validateatmanagementgroupscope.go @@ -0,0 +1,75 @@ +package deployments + +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 ValidateAtManagementGroupScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentValidateResult +} + +// ValidateAtManagementGroupScope ... +func (c DeploymentsClient) ValidateAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId, input ScopedDeployment) (result ValidateAtManagementGroupScopeOperationResponse, 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 +} + +// ValidateAtManagementGroupScopeThenPoll performs ValidateAtManagementGroupScope then polls until it's completed +func (c DeploymentsClient) ValidateAtManagementGroupScopeThenPoll(ctx context.Context, id Providers2DeploymentId, input ScopedDeployment) error { + result, err := c.ValidateAtManagementGroupScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateAtManagementGroupScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateAtManagementGroupScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_validateatscope.go b/resource-manager/resources/2025-03-01/deployments/method_validateatscope.go new file mode 100644 index 00000000000..21e6482c2d2 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_validateatscope.go @@ -0,0 +1,75 @@ +package deployments + +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 ValidateAtScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentValidateResult +} + +// ValidateAtScope ... +func (c DeploymentsClient) ValidateAtScope(ctx context.Context, id ScopedDeploymentId, input Deployment) (result ValidateAtScopeOperationResponse, 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 +} + +// ValidateAtScopeThenPoll performs ValidateAtScope then polls until it's completed +func (c DeploymentsClient) ValidateAtScopeThenPoll(ctx context.Context, id ScopedDeploymentId, input Deployment) error { + result, err := c.ValidateAtScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateAtScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateAtScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_validateatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_validateatsubscriptionscope.go new file mode 100644 index 00000000000..bb85e3ac4e0 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_validateatsubscriptionscope.go @@ -0,0 +1,75 @@ +package deployments + +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 ValidateAtSubscriptionScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentValidateResult +} + +// ValidateAtSubscriptionScope ... +func (c DeploymentsClient) ValidateAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId, input Deployment) (result ValidateAtSubscriptionScopeOperationResponse, 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 +} + +// ValidateAtSubscriptionScopeThenPoll performs ValidateAtSubscriptionScope then polls until it's completed +func (c DeploymentsClient) ValidateAtSubscriptionScopeThenPoll(ctx context.Context, id ProviderDeploymentId, input Deployment) error { + result, err := c.ValidateAtSubscriptionScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateAtSubscriptionScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateAtSubscriptionScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_validateattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_validateattenantscope.go new file mode 100644 index 00000000000..2200053106b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_validateattenantscope.go @@ -0,0 +1,75 @@ +package deployments + +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 ValidateAtTenantScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentValidateResult +} + +// ValidateAtTenantScope ... +func (c DeploymentsClient) ValidateAtTenantScope(ctx context.Context, id DeploymentId, input ScopedDeployment) (result ValidateAtTenantScopeOperationResponse, 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 +} + +// ValidateAtTenantScopeThenPoll performs ValidateAtTenantScope then polls until it's completed +func (c DeploymentsClient) ValidateAtTenantScopeThenPoll(ctx context.Context, id DeploymentId, input ScopedDeployment) error { + result, err := c.ValidateAtTenantScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateAtTenantScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateAtTenantScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_whatif.go b/resource-manager/resources/2025-03-01/deployments/method_whatif.go new file mode 100644 index 00000000000..ed328506f94 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_whatif.go @@ -0,0 +1,75 @@ +package deployments + +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 WhatIfOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WhatIfOperationResult +} + +// WhatIf ... +func (c DeploymentsClient) WhatIf(ctx context.Context, id ResourceGroupProviderDeploymentId, input DeploymentWhatIf) (result WhatIfOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/whatIf", 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 +} + +// WhatIfThenPoll performs WhatIf then polls until it's completed +func (c DeploymentsClient) WhatIfThenPoll(ctx context.Context, id ResourceGroupProviderDeploymentId, input DeploymentWhatIf) error { + result, err := c.WhatIf(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WhatIf: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WhatIf: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_whatifatmanagementgroupscope.go b/resource-manager/resources/2025-03-01/deployments/method_whatifatmanagementgroupscope.go new file mode 100644 index 00000000000..84caa3c7b5d --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_whatifatmanagementgroupscope.go @@ -0,0 +1,75 @@ +package deployments + +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 WhatIfAtManagementGroupScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WhatIfOperationResult +} + +// WhatIfAtManagementGroupScope ... +func (c DeploymentsClient) WhatIfAtManagementGroupScope(ctx context.Context, id Providers2DeploymentId, input ScopedDeploymentWhatIf) (result WhatIfAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/whatIf", 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 +} + +// WhatIfAtManagementGroupScopeThenPoll performs WhatIfAtManagementGroupScope then polls until it's completed +func (c DeploymentsClient) WhatIfAtManagementGroupScopeThenPoll(ctx context.Context, id Providers2DeploymentId, input ScopedDeploymentWhatIf) error { + result, err := c.WhatIfAtManagementGroupScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WhatIfAtManagementGroupScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WhatIfAtManagementGroupScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_whatifatsubscriptionscope.go b/resource-manager/resources/2025-03-01/deployments/method_whatifatsubscriptionscope.go new file mode 100644 index 00000000000..edfb1588b32 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_whatifatsubscriptionscope.go @@ -0,0 +1,75 @@ +package deployments + +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 WhatIfAtSubscriptionScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WhatIfOperationResult +} + +// WhatIfAtSubscriptionScope ... +func (c DeploymentsClient) WhatIfAtSubscriptionScope(ctx context.Context, id ProviderDeploymentId, input DeploymentWhatIf) (result WhatIfAtSubscriptionScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/whatIf", 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 +} + +// WhatIfAtSubscriptionScopeThenPoll performs WhatIfAtSubscriptionScope then polls until it's completed +func (c DeploymentsClient) WhatIfAtSubscriptionScopeThenPoll(ctx context.Context, id ProviderDeploymentId, input DeploymentWhatIf) error { + result, err := c.WhatIfAtSubscriptionScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WhatIfAtSubscriptionScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WhatIfAtSubscriptionScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/method_whatifattenantscope.go b/resource-manager/resources/2025-03-01/deployments/method_whatifattenantscope.go new file mode 100644 index 00000000000..05a462f7296 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/method_whatifattenantscope.go @@ -0,0 +1,75 @@ +package deployments + +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 WhatIfAtTenantScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WhatIfOperationResult +} + +// WhatIfAtTenantScope ... +func (c DeploymentsClient) WhatIfAtTenantScope(ctx context.Context, id DeploymentId, input ScopedDeploymentWhatIf) (result WhatIfAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/whatIf", 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 +} + +// WhatIfAtTenantScopeThenPoll performs WhatIfAtTenantScope then polls until it's completed +func (c DeploymentsClient) WhatIfAtTenantScopeThenPoll(ctx context.Context, id DeploymentId, input ScopedDeploymentWhatIf) error { + result, err := c.WhatIfAtTenantScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WhatIfAtTenantScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WhatIfAtTenantScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_alias.go b/resource-manager/resources/2025-03-01/deployments/model_alias.go new file mode 100644 index 00000000000..c55805e3c88 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_alias.go @@ -0,0 +1,13 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Alias struct { + DefaultMetadata *AliasPathMetadata `json:"defaultMetadata,omitempty"` + DefaultPath *string `json:"defaultPath,omitempty"` + DefaultPattern *AliasPattern `json:"defaultPattern,omitempty"` + Name *string `json:"name,omitempty"` + Paths *[]AliasPath `json:"paths,omitempty"` + Type *AliasType `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_aliaspath.go b/resource-manager/resources/2025-03-01/deployments/model_aliaspath.go new file mode 100644 index 00000000000..4a917a6be54 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_aliaspath.go @@ -0,0 +1,11 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasPath struct { + ApiVersions *[]string `json:"apiVersions,omitempty"` + Metadata *AliasPathMetadata `json:"metadata,omitempty"` + Path *string `json:"path,omitempty"` + Pattern *AliasPattern `json:"pattern,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_aliaspathmetadata.go b/resource-manager/resources/2025-03-01/deployments/model_aliaspathmetadata.go new file mode 100644 index 00000000000..7931ef136ce --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_aliaspathmetadata.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasPathMetadata struct { + Attributes *AliasPathAttributes `json:"attributes,omitempty"` + Type *AliasPathTokenType `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_aliaspattern.go b/resource-manager/resources/2025-03-01/deployments/model_aliaspattern.go new file mode 100644 index 00000000000..e25948c5150 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_aliaspattern.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasPattern struct { + Phrase *string `json:"phrase,omitempty"` + Type *AliasPatternType `json:"type,omitempty"` + Variable *string `json:"variable,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_apiprofile.go b/resource-manager/resources/2025-03-01/deployments/model_apiprofile.go new file mode 100644 index 00000000000..98a975231b6 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_apiprofile.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiProfile struct { + ApiVersion *string `json:"apiVersion,omitempty"` + ProfileVersion *string `json:"profileVersion,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_basicdependency.go b/resource-manager/resources/2025-03-01/deployments/model_basicdependency.go new file mode 100644 index 00000000000..151f1c0247c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_basicdependency.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BasicDependency struct { + Id *string `json:"id,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_debugsetting.go b/resource-manager/resources/2025-03-01/deployments/model_debugsetting.go new file mode 100644 index 00000000000..8fb47092efd --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_debugsetting.go @@ -0,0 +1,8 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DebugSetting struct { + DetailLevel *string `json:"detailLevel,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_dependency.go b/resource-manager/resources/2025-03-01/deployments/model_dependency.go new file mode 100644 index 00000000000..e700824cc96 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_dependency.go @@ -0,0 +1,11 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Dependency struct { + DependsOn *[]BasicDependency `json:"dependsOn,omitempty"` + Id *string `json:"id,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deployment.go b/resource-manager/resources/2025-03-01/deployments/model_deployment.go new file mode 100644 index 00000000000..f874d9d4b85 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deployment.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Deployment struct { + Location *string `json:"location,omitempty"` + Properties DeploymentProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentdiagnosticsdefinition.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentdiagnosticsdefinition.go new file mode 100644 index 00000000000..8af4b61479a --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentdiagnosticsdefinition.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentDiagnosticsDefinition struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code string `json:"code"` + Level Level `json:"level"` + Message string `json:"message"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentexportresult.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentexportresult.go new file mode 100644 index 00000000000..fb66469962e --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentexportresult.go @@ -0,0 +1,8 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExportResult struct { + Template *interface{} `json:"template,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentextended.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentextended.go new file mode 100644 index 00000000000..5905f4b3f19 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentextended.go @@ -0,0 +1,13 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtended struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeploymentPropertiesExtended `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentextensionconfigitem.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentextensionconfigitem.go new file mode 100644 index 00000000000..069e1f9dbc5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentextensionconfigitem.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtensionConfigItem struct { + KeyVaultReference *KeyVaultParameterReference `json:"keyVaultReference,omitempty"` + Type *ExtensionConfigPropertyType `json:"type,omitempty"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentextensiondefinition.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentextensiondefinition.go new file mode 100644 index 00000000000..17e865059f5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentextensiondefinition.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtensionDefinition struct { + Alias *string `json:"alias,omitempty"` + Config *map[string]DeploymentExtensionConfigItem `json:"config,omitempty"` + ConfigId *string `json:"configId,omitempty"` + Name *string `json:"name,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentparameter.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentparameter.go new file mode 100644 index 00000000000..a1a66987f73 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentparameter.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentParameter struct { + Reference *KeyVaultParameterReference `json:"reference,omitempty"` + Value *interface{} `json:"value,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentproperties.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentproperties.go new file mode 100644 index 00000000000..4c27dcaddbf --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentproperties.go @@ -0,0 +1,17 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentProperties struct { + DebugSetting *DebugSetting `json:"debugSetting,omitempty"` + ExpressionEvaluationOptions *ExpressionEvaluationOptions `json:"expressionEvaluationOptions,omitempty"` + ExtensionConfigs *map[string]map[string]DeploymentExtensionConfigItem `json:"extensionConfigs,omitempty"` + Mode DeploymentMode `json:"mode"` + OnErrorDeployment *OnErrorDeployment `json:"onErrorDeployment,omitempty"` + Parameters *map[string]DeploymentParameter `json:"parameters,omitempty"` + ParametersLink *ParametersLink `json:"parametersLink,omitempty"` + Template *interface{} `json:"template,omitempty"` + TemplateLink *TemplateLink `json:"templateLink,omitempty"` + ValidationLevel *ValidationLevel `json:"validationLevel,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentpropertiesextended.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentpropertiesextended.go new file mode 100644 index 00000000000..c7625970c77 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentpropertiesextended.go @@ -0,0 +1,45 @@ +package deployments + +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 DeploymentPropertiesExtended struct { + CorrelationId *string `json:"correlationId,omitempty"` + DebugSetting *DebugSetting `json:"debugSetting,omitempty"` + Dependencies *[]Dependency `json:"dependencies,omitempty"` + Diagnostics *[]DeploymentDiagnosticsDefinition `json:"diagnostics,omitempty"` + Duration *string `json:"duration,omitempty"` + Error *ErrorResponse `json:"error,omitempty"` + Extensions *[]DeploymentExtensionDefinition `json:"extensions,omitempty"` + Mode *DeploymentMode `json:"mode,omitempty"` + OnErrorDeployment *OnErrorDeploymentExtended `json:"onErrorDeployment,omitempty"` + OutputResources *[]ResourceReference `json:"outputResources,omitempty"` + Outputs *interface{} `json:"outputs,omitempty"` + Parameters *interface{} `json:"parameters,omitempty"` + ParametersLink *ParametersLink `json:"parametersLink,omitempty"` + Providers *[]Provider `json:"providers,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + TemplateHash *string `json:"templateHash,omitempty"` + TemplateLink *TemplateLink `json:"templateLink,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + ValidatedResources *[]ResourceReference `json:"validatedResources,omitempty"` + ValidationLevel *ValidationLevel `json:"validationLevel,omitempty"` +} + +func (o *DeploymentPropertiesExtended) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeploymentPropertiesExtended) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentvalidateresult.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentvalidateresult.go new file mode 100644 index 00000000000..831b8215f1c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentvalidateresult.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentValidateResult struct { + Error *ErrorResponse `json:"error,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeploymentPropertiesExtended `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatif.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatif.go new file mode 100644 index 00000000000..bec24cb1803 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatif.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentWhatIf struct { + Location *string `json:"location,omitempty"` + Properties DeploymentWhatIfProperties `json:"properties"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifproperties.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifproperties.go new file mode 100644 index 00000000000..f67d4ac000c --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifproperties.go @@ -0,0 +1,18 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentWhatIfProperties struct { + DebugSetting *DebugSetting `json:"debugSetting,omitempty"` + ExpressionEvaluationOptions *ExpressionEvaluationOptions `json:"expressionEvaluationOptions,omitempty"` + ExtensionConfigs *map[string]map[string]DeploymentExtensionConfigItem `json:"extensionConfigs,omitempty"` + Mode DeploymentMode `json:"mode"` + OnErrorDeployment *OnErrorDeployment `json:"onErrorDeployment,omitempty"` + Parameters *map[string]DeploymentParameter `json:"parameters,omitempty"` + ParametersLink *ParametersLink `json:"parametersLink,omitempty"` + Template *interface{} `json:"template,omitempty"` + TemplateLink *TemplateLink `json:"templateLink,omitempty"` + ValidationLevel *ValidationLevel `json:"validationLevel,omitempty"` + WhatIfSettings *DeploymentWhatIfSettings `json:"whatIfSettings,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifsettings.go b/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifsettings.go new file mode 100644 index 00000000000..cc2e5cf314b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_deploymentwhatifsettings.go @@ -0,0 +1,8 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentWhatIfSettings struct { + ResultFormat *WhatIfResultFormat `json:"resultFormat,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_erroradditionalinfo.go b/resource-manager/resources/2025-03-01/deployments/model_erroradditionalinfo.go new file mode 100644 index 00000000000..79931ec15fa --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_errorresponse.go b/resource-manager/resources/2025-03-01/deployments/model_errorresponse.go new file mode 100644 index 00000000000..138e7832440 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_errorresponse.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorResponse struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorResponse `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_expressionevaluationoptions.go b/resource-manager/resources/2025-03-01/deployments/model_expressionevaluationoptions.go new file mode 100644 index 00000000000..da0fb0d9133 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_expressionevaluationoptions.go @@ -0,0 +1,8 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExpressionEvaluationOptions struct { + Scope *ExpressionEvaluationOptionsScopeType `json:"scope,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_keyvaultparameterreference.go b/resource-manager/resources/2025-03-01/deployments/model_keyvaultparameterreference.go new file mode 100644 index 00000000000..28f91567faf --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_keyvaultparameterreference.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultParameterReference struct { + KeyVault KeyVaultReference `json:"keyVault"` + SecretName string `json:"secretName"` + SecretVersion *string `json:"secretVersion,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_keyvaultreference.go b/resource-manager/resources/2025-03-01/deployments/model_keyvaultreference.go new file mode 100644 index 00000000000..b8ec27d1cdd --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_keyvaultreference.go @@ -0,0 +1,8 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultReference struct { + Id string `json:"id"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_onerrordeployment.go b/resource-manager/resources/2025-03-01/deployments/model_onerrordeployment.go new file mode 100644 index 00000000000..1b92aeb3bba --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_onerrordeployment.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OnErrorDeployment struct { + DeploymentName *string `json:"deploymentName,omitempty"` + Type *OnErrorDeploymentType `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_onerrordeploymentextended.go b/resource-manager/resources/2025-03-01/deployments/model_onerrordeploymentextended.go new file mode 100644 index 00000000000..74768b99898 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_onerrordeploymentextended.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OnErrorDeploymentExtended struct { + DeploymentName *string `json:"deploymentName,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Type *OnErrorDeploymentType `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_parameterslink.go b/resource-manager/resources/2025-03-01/deployments/model_parameterslink.go new file mode 100644 index 00000000000..a17ec8eadcc --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_parameterslink.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ParametersLink struct { + ContentVersion *string `json:"contentVersion,omitempty"` + Uri string `json:"uri"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_provider.go b/resource-manager/resources/2025-03-01/deployments/model_provider.go new file mode 100644 index 00000000000..2717de3ea16 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_provider.go @@ -0,0 +1,13 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Provider struct { + Id *string `json:"id,omitempty"` + Namespace *string `json:"namespace,omitempty"` + ProviderAuthorizationConsentState *ProviderAuthorizationConsentState `json:"providerAuthorizationConsentState,omitempty"` + RegistrationPolicy *string `json:"registrationPolicy,omitempty"` + RegistrationState *string `json:"registrationState,omitempty"` + ResourceTypes *[]ProviderResourceType `json:"resourceTypes,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_providerextendedlocation.go b/resource-manager/resources/2025-03-01/deployments/model_providerextendedlocation.go new file mode 100644 index 00000000000..62e438c4ed4 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_providerextendedlocation.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderExtendedLocation struct { + ExtendedLocations *[]string `json:"extendedLocations,omitempty"` + Location *string `json:"location,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_providerresourcetype.go b/resource-manager/resources/2025-03-01/deployments/model_providerresourcetype.go new file mode 100644 index 00000000000..3aff9438ce8 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_providerresourcetype.go @@ -0,0 +1,17 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderResourceType struct { + Aliases *[]Alias `json:"aliases,omitempty"` + ApiProfiles *[]ApiProfile `json:"apiProfiles,omitempty"` + ApiVersions *[]string `json:"apiVersions,omitempty"` + Capabilities *string `json:"capabilities,omitempty"` + DefaultApiVersion *string `json:"defaultApiVersion,omitempty"` + LocationMappings *[]ProviderExtendedLocation `json:"locationMappings,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ZoneMappings *[]ZoneMapping `json:"zoneMappings,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_resourcereference.go b/resource-manager/resources/2025-03-01/deployments/model_resourcereference.go new file mode 100644 index 00000000000..d04d7fedbae --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_resourcereference.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceReference struct { + ApiVersion *string `json:"apiVersion,omitempty"` + Extension *DeploymentExtensionDefinition `json:"extension,omitempty"` + Id *string `json:"id,omitempty"` + Identifiers *interface{} `json:"identifiers,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_scopeddeployment.go b/resource-manager/resources/2025-03-01/deployments/model_scopeddeployment.go new file mode 100644 index 00000000000..6b642f5463e --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_scopeddeployment.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopedDeployment struct { + Location string `json:"location"` + Properties DeploymentProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_scopeddeploymentwhatif.go b/resource-manager/resources/2025-03-01/deployments/model_scopeddeploymentwhatif.go new file mode 100644 index 00000000000..5adf7f7ab32 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_scopeddeploymentwhatif.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopedDeploymentWhatIf struct { + Location string `json:"location"` + Properties DeploymentWhatIfProperties `json:"properties"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_templatehashresult.go b/resource-manager/resources/2025-03-01/deployments/model_templatehashresult.go new file mode 100644 index 00000000000..baebdeb77e3 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_templatehashresult.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TemplateHashResult struct { + MinifiedTemplate *string `json:"minifiedTemplate,omitempty"` + TemplateHash *string `json:"templateHash,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_templatelink.go b/resource-manager/resources/2025-03-01/deployments/model_templatelink.go new file mode 100644 index 00000000000..1863df0b4d7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_templatelink.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TemplateLink struct { + ContentVersion *string `json:"contentVersion,omitempty"` + Id *string `json:"id,omitempty"` + QueryString *string `json:"queryString,omitempty"` + RelativePath *string `json:"relativePath,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_whatifchange.go b/resource-manager/resources/2025-03-01/deployments/model_whatifchange.go new file mode 100644 index 00000000000..d1adedfb6e8 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_whatifchange.go @@ -0,0 +1,16 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WhatIfChange struct { + After *interface{} `json:"after,omitempty"` + Before *interface{} `json:"before,omitempty"` + ChangeType ChangeType `json:"changeType"` + Delta *[]WhatIfPropertyChange `json:"delta,omitempty"` + DeploymentId *string `json:"deploymentId,omitempty"` + Identifiers *interface{} `json:"identifiers,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + SymbolicName *string `json:"symbolicName,omitempty"` + UnsupportedReason *string `json:"unsupportedReason,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_whatifoperationproperties.go b/resource-manager/resources/2025-03-01/deployments/model_whatifoperationproperties.go new file mode 100644 index 00000000000..bbd61334840 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_whatifoperationproperties.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WhatIfOperationProperties struct { + Changes *[]WhatIfChange `json:"changes,omitempty"` + Diagnostics *[]DeploymentDiagnosticsDefinition `json:"diagnostics,omitempty"` + PotentialChanges *[]WhatIfChange `json:"potentialChanges,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_whatifoperationresult.go b/resource-manager/resources/2025-03-01/deployments/model_whatifoperationresult.go new file mode 100644 index 00000000000..8e2a684870b --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_whatifoperationresult.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WhatIfOperationResult struct { + Error *ErrorResponse `json:"error,omitempty"` + Properties *WhatIfOperationProperties `json:"properties,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_whatifpropertychange.go b/resource-manager/resources/2025-03-01/deployments/model_whatifpropertychange.go new file mode 100644 index 00000000000..b440f5bef12 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_whatifpropertychange.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WhatIfPropertyChange struct { + After *interface{} `json:"after,omitempty"` + Before *interface{} `json:"before,omitempty"` + Children *[]WhatIfPropertyChange `json:"children,omitempty"` + Path string `json:"path"` + PropertyChangeType PropertyChangeType `json:"propertyChangeType"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/model_zonemapping.go b/resource-manager/resources/2025-03-01/deployments/model_zonemapping.go new file mode 100644 index 00000000000..2fdaf26f223 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/model_zonemapping.go @@ -0,0 +1,13 @@ +package deployments + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ZoneMapping struct { + Location *string `json:"location,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/deployments/predicates.go b/resource-manager/resources/2025-03-01/deployments/predicates.go new file mode 100644 index 00000000000..84e14eb0c22 --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/predicates.go @@ -0,0 +1,32 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtendedOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DeploymentExtendedOperationPredicate) Matches(input DeploymentExtended) 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/resources/2025-03-01/deployments/version.go b/resource-manager/resources/2025-03-01/deployments/version.go new file mode 100644 index 00000000000..93ca899784a --- /dev/null +++ b/resource-manager/resources/2025-03-01/deployments/version.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/deployments/2025-03-01" +} diff --git a/resource-manager/resources/2025-03-01/providers/README.md b/resource-manager/resources/2025-03-01/providers/README.md new file mode 100644 index 00000000000..f448d8b780d --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/README.md @@ -0,0 +1,174 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/providers` Documentation + +The `providers` SDK allows for interaction with Azure Resource Manager `resources` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/providers" +``` + + +### Client Initialization + +```go +client := providers.NewProvidersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProvidersClient.Get` + +```go +ctx := context.TODO() +id := providers.NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName") + +read, err := client.Get(ctx, id, providers.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProvidersClient.GetAtTenantScope` + +```go +ctx := context.TODO() +id := providers.NewProviderID("providerName") + +read, err := client.GetAtTenantScope(ctx, id, providers.DefaultGetAtTenantScopeOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProvidersClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, providers.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, providers.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProvidersClient.ListAtTenantScope` + +```go +ctx := context.TODO() + + +// alternatively `client.ListAtTenantScope(ctx, providers.DefaultListAtTenantScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListAtTenantScopeComplete(ctx, providers.DefaultListAtTenantScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProvidersClient.ProviderPermissions` + +```go +ctx := context.TODO() +id := providers.NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName") + +// alternatively `client.ProviderPermissions(ctx, id)` can be used to do batched pagination +items, err := client.ProviderPermissionsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProvidersClient.ProviderResourceTypesList` + +```go +ctx := context.TODO() +id := providers.NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName") + +// alternatively `client.ProviderResourceTypesList(ctx, id, providers.DefaultProviderResourceTypesListOperationOptions())` can be used to do batched pagination +items, err := client.ProviderResourceTypesListComplete(ctx, id, providers.DefaultProviderResourceTypesListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProvidersClient.Register` + +```go +ctx := context.TODO() +id := providers.NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName") + +payload := providers.ProviderRegistrationRequest{ + // ... +} + + +read, err := client.Register(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProvidersClient.RegisterAtManagementGroupScope` + +```go +ctx := context.TODO() +id := providers.NewProviders2ID("groupId", "providerName") + +read, err := client.RegisterAtManagementGroupScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProvidersClient.Unregister` + +```go +ctx := context.TODO() +id := providers.NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName") + +read, err := client.Unregister(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/resources/2025-03-01/providers/client.go b/resource-manager/resources/2025-03-01/providers/client.go new file mode 100644 index 00000000000..34b98302c9d --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/client.go @@ -0,0 +1,26 @@ +package providers + +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 ProvidersClient struct { + Client *resourcemanager.Client +} + +func NewProvidersClientWithBaseURI(sdkApi sdkEnv.Api) (*ProvidersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "providers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProvidersClient: %+v", err) + } + + return &ProvidersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2025-03-01/providers/constants.go b/resource-manager/resources/2025-03-01/providers/constants.go new file mode 100644 index 00000000000..39f123961bf --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/constants.go @@ -0,0 +1,242 @@ +package providers + +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 AliasPathAttributes string + +const ( + AliasPathAttributesModifiable AliasPathAttributes = "Modifiable" + AliasPathAttributesNone AliasPathAttributes = "None" +) + +func PossibleValuesForAliasPathAttributes() []string { + return []string{ + string(AliasPathAttributesModifiable), + string(AliasPathAttributesNone), + } +} + +func (s *AliasPathAttributes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasPathAttributes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasPathAttributes(input string) (*AliasPathAttributes, error) { + vals := map[string]AliasPathAttributes{ + "modifiable": AliasPathAttributesModifiable, + "none": AliasPathAttributesNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasPathAttributes(input) + return &out, nil +} + +type AliasPathTokenType string + +const ( + AliasPathTokenTypeAny AliasPathTokenType = "Any" + AliasPathTokenTypeArray AliasPathTokenType = "Array" + AliasPathTokenTypeBoolean AliasPathTokenType = "Boolean" + AliasPathTokenTypeInteger AliasPathTokenType = "Integer" + AliasPathTokenTypeNotSpecified AliasPathTokenType = "NotSpecified" + AliasPathTokenTypeNumber AliasPathTokenType = "Number" + AliasPathTokenTypeObject AliasPathTokenType = "Object" + AliasPathTokenTypeString AliasPathTokenType = "String" +) + +func PossibleValuesForAliasPathTokenType() []string { + return []string{ + string(AliasPathTokenTypeAny), + string(AliasPathTokenTypeArray), + string(AliasPathTokenTypeBoolean), + string(AliasPathTokenTypeInteger), + string(AliasPathTokenTypeNotSpecified), + string(AliasPathTokenTypeNumber), + string(AliasPathTokenTypeObject), + string(AliasPathTokenTypeString), + } +} + +func (s *AliasPathTokenType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasPathTokenType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasPathTokenType(input string) (*AliasPathTokenType, error) { + vals := map[string]AliasPathTokenType{ + "any": AliasPathTokenTypeAny, + "array": AliasPathTokenTypeArray, + "boolean": AliasPathTokenTypeBoolean, + "integer": AliasPathTokenTypeInteger, + "notspecified": AliasPathTokenTypeNotSpecified, + "number": AliasPathTokenTypeNumber, + "object": AliasPathTokenTypeObject, + "string": AliasPathTokenTypeString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasPathTokenType(input) + return &out, nil +} + +type AliasPatternType string + +const ( + AliasPatternTypeExtract AliasPatternType = "Extract" + AliasPatternTypeNotSpecified AliasPatternType = "NotSpecified" +) + +func PossibleValuesForAliasPatternType() []string { + return []string{ + string(AliasPatternTypeExtract), + string(AliasPatternTypeNotSpecified), + } +} + +func (s *AliasPatternType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasPatternType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasPatternType(input string) (*AliasPatternType, error) { + vals := map[string]AliasPatternType{ + "extract": AliasPatternTypeExtract, + "notspecified": AliasPatternTypeNotSpecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasPatternType(input) + return &out, nil +} + +type AliasType string + +const ( + AliasTypeMask AliasType = "Mask" + AliasTypeNotSpecified AliasType = "NotSpecified" + AliasTypePlainText AliasType = "PlainText" +) + +func PossibleValuesForAliasType() []string { + return []string{ + string(AliasTypeMask), + string(AliasTypeNotSpecified), + string(AliasTypePlainText), + } +} + +func (s *AliasType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAliasType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAliasType(input string) (*AliasType, error) { + vals := map[string]AliasType{ + "mask": AliasTypeMask, + "notspecified": AliasTypeNotSpecified, + "plaintext": AliasTypePlainText, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AliasType(input) + return &out, nil +} + +type ProviderAuthorizationConsentState string + +const ( + ProviderAuthorizationConsentStateConsented ProviderAuthorizationConsentState = "Consented" + ProviderAuthorizationConsentStateNotRequired ProviderAuthorizationConsentState = "NotRequired" + ProviderAuthorizationConsentStateNotSpecified ProviderAuthorizationConsentState = "NotSpecified" + ProviderAuthorizationConsentStateRequired ProviderAuthorizationConsentState = "Required" +) + +func PossibleValuesForProviderAuthorizationConsentState() []string { + return []string{ + string(ProviderAuthorizationConsentStateConsented), + string(ProviderAuthorizationConsentStateNotRequired), + string(ProviderAuthorizationConsentStateNotSpecified), + string(ProviderAuthorizationConsentStateRequired), + } +} + +func (s *ProviderAuthorizationConsentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProviderAuthorizationConsentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProviderAuthorizationConsentState(input string) (*ProviderAuthorizationConsentState, error) { + vals := map[string]ProviderAuthorizationConsentState{ + "consented": ProviderAuthorizationConsentStateConsented, + "notrequired": ProviderAuthorizationConsentStateNotRequired, + "notspecified": ProviderAuthorizationConsentStateNotSpecified, + "required": ProviderAuthorizationConsentStateRequired, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProviderAuthorizationConsentState(input) + return &out, nil +} diff --git a/resource-manager/resources/2025-03-01/providers/id_provider.go b/resource-manager/resources/2025-03-01/providers/id_provider.go new file mode 100644 index 00000000000..71544793e1f --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/id_provider.go @@ -0,0 +1,110 @@ +package providers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderId{}) +} + +var _ resourceids.ResourceId = &ProviderId{} + +// ProviderId is a struct representing the Resource ID for a Provider +type ProviderId struct { + ProviderName string +} + +// NewProviderID returns a new ProviderId struct +func NewProviderID(providerName string) ProviderId { + return ProviderId{ + ProviderName: providerName, + } +} + +// ParseProviderID parses 'input' into a ProviderId +func ParseProviderID(input string) (*ProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderIDInsensitively parses 'input' case-insensitively into a ProviderId +// note: this method should only be used for API response data and not user input +func ParseProviderIDInsensitively(input string) (*ProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ProviderName, ok = input.Parsed["providerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "providerName", input) + } + + return nil +} + +// ValidateProviderID checks that 'input' can be parsed as a Provider ID +func ValidateProviderID(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 := ParseProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider ID +func (id ProviderId) ID() string { + fmtString := "/providers/%s" + return fmt.Sprintf(fmtString, id.ProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider ID +func (id ProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.UserSpecifiedSegment("providerName", "providerName"), + } +} + +// String returns a human-readable description of this Provider ID +func (id ProviderId) String() string { + components := []string{ + fmt.Sprintf("Provider Name: %q", id.ProviderName), + } + return fmt.Sprintf("Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/providers/id_provider_test.go b/resource-manager/resources/2025-03-01/providers/id_provider_test.go new file mode 100644 index 00000000000..262553688e3 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/id_provider_test.go @@ -0,0 +1,162 @@ +package providers + +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 = &ProviderId{} + +func TestNewProviderID(t *testing.T) { + id := NewProviderID("providerName") + + if id.ProviderName != "providerName" { + t.Fatalf("Expected %q but got %q for Segment 'ProviderName'", id.ProviderName, "providerName") + } +} + +func TestFormatProviderID(t *testing.T) { + actual := NewProviderID("providerName").ID() + expected := "/providers/providerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Valid URI + Input: "/providers/providerName", + Expected: &ProviderId{ + ProviderName: "providerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/providerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderID(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.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestParseProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/providerName", + Expected: &ProviderId{ + ProviderName: "providerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/providerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/pRoViDeRnAmE", + Expected: &ProviderId{ + ProviderName: "pRoViDeRnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/pRoViDeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderIDInsensitively(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.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestSegmentsForProviderId(t *testing.T) { + segments := ProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderId 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/resources/2025-03-01/providers/id_providers2.go b/resource-manager/resources/2025-03-01/providers/id_providers2.go new file mode 100644 index 00000000000..6236a5adf0c --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/id_providers2.go @@ -0,0 +1,121 @@ +package providers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&Providers2Id{}) +} + +var _ resourceids.ResourceId = &Providers2Id{} + +// Providers2Id is a struct representing the Resource ID for a Providers 2 +type Providers2Id struct { + GroupId string + ProviderName string +} + +// NewProviders2ID returns a new Providers2Id struct +func NewProviders2ID(groupId string, providerName string) Providers2Id { + return Providers2Id{ + GroupId: groupId, + ProviderName: providerName, + } +} + +// ParseProviders2ID parses 'input' into a Providers2Id +func ParseProviders2ID(input string) (*Providers2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2Id{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2Id{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviders2IDInsensitively parses 'input' case-insensitively into a Providers2Id +// note: this method should only be used for API response data and not user input +func ParseProviders2IDInsensitively(input string) (*Providers2Id, error) { + parser := resourceids.NewParserFromResourceIdType(&Providers2Id{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := Providers2Id{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *Providers2Id) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.GroupId, ok = input.Parsed["groupId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "groupId", input) + } + + if id.ProviderName, ok = input.Parsed["providerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "providerName", input) + } + + return nil +} + +// ValidateProviders2ID checks that 'input' can be parsed as a Providers 2 ID +func ValidateProviders2ID(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 := ParseProviders2ID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Providers 2 ID +func (id Providers2Id) ID() string { + fmtString := "/providers/Microsoft.Management/managementGroups/%s/providers/%s" + return fmt.Sprintf(fmtString, id.GroupId, id.ProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Providers 2 ID +func (id Providers2Id) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.StaticSegment("staticManagementGroups", "managementGroups", "managementGroups"), + resourceids.UserSpecifiedSegment("groupId", "groupId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.UserSpecifiedSegment("providerName", "providerName"), + } +} + +// String returns a human-readable description of this Providers 2 ID +func (id Providers2Id) String() string { + components := []string{ + fmt.Sprintf("Group: %q", id.GroupId), + fmt.Sprintf("Provider Name: %q", id.ProviderName), + } + return fmt.Sprintf("Providers 2 (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/providers/id_providers2_test.go b/resource-manager/resources/2025-03-01/providers/id_providers2_test.go new file mode 100644 index 00000000000..cc31c332e6e --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/id_providers2_test.go @@ -0,0 +1,237 @@ +package providers + +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 = &Providers2Id{} + +func TestNewProviders2ID(t *testing.T) { + id := NewProviders2ID("groupId", "providerName") + + if id.GroupId != "groupId" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupId") + } + + if id.ProviderName != "providerName" { + t.Fatalf("Expected %q but got %q for Segment 'ProviderName'", id.ProviderName, "providerName") + } +} + +func TestFormatProviders2ID(t *testing.T) { + actual := NewProviders2ID("groupId", "providerName").ID() + expected := "/providers/Microsoft.Management/managementGroups/groupId/providers/providerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviders2ID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/providerName", + Expected: &Providers2Id{ + GroupId: "groupId", + ProviderName: "providerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/providerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2ID(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestParseProviders2IDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *Providers2Id + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/providerName", + Expected: &Providers2Id{ + GroupId: "groupId", + ProviderName: "providerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Management/managementGroups/groupId/providers/providerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/pRoViDeRnAmE", + Expected: &Providers2Id{ + GroupId: "gRoUpId", + ProviderName: "pRoViDeRnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.mAnAgEmEnT/mAnAgEmEnTgRoUpS/gRoUpId/pRoViDeRs/pRoViDeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviders2IDInsensitively(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.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + if actual.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestSegmentsForProviders2Id(t *testing.T) { + segments := Providers2Id{}.Segments() + if len(segments) == 0 { + t.Fatalf("Providers2Id 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/resources/2025-03-01/providers/id_subscriptionprovider.go b/resource-manager/resources/2025-03-01/providers/id_subscriptionprovider.go new file mode 100644 index 00000000000..4ba6dbab693 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/id_subscriptionprovider.go @@ -0,0 +1,119 @@ +package providers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SubscriptionProviderId{}) +} + +var _ resourceids.ResourceId = &SubscriptionProviderId{} + +// SubscriptionProviderId is a struct representing the Resource ID for a Subscription Provider +type SubscriptionProviderId struct { + SubscriptionId string + ProviderName string +} + +// NewSubscriptionProviderID returns a new SubscriptionProviderId struct +func NewSubscriptionProviderID(subscriptionId string, providerName string) SubscriptionProviderId { + return SubscriptionProviderId{ + SubscriptionId: subscriptionId, + ProviderName: providerName, + } +} + +// ParseSubscriptionProviderID parses 'input' into a SubscriptionProviderId +func ParseSubscriptionProviderID(input string) (*SubscriptionProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&SubscriptionProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SubscriptionProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSubscriptionProviderIDInsensitively parses 'input' case-insensitively into a SubscriptionProviderId +// note: this method should only be used for API response data and not user input +func ParseSubscriptionProviderIDInsensitively(input string) (*SubscriptionProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&SubscriptionProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SubscriptionProviderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SubscriptionProviderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ProviderName, ok = input.Parsed["providerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "providerName", input) + } + + return nil +} + +// ValidateSubscriptionProviderID checks that 'input' can be parsed as a Subscription Provider ID +func ValidateSubscriptionProviderID(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 := ParseSubscriptionProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Subscription Provider ID +func (id SubscriptionProviderId) ID() string { + fmtString := "/subscriptions/%s/providers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Subscription Provider ID +func (id SubscriptionProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.UserSpecifiedSegment("providerName", "providerName"), + } +} + +// String returns a human-readable description of this Subscription Provider ID +func (id SubscriptionProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Provider Name: %q", id.ProviderName), + } + return fmt.Sprintf("Subscription Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/providers/id_subscriptionprovider_test.go b/resource-manager/resources/2025-03-01/providers/id_subscriptionprovider_test.go new file mode 100644 index 00000000000..a9ca5cba7d0 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/id_subscriptionprovider_test.go @@ -0,0 +1,207 @@ +package providers + +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 = &SubscriptionProviderId{} + +func TestNewSubscriptionProviderID(t *testing.T) { + id := NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName") + + 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.ProviderName != "providerName" { + t.Fatalf("Expected %q but got %q for Segment 'ProviderName'", id.ProviderName, "providerName") + } +} + +func TestFormatSubscriptionProviderID(t *testing.T) { + actual := NewSubscriptionProviderID("12345678-1234-9876-4563-123456789012", "providerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSubscriptionProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerName", + Expected: &SubscriptionProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ProviderName: "providerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptionProviderID(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.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestParseSubscriptionProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SubscriptionProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerName", + Expected: &SubscriptionProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ProviderName: "providerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/pRoViDeRnAmE", + Expected: &SubscriptionProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ProviderName: "pRoViDeRnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/pRoViDeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSubscriptionProviderIDInsensitively(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.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestSegmentsForSubscriptionProviderId(t *testing.T) { + segments := SubscriptionProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SubscriptionProviderId 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/resources/2025-03-01/providers/method_get.go b/resource-manager/resources/2025-03-01/providers/method_get.go new file mode 100644 index 00000000000..2a780770db9 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_get.go @@ -0,0 +1,83 @@ +package providers + +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 *Provider +} + +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 ProvidersClient) Get(ctx context.Context, id SubscriptionProviderId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 Provider + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_getattenantscope.go b/resource-manager/resources/2025-03-01/providers/method_getattenantscope.go new file mode 100644 index 00000000000..18fae99a5b5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_getattenantscope.go @@ -0,0 +1,83 @@ +package providers + +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 GetAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Provider +} + +type GetAtTenantScopeOperationOptions struct { + Expand *string +} + +func DefaultGetAtTenantScopeOperationOptions() GetAtTenantScopeOperationOptions { + return GetAtTenantScopeOperationOptions{} +} + +func (o GetAtTenantScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetAtTenantScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o GetAtTenantScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// GetAtTenantScope ... +func (c ProvidersClient) GetAtTenantScope(ctx context.Context, id ProviderId, options GetAtTenantScopeOperationOptions) (result GetAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 Provider + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_list.go b/resource-manager/resources/2025-03-01/providers/method_list.go new file mode 100644 index 00000000000..d255799a080 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_list.go @@ -0,0 +1,135 @@ +package providers + +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 *[]Provider +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Provider +} + +type ListOperationOptions struct { + Expand *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ProvidersClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers", 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 *[]Provider `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 ProvidersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProviderOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProvidersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ProviderOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Provider, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_listattenantscope.go b/resource-manager/resources/2025-03-01/providers/method_listattenantscope.go new file mode 100644 index 00000000000..6f2329165f2 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_listattenantscope.go @@ -0,0 +1,134 @@ +package providers + +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 ListAtTenantScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Provider +} + +type ListAtTenantScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []Provider +} + +type ListAtTenantScopeOperationOptions struct { + Expand *string +} + +func DefaultListAtTenantScopeOperationOptions() ListAtTenantScopeOperationOptions { + return ListAtTenantScopeOperationOptions{} +} + +func (o ListAtTenantScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListAtTenantScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListAtTenantScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListAtTenantScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListAtTenantScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListAtTenantScope ... +func (c ProvidersClient) ListAtTenantScope(ctx context.Context, options ListAtTenantScopeOperationOptions) (result ListAtTenantScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListAtTenantScopeCustomPager{}, + Path: "/providers", + } + + 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 *[]Provider `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAtTenantScopeComplete retrieves all the results into a single object +func (c ProvidersClient) ListAtTenantScopeComplete(ctx context.Context, options ListAtTenantScopeOperationOptions) (ListAtTenantScopeCompleteResult, error) { + return c.ListAtTenantScopeCompleteMatchingPredicate(ctx, options, ProviderOperationPredicate{}) +} + +// ListAtTenantScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProvidersClient) ListAtTenantScopeCompleteMatchingPredicate(ctx context.Context, options ListAtTenantScopeOperationOptions, predicate ProviderOperationPredicate) (result ListAtTenantScopeCompleteResult, err error) { + items := make([]Provider, 0) + + resp, err := c.ListAtTenantScope(ctx, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListAtTenantScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_providerpermissions.go b/resource-manager/resources/2025-03-01/providers/method_providerpermissions.go new file mode 100644 index 00000000000..febf3c1a058 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_providerpermissions.go @@ -0,0 +1,105 @@ +package providers + +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 ProviderPermissionsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProviderPermission +} + +type ProviderPermissionsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProviderPermission +} + +type ProviderPermissionsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ProviderPermissionsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ProviderPermissions ... +func (c ProvidersClient) ProviderPermissions(ctx context.Context, id SubscriptionProviderId) (result ProviderPermissionsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ProviderPermissionsCustomPager{}, + Path: fmt.Sprintf("%s/providerPermissions", 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 *[]ProviderPermission `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProviderPermissionsComplete retrieves all the results into a single object +func (c ProvidersClient) ProviderPermissionsComplete(ctx context.Context, id SubscriptionProviderId) (ProviderPermissionsCompleteResult, error) { + return c.ProviderPermissionsCompleteMatchingPredicate(ctx, id, ProviderPermissionOperationPredicate{}) +} + +// ProviderPermissionsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProvidersClient) ProviderPermissionsCompleteMatchingPredicate(ctx context.Context, id SubscriptionProviderId, predicate ProviderPermissionOperationPredicate) (result ProviderPermissionsCompleteResult, err error) { + items := make([]ProviderPermission, 0) + + resp, err := c.ProviderPermissions(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProviderPermissionsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_providerresourcetypeslist.go b/resource-manager/resources/2025-03-01/providers/method_providerresourcetypeslist.go new file mode 100644 index 00000000000..f126b5fe436 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_providerresourcetypeslist.go @@ -0,0 +1,134 @@ +package providers + +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 ProviderResourceTypesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProviderResourceType +} + +type ProviderResourceTypesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProviderResourceType +} + +type ProviderResourceTypesListOperationOptions struct { + Expand *string +} + +func DefaultProviderResourceTypesListOperationOptions() ProviderResourceTypesListOperationOptions { + return ProviderResourceTypesListOperationOptions{} +} + +func (o ProviderResourceTypesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProviderResourceTypesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ProviderResourceTypesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ProviderResourceTypesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ProviderResourceTypesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ProviderResourceTypesList ... +func (c ProvidersClient) ProviderResourceTypesList(ctx context.Context, id SubscriptionProviderId, options ProviderResourceTypesListOperationOptions) (result ProviderResourceTypesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ProviderResourceTypesListCustomPager{}, + Path: fmt.Sprintf("%s/resourceTypes", 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 *[]ProviderResourceType `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProviderResourceTypesListComplete retrieves all the results into a single object +func (c ProvidersClient) ProviderResourceTypesListComplete(ctx context.Context, id SubscriptionProviderId, options ProviderResourceTypesListOperationOptions) (ProviderResourceTypesListCompleteResult, error) { + return c.ProviderResourceTypesListCompleteMatchingPredicate(ctx, id, options, ProviderResourceTypeOperationPredicate{}) +} + +// ProviderResourceTypesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProvidersClient) ProviderResourceTypesListCompleteMatchingPredicate(ctx context.Context, id SubscriptionProviderId, options ProviderResourceTypesListOperationOptions, predicate ProviderResourceTypeOperationPredicate) (result ProviderResourceTypesListCompleteResult, err error) { + items := make([]ProviderResourceType, 0) + + resp, err := c.ProviderResourceTypesList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProviderResourceTypesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_register.go b/resource-manager/resources/2025-03-01/providers/method_register.go new file mode 100644 index 00000000000..11d8a56a107 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_register.go @@ -0,0 +1,58 @@ +package providers + +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 RegisterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Provider +} + +// Register ... +func (c ProvidersClient) Register(ctx context.Context, id SubscriptionProviderId, input ProviderRegistrationRequest) (result RegisterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/register", 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 Provider + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_registeratmanagementgroupscope.go b/resource-manager/resources/2025-03-01/providers/method_registeratmanagementgroupscope.go new file mode 100644 index 00000000000..d699e9f835a --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_registeratmanagementgroupscope.go @@ -0,0 +1,47 @@ +package providers + +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 RegisterAtManagementGroupScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RegisterAtManagementGroupScope ... +func (c ProvidersClient) RegisterAtManagementGroupScope(ctx context.Context, id Providers2Id) (result RegisterAtManagementGroupScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/register", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/providers/method_unregister.go b/resource-manager/resources/2025-03-01/providers/method_unregister.go new file mode 100644 index 00000000000..02cd514d18a --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/method_unregister.go @@ -0,0 +1,54 @@ +package providers + +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 UnregisterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Provider +} + +// Unregister ... +func (c ProvidersClient) Unregister(ctx context.Context, id SubscriptionProviderId) (result UnregisterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/unregister", 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 Provider + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/providers/model_alias.go b/resource-manager/resources/2025-03-01/providers/model_alias.go new file mode 100644 index 00000000000..c5310c681b4 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_alias.go @@ -0,0 +1,13 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Alias struct { + DefaultMetadata *AliasPathMetadata `json:"defaultMetadata,omitempty"` + DefaultPath *string `json:"defaultPath,omitempty"` + DefaultPattern *AliasPattern `json:"defaultPattern,omitempty"` + Name *string `json:"name,omitempty"` + Paths *[]AliasPath `json:"paths,omitempty"` + Type *AliasType `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_aliaspath.go b/resource-manager/resources/2025-03-01/providers/model_aliaspath.go new file mode 100644 index 00000000000..56135bfcb6d --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_aliaspath.go @@ -0,0 +1,11 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasPath struct { + ApiVersions *[]string `json:"apiVersions,omitempty"` + Metadata *AliasPathMetadata `json:"metadata,omitempty"` + Path *string `json:"path,omitempty"` + Pattern *AliasPattern `json:"pattern,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_aliaspathmetadata.go b/resource-manager/resources/2025-03-01/providers/model_aliaspathmetadata.go new file mode 100644 index 00000000000..2c61145cb3b --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_aliaspathmetadata.go @@ -0,0 +1,9 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasPathMetadata struct { + Attributes *AliasPathAttributes `json:"attributes,omitempty"` + Type *AliasPathTokenType `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_aliaspattern.go b/resource-manager/resources/2025-03-01/providers/model_aliaspattern.go new file mode 100644 index 00000000000..cd67c3d713a --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_aliaspattern.go @@ -0,0 +1,10 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AliasPattern struct { + Phrase *string `json:"phrase,omitempty"` + Type *AliasPatternType `json:"type,omitempty"` + Variable *string `json:"variable,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_apiprofile.go b/resource-manager/resources/2025-03-01/providers/model_apiprofile.go new file mode 100644 index 00000000000..cd402753bfc --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_apiprofile.go @@ -0,0 +1,9 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiProfile struct { + ApiVersion *string `json:"apiVersion,omitempty"` + ProfileVersion *string `json:"profileVersion,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_permission.go b/resource-manager/resources/2025-03-01/providers/model_permission.go new file mode 100644 index 00000000000..1ef9d80d6b6 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_permission.go @@ -0,0 +1,11 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Permission struct { + Actions *[]string `json:"actions,omitempty"` + DataActions *[]string `json:"dataActions,omitempty"` + NotActions *[]string `json:"notActions,omitempty"` + NotDataActions *[]string `json:"notDataActions,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_provider.go b/resource-manager/resources/2025-03-01/providers/model_provider.go new file mode 100644 index 00000000000..2f14f379d95 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_provider.go @@ -0,0 +1,13 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Provider struct { + Id *string `json:"id,omitempty"` + Namespace *string `json:"namespace,omitempty"` + ProviderAuthorizationConsentState *ProviderAuthorizationConsentState `json:"providerAuthorizationConsentState,omitempty"` + RegistrationPolicy *string `json:"registrationPolicy,omitempty"` + RegistrationState *string `json:"registrationState,omitempty"` + ResourceTypes *[]ProviderResourceType `json:"resourceTypes,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_providerconsentdefinition.go b/resource-manager/resources/2025-03-01/providers/model_providerconsentdefinition.go new file mode 100644 index 00000000000..9d720d4eded --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_providerconsentdefinition.go @@ -0,0 +1,8 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderConsentDefinition struct { + ConsentToAuthorization *bool `json:"consentToAuthorization,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_providerextendedlocation.go b/resource-manager/resources/2025-03-01/providers/model_providerextendedlocation.go new file mode 100644 index 00000000000..4b8d25ac023 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_providerextendedlocation.go @@ -0,0 +1,10 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderExtendedLocation struct { + ExtendedLocations *[]string `json:"extendedLocations,omitempty"` + Location *string `json:"location,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_providerpermission.go b/resource-manager/resources/2025-03-01/providers/model_providerpermission.go new file mode 100644 index 00000000000..2c50f300e50 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_providerpermission.go @@ -0,0 +1,11 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderPermission struct { + ApplicationId *string `json:"applicationId,omitempty"` + ManagedByRoleDefinition *RoleDefinition `json:"managedByRoleDefinition,omitempty"` + ProviderAuthorizationConsentState *ProviderAuthorizationConsentState `json:"providerAuthorizationConsentState,omitempty"` + RoleDefinition *RoleDefinition `json:"roleDefinition,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_providerregistrationrequest.go b/resource-manager/resources/2025-03-01/providers/model_providerregistrationrequest.go new file mode 100644 index 00000000000..43935de225e --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_providerregistrationrequest.go @@ -0,0 +1,8 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderRegistrationRequest struct { + ThirdPartyProviderConsent *ProviderConsentDefinition `json:"thirdPartyProviderConsent,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_providerresourcetype.go b/resource-manager/resources/2025-03-01/providers/model_providerresourcetype.go new file mode 100644 index 00000000000..fa3f581d7cb --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_providerresourcetype.go @@ -0,0 +1,17 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderResourceType struct { + Aliases *[]Alias `json:"aliases,omitempty"` + ApiProfiles *[]ApiProfile `json:"apiProfiles,omitempty"` + ApiVersions *[]string `json:"apiVersions,omitempty"` + Capabilities *string `json:"capabilities,omitempty"` + DefaultApiVersion *string `json:"defaultApiVersion,omitempty"` + LocationMappings *[]ProviderExtendedLocation `json:"locationMappings,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + ZoneMappings *[]ZoneMapping `json:"zoneMappings,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_roledefinition.go b/resource-manager/resources/2025-03-01/providers/model_roledefinition.go new file mode 100644 index 00000000000..a4a432ddaf8 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_roledefinition.go @@ -0,0 +1,12 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RoleDefinition struct { + Id *string `json:"id,omitempty"` + IsServiceRole *bool `json:"isServiceRole,omitempty"` + Name *string `json:"name,omitempty"` + Permissions *[]Permission `json:"permissions,omitempty"` + Scopes *[]string `json:"scopes,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/model_zonemapping.go b/resource-manager/resources/2025-03-01/providers/model_zonemapping.go new file mode 100644 index 00000000000..d491263d1fd --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/model_zonemapping.go @@ -0,0 +1,13 @@ +package providers + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ZoneMapping struct { + Location *string `json:"location,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/providers/predicates.go b/resource-manager/resources/2025-03-01/providers/predicates.go new file mode 100644 index 00000000000..e0ba3ce5f06 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/predicates.go @@ -0,0 +1,68 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderOperationPredicate struct { + Id *string + Namespace *string + RegistrationPolicy *string + RegistrationState *string +} + +func (p ProviderOperationPredicate) Matches(input Provider) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Namespace != nil && (input.Namespace == nil || *p.Namespace != *input.Namespace) { + return false + } + + if p.RegistrationPolicy != nil && (input.RegistrationPolicy == nil || *p.RegistrationPolicy != *input.RegistrationPolicy) { + return false + } + + if p.RegistrationState != nil && (input.RegistrationState == nil || *p.RegistrationState != *input.RegistrationState) { + return false + } + + return true +} + +type ProviderPermissionOperationPredicate struct { + ApplicationId *string +} + +func (p ProviderPermissionOperationPredicate) Matches(input ProviderPermission) bool { + + if p.ApplicationId != nil && (input.ApplicationId == nil || *p.ApplicationId != *input.ApplicationId) { + return false + } + + return true +} + +type ProviderResourceTypeOperationPredicate struct { + Capabilities *string + DefaultApiVersion *string + ResourceType *string +} + +func (p ProviderResourceTypeOperationPredicate) Matches(input ProviderResourceType) bool { + + if p.Capabilities != nil && (input.Capabilities == nil || *p.Capabilities != *input.Capabilities) { + return false + } + + if p.DefaultApiVersion != nil && (input.DefaultApiVersion == nil || *p.DefaultApiVersion != *input.DefaultApiVersion) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/resource-manager/resources/2025-03-01/providers/version.go b/resource-manager/resources/2025-03-01/providers/version.go new file mode 100644 index 00000000000..cb2293003a7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/providers/version.go @@ -0,0 +1,10 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/providers/2025-03-01" +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/README.md b/resource-manager/resources/2025-03-01/resourcegroups/README.md new file mode 100644 index 00000000000..0e2ddd8eccf --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/README.md @@ -0,0 +1,158 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/resourcegroups` Documentation + +The `resourcegroups` SDK allows for interaction with Azure Resource Manager `resources` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/resourcegroups" +``` + + +### Client Initialization + +```go +client := resourcegroups.NewResourceGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceGroupsClient.CheckExistence` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +read, err := client.CheckExistence(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resourcegroups.ResourceGroup{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGroupsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +if err := client.DeleteThenPoll(ctx, id, resourcegroups.DefaultDeleteOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourceGroupsClient.ExportTemplate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resourcegroups.ExportTemplateRequest{ + // ... +} + + +if err := client.ExportTemplateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourceGroupsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +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: `ResourceGroupsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, resourcegroups.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, resourcegroups.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGroupsClient.ResourcesListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ResourcesListByResourceGroup(ctx, id, resourcegroups.DefaultResourcesListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ResourcesListByResourceGroupComplete(ctx, id, resourcegroups.DefaultResourcesListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGroupsClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resourcegroups.ResourceGroupPatchable{ + // ... +} + + +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/resources/2025-03-01/resourcegroups/client.go b/resource-manager/resources/2025-03-01/resourcegroups/client.go new file mode 100644 index 00000000000..770fb5d71d9 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/client.go @@ -0,0 +1,26 @@ +package resourcegroups + +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 ResourceGroupsClient struct { + Client *resourcemanager.Client +} + +func NewResourceGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourceGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "resourcegroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourceGroupsClient: %+v", err) + } + + return &ResourceGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/constants.go b/resource-manager/resources/2025-03-01/resourcegroups/constants.go new file mode 100644 index 00000000000..73df2116684 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/constants.go @@ -0,0 +1,51 @@ +package resourcegroups + +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 ExportTemplateOutputFormat string + +const ( + ExportTemplateOutputFormatBicep ExportTemplateOutputFormat = "Bicep" + ExportTemplateOutputFormatJson ExportTemplateOutputFormat = "Json" +) + +func PossibleValuesForExportTemplateOutputFormat() []string { + return []string{ + string(ExportTemplateOutputFormatBicep), + string(ExportTemplateOutputFormatJson), + } +} + +func (s *ExportTemplateOutputFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExportTemplateOutputFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExportTemplateOutputFormat(input string) (*ExportTemplateOutputFormat, error) { + vals := map[string]ExportTemplateOutputFormat{ + "bicep": ExportTemplateOutputFormatBicep, + "json": ExportTemplateOutputFormatJson, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExportTemplateOutputFormat(input) + return &out, nil +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_checkexistence.go b/resource-manager/resources/2025-03-01/resourcegroups/method_checkexistence.go new file mode 100644 index 00000000000..18ba2870e19 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_checkexistence.go @@ -0,0 +1,47 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckExistenceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistence ... +func (c ResourceGroupsClient) CheckExistence(ctx context.Context, id commonids.ResourceGroupId) (result CheckExistenceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_createorupdate.go b/resource-manager/resources/2025-03-01/resourcegroups/method_createorupdate.go new file mode 100644 index 00000000000..6b7f26d9e02 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_createorupdate.go @@ -0,0 +1,59 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGroup +} + +// CreateOrUpdate ... +func (c ResourceGroupsClient) CreateOrUpdate(ctx context.Context, id commonids.ResourceGroupId, input ResourceGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ResourceGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_delete.go b/resource-manager/resources/2025-03-01/resourcegroups/method_delete.go new file mode 100644 index 00000000000..7b9b6b4ff48 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_delete.go @@ -0,0 +1,100 @@ +package resourcegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + ForceDeletionTypes *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ForceDeletionTypes != nil { + out.Append("forceDeletionTypes", fmt.Sprintf("%v", *o.ForceDeletionTypes)) + } + return &out +} + +// Delete ... +func (c ResourceGroupsClient) Delete(ctx context.Context, id commonids.ResourceGroupId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + 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 ResourceGroupsClient) DeleteThenPoll(ctx context.Context, id commonids.ResourceGroupId, options DeleteOperationOptions) error { + result, err := c.Delete(ctx, id, options) + 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/resources/2025-03-01/resourcegroups/method_exporttemplate.go b/resource-manager/resources/2025-03-01/resourcegroups/method_exporttemplate.go new file mode 100644 index 00000000000..87b120fa03a --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_exporttemplate.go @@ -0,0 +1,76 @@ +package resourcegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportTemplateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGroupExportResult +} + +// ExportTemplate ... +func (c ResourceGroupsClient) ExportTemplate(ctx context.Context, id commonids.ResourceGroupId, input ExportTemplateRequest) (result ExportTemplateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/exportTemplate", 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 +} + +// ExportTemplateThenPoll performs ExportTemplate then polls until it's completed +func (c ResourceGroupsClient) ExportTemplateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input ExportTemplateRequest) error { + result, err := c.ExportTemplate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ExportTemplate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ExportTemplate: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_get.go b/resource-manager/resources/2025-03-01/resourcegroups/method_get.go new file mode 100644 index 00000000000..0a805dd40e2 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_get.go @@ -0,0 +1,54 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGroup +} + +// Get ... +func (c ResourceGroupsClient) Get(ctx context.Context, id commonids.ResourceGroupId) (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 ResourceGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_list.go b/resource-manager/resources/2025-03-01/resourcegroups/method_list.go new file mode 100644 index 00000000000..d78f8e8818d --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_list.go @@ -0,0 +1,139 @@ +package resourcegroups + +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 *[]ResourceGroup +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceGroup +} + +type ListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ResourceGroupsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/resourceGroups", 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 *[]ResourceGroup `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 ResourceGroupsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ResourceGroupOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGroupsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ResourceGroupOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ResourceGroup, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_resourceslistbyresourcegroup.go b/resource-manager/resources/2025-03-01/resourcegroups/method_resourceslistbyresourcegroup.go new file mode 100644 index 00000000000..fc72e1e6ea6 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_resourceslistbyresourcegroup.go @@ -0,0 +1,143 @@ +package resourcegroups + +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 ResourcesListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GenericResourceExpanded +} + +type ResourcesListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []GenericResourceExpanded +} + +type ResourcesListByResourceGroupOperationOptions struct { + Expand *string + Filter *string + Top *int64 +} + +func DefaultResourcesListByResourceGroupOperationOptions() ResourcesListByResourceGroupOperationOptions { + return ResourcesListByResourceGroupOperationOptions{} +} + +func (o ResourcesListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ResourcesListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ResourcesListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ResourcesListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ResourcesListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ResourcesListByResourceGroup ... +func (c ResourceGroupsClient) ResourcesListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ResourcesListByResourceGroupOperationOptions) (result ResourcesListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ResourcesListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/resources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GenericResourceExpanded `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ResourcesListByResourceGroupComplete retrieves all the results into a single object +func (c ResourceGroupsClient) ResourcesListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ResourcesListByResourceGroupOperationOptions) (ResourcesListByResourceGroupCompleteResult, error) { + return c.ResourcesListByResourceGroupCompleteMatchingPredicate(ctx, id, options, GenericResourceExpandedOperationPredicate{}) +} + +// ResourcesListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGroupsClient) ResourcesListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ResourcesListByResourceGroupOperationOptions, predicate GenericResourceExpandedOperationPredicate) (result ResourcesListByResourceGroupCompleteResult, err error) { + items := make([]GenericResourceExpanded, 0) + + resp, err := c.ResourcesListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ResourcesListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/method_update.go b/resource-manager/resources/2025-03-01/resourcegroups/method_update.go new file mode 100644 index 00000000000..0af23ede9e7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/method_update.go @@ -0,0 +1,58 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGroup +} + +// Update ... +func (c ResourceGroupsClient) Update(ctx context.Context, id commonids.ResourceGroupId, input ResourceGroupPatchable) (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 ResourceGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_erroradditionalinfo.go b/resource-manager/resources/2025-03-01/resourcegroups/model_erroradditionalinfo.go new file mode 100644 index 00000000000..041f719ae04 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_errorresponse.go b/resource-manager/resources/2025-03-01/resourcegroups/model_errorresponse.go new file mode 100644 index 00000000000..fd11f3aa7ac --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_errorresponse.go @@ -0,0 +1,12 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorResponse struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorResponse `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_exporttemplaterequest.go b/resource-manager/resources/2025-03-01/resourcegroups/model_exporttemplaterequest.go new file mode 100644 index 00000000000..7a4aa934c69 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_exporttemplaterequest.go @@ -0,0 +1,10 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportTemplateRequest struct { + Options *string `json:"options,omitempty"` + OutputFormat *ExportTemplateOutputFormat `json:"outputFormat,omitempty"` + Resources *[]string `json:"resources,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_genericresourceexpanded.go b/resource-manager/resources/2025-03-01/resourcegroups/model_genericresourceexpanded.go new file mode 100644 index 00000000000..6a33cd1d535 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_genericresourceexpanded.go @@ -0,0 +1,54 @@ +package resourcegroups + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" + "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 GenericResourceExpanded struct { + ChangedTime *string `json:"changedTime,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + ExtendedLocation *edgezones.Model `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *GenericResourceExpanded) GetChangedTimeAsTime() (*time.Time, error) { + if o.ChangedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ChangedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetChangedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ChangedTime = &formatted +} + +func (o *GenericResourceExpanded) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_plan.go b/resource-manager/resources/2025-03-01/resourcegroups/model_plan.go new file mode 100644 index 00000000000..2fe113c113c --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_plan.go @@ -0,0 +1,12 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name *string `json:"name,omitempty"` + Product *string `json:"product,omitempty"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroup.go b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroup.go new file mode 100644 index 00000000000..f0945027a5d --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroup.go @@ -0,0 +1,14 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGroup struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGroupProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupexportresult.go b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupexportresult.go new file mode 100644 index 00000000000..eed09b43006 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupexportresult.go @@ -0,0 +1,10 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGroupExportResult struct { + Error *ErrorResponse `json:"error,omitempty"` + Output *string `json:"output,omitempty"` + Template *interface{} `json:"template,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegrouppatchable.go b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegrouppatchable.go new file mode 100644 index 00000000000..f4d557b1e55 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegrouppatchable.go @@ -0,0 +1,11 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGroupPatchable struct { + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ResourceGroupProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupproperties.go b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupproperties.go new file mode 100644 index 00000000000..aa68a1f10b4 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_resourcegroupproperties.go @@ -0,0 +1,8 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGroupProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/model_sku.go b/resource-manager/resources/2025-03-01/resourcegroups/model_sku.go new file mode 100644 index 00000000000..85f15ef6c0e --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/model_sku.go @@ -0,0 +1,13 @@ +package resourcegroups + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Model *string `json:"model,omitempty"` + Name *string `json:"name,omitempty"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resourcegroups/predicates.go b/resource-manager/resources/2025-03-01/resourcegroups/predicates.go new file mode 100644 index 00000000000..dfc76d5202b --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/predicates.go @@ -0,0 +1,95 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericResourceExpandedOperationPredicate struct { + ChangedTime *string + CreatedTime *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Properties *interface{} + ProvisioningState *string + Type *string +} + +func (p GenericResourceExpandedOperationPredicate) Matches(input GenericResourceExpanded) bool { + + if p.ChangedTime != nil && (input.ChangedTime == nil || *p.ChangedTime != *input.ChangedTime) { + return false + } + + if p.CreatedTime != nil && (input.CreatedTime == nil || *p.CreatedTime != *input.CreatedTime) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Properties != nil && (input.Properties == nil || *p.Properties != *input.Properties) { + return false + } + + if p.ProvisioningState != nil && (input.ProvisioningState == nil || *p.ProvisioningState != *input.ProvisioningState) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ResourceGroupOperationPredicate struct { + Id *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p ResourceGroupOperationPredicate) Matches(input ResourceGroup) 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.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + 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/resources/2025-03-01/resourcegroups/version.go b/resource-manager/resources/2025-03-01/resourcegroups/version.go new file mode 100644 index 00000000000..d9b5be36a75 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resourcegroups/version.go @@ -0,0 +1,10 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/resourcegroups/2025-03-01" +} diff --git a/resource-manager/resources/2025-03-01/resources/README.md b/resource-manager/resources/2025-03-01/resources/README.md new file mode 100644 index 00000000000..f6b83d192b3 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/README.md @@ -0,0 +1,228 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/resources` Documentation + +The `resources` SDK allows for interaction with Azure Resource Manager `resources` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/resources" +``` + + +### Client Initialization + +```go +client := resources.NewResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourcesClient.CheckExistence` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.CheckExistence(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourcesClient.CheckExistenceById` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.CheckExistenceById(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourcesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := resources.GenericResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.CreateOrUpdateById` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := resources.GenericResource{ + // ... +} + + +if err := client.CreateOrUpdateByIdThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.DeleteById` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +if err := client.DeleteByIdThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +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: `ResourcesClient.GetById` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.GetById(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourcesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, resources.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, resources.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourcesClient.MoveResources` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resources.ResourcesMoveInfo{ + // ... +} + + +if err := client.MoveResourcesThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := resources.GenericResource{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.UpdateById` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := resources.GenericResource{ + // ... +} + + +if err := client.UpdateByIdThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.ValidateMoveResources` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resources.ResourcesMoveInfo{ + // ... +} + + +if err := client.ValidateMoveResourcesThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/resources/2025-03-01/resources/client.go b/resource-manager/resources/2025-03-01/resources/client.go new file mode 100644 index 00000000000..6e71db435da --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/client.go @@ -0,0 +1,26 @@ +package resources + +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 ResourcesClient struct { + Client *resourcemanager.Client +} + +func NewResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "resources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourcesClient: %+v", err) + } + + return &ResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2025-03-01/resources/method_checkexistence.go b/resource-manager/resources/2025-03-01/resources/method_checkexistence.go new file mode 100644 index 00000000000..ad5faa25cc1 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_checkexistence.go @@ -0,0 +1,47 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckExistenceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistence ... +func (c ResourcesClient) CheckExistence(ctx context.Context, id commonids.ScopeId) (result CheckExistenceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resources/method_checkexistencebyid.go b/resource-manager/resources/2025-03-01/resources/method_checkexistencebyid.go new file mode 100644 index 00000000000..706df9e53b7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_checkexistencebyid.go @@ -0,0 +1,47 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckExistenceByIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistenceById ... +func (c ResourcesClient) CheckExistenceById(ctx context.Context, id commonids.ScopeId) (result CheckExistenceByIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resources/method_createorupdate.go b/resource-manager/resources/2025-03-01/resources/method_createorupdate.go new file mode 100644 index 00000000000..ee5c80267c6 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_createorupdate.go @@ -0,0 +1,77 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// CreateOrUpdate ... +func (c ResourcesClient) CreateOrUpdate(ctx context.Context, id commonids.ScopeId, input GenericResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ResourcesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.ScopeId, input GenericResource) 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/resources/2025-03-01/resources/method_createorupdatebyid.go b/resource-manager/resources/2025-03-01/resources/method_createorupdatebyid.go new file mode 100644 index 00000000000..30296261d65 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_createorupdatebyid.go @@ -0,0 +1,77 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateByIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// CreateOrUpdateById ... +func (c ResourcesClient) CreateOrUpdateById(ctx context.Context, id commonids.ScopeId, input GenericResource) (result CreateOrUpdateByIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 +} + +// CreateOrUpdateByIdThenPoll performs CreateOrUpdateById then polls until it's completed +func (c ResourcesClient) CreateOrUpdateByIdThenPoll(ctx context.Context, id commonids.ScopeId, input GenericResource) error { + result, err := c.CreateOrUpdateById(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateById: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateById: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/resources/method_delete.go b/resource-manager/resources/2025-03-01/resources/method_delete.go new file mode 100644 index 00000000000..a15437f792a --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_delete.go @@ -0,0 +1,72 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ResourcesClient) Delete(ctx context.Context, id commonids.ScopeId) (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 ResourcesClient) DeleteThenPoll(ctx context.Context, id commonids.ScopeId) 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/resources/2025-03-01/resources/method_deletebyid.go b/resource-manager/resources/2025-03-01/resources/method_deletebyid.go new file mode 100644 index 00000000000..cf0e7b77f68 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_deletebyid.go @@ -0,0 +1,72 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteByIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteById ... +func (c ResourcesClient) DeleteById(ctx context.Context, id commonids.ScopeId) (result DeleteByIdOperationResponse, 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 +} + +// DeleteByIdThenPoll performs DeleteById then polls until it's completed +func (c ResourcesClient) DeleteByIdThenPoll(ctx context.Context, id commonids.ScopeId) error { + result, err := c.DeleteById(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteById: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteById: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/resources/method_get.go b/resource-manager/resources/2025-03-01/resources/method_get.go new file mode 100644 index 00000000000..d2fd91e267d --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_get.go @@ -0,0 +1,54 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// Get ... +func (c ResourcesClient) Get(ctx context.Context, id commonids.ScopeId) (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 GenericResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resources/method_getbyid.go b/resource-manager/resources/2025-03-01/resources/method_getbyid.go new file mode 100644 index 00000000000..c544e002b57 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_getbyid.go @@ -0,0 +1,54 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetByIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// GetById ... +func (c ResourcesClient) GetById(ctx context.Context, id commonids.ScopeId) (result GetByIdOperationResponse, 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 GenericResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/resources/method_list.go b/resource-manager/resources/2025-03-01/resources/method_list.go new file mode 100644 index 00000000000..210382a2f38 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_list.go @@ -0,0 +1,143 @@ +package resources + +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 *[]GenericResourceExpanded +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GenericResourceExpanded +} + +type ListOperationOptions struct { + Expand *string + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ResourcesClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/resources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GenericResourceExpanded `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 ResourcesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, GenericResourceExpandedOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourcesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate GenericResourceExpandedOperationPredicate) (result ListCompleteResult, err error) { + items := make([]GenericResourceExpanded, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/resources/method_moveresources.go b/resource-manager/resources/2025-03-01/resources/method_moveresources.go new file mode 100644 index 00000000000..424b1c4539e --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_moveresources.go @@ -0,0 +1,75 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MoveResourcesOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// MoveResources ... +func (c ResourcesClient) MoveResources(ctx context.Context, id commonids.ResourceGroupId, input ResourcesMoveInfo) (result MoveResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/moveResources", 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 +} + +// MoveResourcesThenPoll performs MoveResources then polls until it's completed +func (c ResourcesClient) MoveResourcesThenPoll(ctx context.Context, id commonids.ResourceGroupId, input ResourcesMoveInfo) error { + result, err := c.MoveResources(ctx, id, input) + if err != nil { + return fmt.Errorf("performing MoveResources: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MoveResources: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/resources/method_update.go b/resource-manager/resources/2025-03-01/resources/method_update.go new file mode 100644 index 00000000000..86d87e03726 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_update.go @@ -0,0 +1,76 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// Update ... +func (c ResourcesClient) Update(ctx context.Context, id commonids.ScopeId, input GenericResource) (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 ResourcesClient) UpdateThenPoll(ctx context.Context, id commonids.ScopeId, input GenericResource) 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/resources/2025-03-01/resources/method_updatebyid.go b/resource-manager/resources/2025-03-01/resources/method_updatebyid.go new file mode 100644 index 00000000000..215432d574a --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_updatebyid.go @@ -0,0 +1,76 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateByIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// UpdateById ... +func (c ResourcesClient) UpdateById(ctx context.Context, id commonids.ScopeId, input GenericResource) (result UpdateByIdOperationResponse, 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 +} + +// UpdateByIdThenPoll performs UpdateById then polls until it's completed +func (c ResourcesClient) UpdateByIdThenPoll(ctx context.Context, id commonids.ScopeId, input GenericResource) error { + result, err := c.UpdateById(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpdateById: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpdateById: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/resources/method_validatemoveresources.go b/resource-manager/resources/2025-03-01/resources/method_validatemoveresources.go new file mode 100644 index 00000000000..64c7bde6350 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/method_validatemoveresources.go @@ -0,0 +1,75 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateMoveResourcesOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ValidateMoveResources ... +func (c ResourcesClient) ValidateMoveResources(ctx context.Context, id commonids.ResourceGroupId, input ResourcesMoveInfo) (result ValidateMoveResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validateMoveResources", 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 +} + +// ValidateMoveResourcesThenPoll performs ValidateMoveResources then polls until it's completed +func (c ResourcesClient) ValidateMoveResourcesThenPoll(ctx context.Context, id commonids.ResourceGroupId, input ResourcesMoveInfo) error { + result, err := c.ValidateMoveResources(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ValidateMoveResources: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ValidateMoveResources: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/resources/model_genericresource.go b/resource-manager/resources/2025-03-01/resources/model_genericresource.go new file mode 100644 index 00000000000..e693dbaebca --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/model_genericresource.go @@ -0,0 +1,24 @@ +package resources + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" + "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 GenericResource struct { + ExtendedLocation *edgezones.Model `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resources/model_genericresourceexpanded.go b/resource-manager/resources/2025-03-01/resources/model_genericresourceexpanded.go new file mode 100644 index 00000000000..deaddbfc5db --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/model_genericresourceexpanded.go @@ -0,0 +1,54 @@ +package resources + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" + "github.com/hashicorp/go-azure-helpers/resourcemanager/edgezones" + "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 GenericResourceExpanded struct { + ChangedTime *string `json:"changedTime,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + ExtendedLocation *edgezones.Model `json:"extendedLocation,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *GenericResourceExpanded) GetChangedTimeAsTime() (*time.Time, error) { + if o.ChangedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ChangedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetChangedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ChangedTime = &formatted +} + +func (o *GenericResourceExpanded) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} diff --git a/resource-manager/resources/2025-03-01/resources/model_plan.go b/resource-manager/resources/2025-03-01/resources/model_plan.go new file mode 100644 index 00000000000..d28c531b7d7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/model_plan.go @@ -0,0 +1,12 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name *string `json:"name,omitempty"` + Product *string `json:"product,omitempty"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher *string `json:"publisher,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resources/model_resourcesmoveinfo.go b/resource-manager/resources/2025-03-01/resources/model_resourcesmoveinfo.go new file mode 100644 index 00000000000..0d90bb09287 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/model_resourcesmoveinfo.go @@ -0,0 +1,9 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesMoveInfo struct { + Resources *[]string `json:"resources,omitempty"` + TargetResourceGroup *string `json:"targetResourceGroup,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resources/model_sku.go b/resource-manager/resources/2025-03-01/resources/model_sku.go new file mode 100644 index 00000000000..2086ca94311 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/model_sku.go @@ -0,0 +1,13 @@ +package resources + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Model *string `json:"model,omitempty"` + Name *string `json:"name,omitempty"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/resources/predicates.go b/resource-manager/resources/2025-03-01/resources/predicates.go new file mode 100644 index 00000000000..cfa7a99b864 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/predicates.go @@ -0,0 +1,62 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericResourceExpandedOperationPredicate struct { + ChangedTime *string + CreatedTime *string + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Properties *interface{} + ProvisioningState *string + Type *string +} + +func (p GenericResourceExpandedOperationPredicate) Matches(input GenericResourceExpanded) bool { + + if p.ChangedTime != nil && (input.ChangedTime == nil || *p.ChangedTime != *input.ChangedTime) { + return false + } + + if p.CreatedTime != nil && (input.CreatedTime == nil || *p.CreatedTime != *input.CreatedTime) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Properties != nil && (input.Properties == nil || *p.Properties != *input.Properties) { + return false + } + + if p.ProvisioningState != nil && (input.ProvisioningState == nil || *p.ProvisioningState != *input.ProvisioningState) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/resources/2025-03-01/resources/version.go b/resource-manager/resources/2025-03-01/resources/version.go new file mode 100644 index 00000000000..435c03296e5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/resources/version.go @@ -0,0 +1,10 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/resources/2025-03-01" +} diff --git a/resource-manager/resources/2025-03-01/tags/README.md b/resource-manager/resources/2025-03-01/tags/README.md new file mode 100644 index 00000000000..724b29bdc7c --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/README.md @@ -0,0 +1,164 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/tags` Documentation + +The `tags` SDK allows for interaction with Azure Resource Manager `resources` (API Version `2025-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2025-03-01/tags" +``` + + +### Client Initialization + +```go +client := tags.NewTagsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tags.NewTagNameID("12345678-1234-9876-4563-123456789012", "tagName") + +read, err := client.CreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.CreateOrUpdateAtScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := tags.TagsResource{ + // ... +} + + +if err := client.CreateOrUpdateAtScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TagsClient.CreateOrUpdateValue` + +```go +ctx := context.TODO() +id := tags.NewTagValueID("12345678-1234-9876-4563-123456789012", "tagName", "tagValueName") + +read, err := client.CreateOrUpdateValue(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.Delete` + +```go +ctx := context.TODO() +id := tags.NewTagNameID("12345678-1234-9876-4563-123456789012", "tagName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.DeleteAtScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +if err := client.DeleteAtScopeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TagsClient.DeleteValue` + +```go +ctx := context.TODO() +id := tags.NewTagValueID("12345678-1234-9876-4563-123456789012", "tagName", "tagValueName") + +read, err := client.DeleteValue(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.GetAtScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.GetAtScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `TagsClient.UpdateAtScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := tags.TagsPatchResource{ + // ... +} + + +if err := client.UpdateAtScopeThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/resources/2025-03-01/tags/client.go b/resource-manager/resources/2025-03-01/tags/client.go new file mode 100644 index 00000000000..1b337a567b0 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/client.go @@ -0,0 +1,26 @@ +package tags + +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 TagsClient struct { + Client *resourcemanager.Client +} + +func NewTagsClientWithBaseURI(sdkApi sdkEnv.Api) (*TagsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "tags", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagsClient: %+v", err) + } + + return &TagsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2025-03-01/tags/constants.go b/resource-manager/resources/2025-03-01/tags/constants.go new file mode 100644 index 00000000000..73319542e47 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/constants.go @@ -0,0 +1,54 @@ +package tags + +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 TagsPatchOperation string + +const ( + TagsPatchOperationDelete TagsPatchOperation = "Delete" + TagsPatchOperationMerge TagsPatchOperation = "Merge" + TagsPatchOperationReplace TagsPatchOperation = "Replace" +) + +func PossibleValuesForTagsPatchOperation() []string { + return []string{ + string(TagsPatchOperationDelete), + string(TagsPatchOperationMerge), + string(TagsPatchOperationReplace), + } +} + +func (s *TagsPatchOperation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTagsPatchOperation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTagsPatchOperation(input string) (*TagsPatchOperation, error) { + vals := map[string]TagsPatchOperation{ + "delete": TagsPatchOperationDelete, + "merge": TagsPatchOperationMerge, + "replace": TagsPatchOperationReplace, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TagsPatchOperation(input) + return &out, nil +} diff --git a/resource-manager/resources/2025-03-01/tags/id_tagname.go b/resource-manager/resources/2025-03-01/tags/id_tagname.go new file mode 100644 index 00000000000..e139995ddb1 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/id_tagname.go @@ -0,0 +1,119 @@ +package tags + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagNameId{}) +} + +var _ resourceids.ResourceId = &TagNameId{} + +// TagNameId is a struct representing the Resource ID for a Tag Name +type TagNameId struct { + SubscriptionId string + TagName string +} + +// NewTagNameID returns a new TagNameId struct +func NewTagNameID(subscriptionId string, tagName string) TagNameId { + return TagNameId{ + SubscriptionId: subscriptionId, + TagName: tagName, + } +} + +// ParseTagNameID parses 'input' into a TagNameId +func ParseTagNameID(input string) (*TagNameId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagNameId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagNameId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagNameIDInsensitively parses 'input' case-insensitively into a TagNameId +// note: this method should only be used for API response data and not user input +func ParseTagNameIDInsensitively(input string) (*TagNameId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagNameId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagNameId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagNameId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.TagName, ok = input.Parsed["tagName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagName", input) + } + + return nil +} + +// ValidateTagNameID checks that 'input' can be parsed as a Tag Name ID +func ValidateTagNameID(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 := ParseTagNameID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Name ID +func (id TagNameId) ID() string { + fmtString := "/subscriptions/%s/tagNames/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.TagName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Name ID +func (id TagNameId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticTagNames", "tagNames", "tagNames"), + resourceids.UserSpecifiedSegment("tagName", "tagName"), + } +} + +// String returns a human-readable description of this Tag Name ID +func (id TagNameId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Tag Name: %q", id.TagName), + } + return fmt.Sprintf("Tag Name (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/tags/id_tagname_test.go b/resource-manager/resources/2025-03-01/tags/id_tagname_test.go new file mode 100644 index 00000000000..f81c85c7a20 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/id_tagname_test.go @@ -0,0 +1,207 @@ +package tags + +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 = &TagNameId{} + +func TestNewTagNameID(t *testing.T) { + id := NewTagNameID("12345678-1234-9876-4563-123456789012", "tagName") + + 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.TagName != "tagName" { + t.Fatalf("Expected %q but got %q for Segment 'TagName'", id.TagName, "tagName") + } +} + +func TestFormatTagNameID(t *testing.T) { + actual := NewTagNameID("12345678-1234-9876-4563-123456789012", "tagName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagNameID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagNameId + }{ + { + // 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/tagNames", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName", + Expected: &TagNameId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagNameID(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.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + } +} + +func TestParseTagNameIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagNameId + }{ + { + // 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/tagNames", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName", + Expected: &TagNameId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgNaMe", + Expected: &TagNameId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tAgNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagNameIDInsensitively(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.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + } +} + +func TestSegmentsForTagNameId(t *testing.T) { + segments := TagNameId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagNameId 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/resources/2025-03-01/tags/id_tagvalue.go b/resource-manager/resources/2025-03-01/tags/id_tagvalue.go new file mode 100644 index 00000000000..3771f3e7f9a --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/id_tagvalue.go @@ -0,0 +1,128 @@ +package tags + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagValueId{}) +} + +var _ resourceids.ResourceId = &TagValueId{} + +// TagValueId is a struct representing the Resource ID for a Tag Value +type TagValueId struct { + SubscriptionId string + TagName string + TagValueName string +} + +// NewTagValueID returns a new TagValueId struct +func NewTagValueID(subscriptionId string, tagName string, tagValueName string) TagValueId { + return TagValueId{ + SubscriptionId: subscriptionId, + TagName: tagName, + TagValueName: tagValueName, + } +} + +// ParseTagValueID parses 'input' into a TagValueId +func ParseTagValueID(input string) (*TagValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagValueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagValueId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagValueIDInsensitively parses 'input' case-insensitively into a TagValueId +// note: this method should only be used for API response data and not user input +func ParseTagValueIDInsensitively(input string) (*TagValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagValueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagValueId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagValueId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.TagName, ok = input.Parsed["tagName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagName", input) + } + + if id.TagValueName, ok = input.Parsed["tagValueName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagValueName", input) + } + + return nil +} + +// ValidateTagValueID checks that 'input' can be parsed as a Tag Value ID +func ValidateTagValueID(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 := ParseTagValueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Value ID +func (id TagValueId) ID() string { + fmtString := "/subscriptions/%s/tagNames/%s/tagValues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.TagName, id.TagValueName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Value ID +func (id TagValueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticTagNames", "tagNames", "tagNames"), + resourceids.UserSpecifiedSegment("tagName", "tagName"), + resourceids.StaticSegment("staticTagValues", "tagValues", "tagValues"), + resourceids.UserSpecifiedSegment("tagValueName", "tagValueName"), + } +} + +// String returns a human-readable description of this Tag Value ID +func (id TagValueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Tag Name: %q", id.TagName), + fmt.Sprintf("Tag Value Name: %q", id.TagValueName), + } + return fmt.Sprintf("Tag Value (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2025-03-01/tags/id_tagvalue_test.go b/resource-manager/resources/2025-03-01/tags/id_tagvalue_test.go new file mode 100644 index 00000000000..a1243c411ae --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/id_tagvalue_test.go @@ -0,0 +1,252 @@ +package tags + +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 = &TagValueId{} + +func TestNewTagValueID(t *testing.T) { + id := NewTagValueID("12345678-1234-9876-4563-123456789012", "tagName", "tagValueName") + + 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.TagName != "tagName" { + t.Fatalf("Expected %q but got %q for Segment 'TagName'", id.TagName, "tagName") + } + + if id.TagValueName != "tagValueName" { + t.Fatalf("Expected %q but got %q for Segment 'TagValueName'", id.TagValueName, "tagValueName") + } +} + +func TestFormatTagValueID(t *testing.T) { + actual := NewTagValueID("12345678-1234-9876-4563-123456789012", "tagName", "tagValueName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues/tagValueName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagValueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagValueId + }{ + { + // 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/tagNames", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues/tagValueName", + Expected: &TagValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagName", + TagValueName: "tagValueName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues/tagValueName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagValueID(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.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + if actual.TagValueName != v.Expected.TagValueName { + t.Fatalf("Expected %q but got %q for TagValueName", v.Expected.TagValueName, actual.TagValueName) + } + + } +} + +func TestParseTagValueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagValueId + }{ + { + // 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/tagNames", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgNaMe/tAgVaLuEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues/tagValueName", + Expected: &TagValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagName", + TagValueName: "tagValueName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagName/tagValues/tagValueName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgNaMe/tAgVaLuEs/tAgVaLuEnAmE", + Expected: &TagValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tAgNaMe", + TagValueName: "tAgVaLuEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgNaMe/tAgVaLuEs/tAgVaLuEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagValueIDInsensitively(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.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + if actual.TagValueName != v.Expected.TagValueName { + t.Fatalf("Expected %q but got %q for TagValueName", v.Expected.TagValueName, actual.TagValueName) + } + + } +} + +func TestSegmentsForTagValueId(t *testing.T) { + segments := TagValueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagValueId 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/resources/2025-03-01/tags/method_createorupdate.go b/resource-manager/resources/2025-03-01/tags/method_createorupdate.go new file mode 100644 index 00000000000..117a6bb5ba7 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_createorupdate.go @@ -0,0 +1,54 @@ +package tags + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagDetails +} + +// CreateOrUpdate ... +func (c TagsClient) CreateOrUpdate(ctx context.Context, id TagNameId) (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 + } + + 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 TagDetails + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/tags/method_createorupdateatscope.go b/resource-manager/resources/2025-03-01/tags/method_createorupdateatscope.go new file mode 100644 index 00000000000..e2a93d0ef68 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_createorupdateatscope.go @@ -0,0 +1,76 @@ +package tags + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateAtScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TagsResource +} + +// CreateOrUpdateAtScope ... +func (c TagsClient) CreateOrUpdateAtScope(ctx context.Context, id commonids.ScopeId, input TagsResource) (result CreateOrUpdateAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/tags/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateAtScopeThenPoll performs CreateOrUpdateAtScope then polls until it's completed +func (c TagsClient) CreateOrUpdateAtScopeThenPoll(ctx context.Context, id commonids.ScopeId, input TagsResource) error { + result, err := c.CreateOrUpdateAtScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateAtScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateAtScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/tags/method_createorupdatevalue.go b/resource-manager/resources/2025-03-01/tags/method_createorupdatevalue.go new file mode 100644 index 00000000000..f5e9476bcb5 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_createorupdatevalue.go @@ -0,0 +1,54 @@ +package tags + +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 CreateOrUpdateValueOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagValue +} + +// CreateOrUpdateValue ... +func (c TagsClient) CreateOrUpdateValue(ctx context.Context, id TagValueId) (result CreateOrUpdateValueOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagValue + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/tags/method_delete.go b/resource-manager/resources/2025-03-01/tags/method_delete.go new file mode 100644 index 00000000000..f1d45af739d --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_delete.go @@ -0,0 +1,47 @@ +package tags + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TagsClient) Delete(ctx context.Context, id TagNameId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/tags/method_deleteatscope.go b/resource-manager/resources/2025-03-01/tags/method_deleteatscope.go new file mode 100644 index 00000000000..a2b4625866f --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_deleteatscope.go @@ -0,0 +1,71 @@ +package tags + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteAtScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteAtScope ... +func (c TagsClient) DeleteAtScope(ctx context.Context, id commonids.ScopeId) (result DeleteAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/tags/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 +} + +// DeleteAtScopeThenPoll performs DeleteAtScope then polls until it's completed +func (c TagsClient) DeleteAtScopeThenPoll(ctx context.Context, id commonids.ScopeId) error { + result, err := c.DeleteAtScope(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteAtScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteAtScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/tags/method_deletevalue.go b/resource-manager/resources/2025-03-01/tags/method_deletevalue.go new file mode 100644 index 00000000000..63a72bc151e --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_deletevalue.go @@ -0,0 +1,47 @@ +package tags + +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 DeleteValueOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteValue ... +func (c TagsClient) DeleteValue(ctx context.Context, id TagValueId) (result DeleteValueOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/tags/method_getatscope.go b/resource-manager/resources/2025-03-01/tags/method_getatscope.go new file mode 100644 index 00000000000..7f5afb9a8ac --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_getatscope.go @@ -0,0 +1,55 @@ +package tags + +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 GetAtScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagsResource +} + +// GetAtScope ... +func (c TagsClient) GetAtScope(ctx context.Context, id commonids.ScopeId) (result GetAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/tags/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 TagsResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2025-03-01/tags/method_list.go b/resource-manager/resources/2025-03-01/tags/method_list.go new file mode 100644 index 00000000000..d0f304b1f43 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_list.go @@ -0,0 +1,106 @@ +package tags + +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 *[]TagDetails +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagDetails +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c TagsClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/tagNames", 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 *[]TagDetails `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 TagsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, TagDetailsOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate TagDetailsOperationPredicate) (result ListCompleteResult, err error) { + items := make([]TagDetails, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2025-03-01/tags/method_updateatscope.go b/resource-manager/resources/2025-03-01/tags/method_updateatscope.go new file mode 100644 index 00000000000..2b3b261ace8 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/method_updateatscope.go @@ -0,0 +1,76 @@ +package tags + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateAtScopeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TagsResource +} + +// UpdateAtScope ... +func (c TagsClient) UpdateAtScope(ctx context.Context, id commonids.ScopeId, input TagsPatchResource) (result UpdateAtScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/tags/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateAtScopeThenPoll performs UpdateAtScope then polls until it's completed +func (c TagsClient) UpdateAtScopeThenPoll(ctx context.Context, id commonids.ScopeId, input TagsPatchResource) error { + result, err := c.UpdateAtScope(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpdateAtScope: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpdateAtScope: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2025-03-01/tags/model_tagcount.go b/resource-manager/resources/2025-03-01/tags/model_tagcount.go new file mode 100644 index 00000000000..59e158ab0f9 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/model_tagcount.go @@ -0,0 +1,9 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagCount struct { + Type *string `json:"type,omitempty"` + Value *int64 `json:"value,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/tags/model_tagdetails.go b/resource-manager/resources/2025-03-01/tags/model_tagdetails.go new file mode 100644 index 00000000000..8123c21aaff --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/model_tagdetails.go @@ -0,0 +1,11 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDetails struct { + Count *TagCount `json:"count,omitempty"` + Id *string `json:"id,omitempty"` + TagName *string `json:"tagName,omitempty"` + Values *[]TagValue `json:"values,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/tags/model_tags.go b/resource-manager/resources/2025-03-01/tags/model_tags.go new file mode 100644 index 00000000000..17819dab694 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/model_tags.go @@ -0,0 +1,8 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Tags struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/tags/model_tagspatchresource.go b/resource-manager/resources/2025-03-01/tags/model_tagspatchresource.go new file mode 100644 index 00000000000..96612f20fe9 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/model_tagspatchresource.go @@ -0,0 +1,9 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsPatchResource struct { + Operation *TagsPatchOperation `json:"operation,omitempty"` + Properties *Tags `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/tags/model_tagsresource.go b/resource-manager/resources/2025-03-01/tags/model_tagsresource.go new file mode 100644 index 00000000000..6c627a11732 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/model_tagsresource.go @@ -0,0 +1,11 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties Tags `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/tags/model_tagvalue.go b/resource-manager/resources/2025-03-01/tags/model_tagvalue.go new file mode 100644 index 00000000000..7c276e68277 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/model_tagvalue.go @@ -0,0 +1,10 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagValue struct { + Count *TagCount `json:"count,omitempty"` + Id *string `json:"id,omitempty"` + TagValue *string `json:"tagValue,omitempty"` +} diff --git a/resource-manager/resources/2025-03-01/tags/predicates.go b/resource-manager/resources/2025-03-01/tags/predicates.go new file mode 100644 index 00000000000..8ff401b12ca --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/predicates.go @@ -0,0 +1,22 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDetailsOperationPredicate struct { + Id *string + TagName *string +} + +func (p TagDetailsOperationPredicate) Matches(input TagDetails) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.TagName != nil && (input.TagName == nil || *p.TagName != *input.TagName) { + return false + } + + return true +} diff --git a/resource-manager/resources/2025-03-01/tags/version.go b/resource-manager/resources/2025-03-01/tags/version.go new file mode 100644 index 00000000000..0ec616bd666 --- /dev/null +++ b/resource-manager/resources/2025-03-01/tags/version.go @@ -0,0 +1,10 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/tags/2025-03-01" +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/README.md b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/README.md new file mode 100644 index 00000000000..e60613a5389 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/README.md @@ -0,0 +1,88 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies` Documentation + +The `backupshorttermretentionpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies" +``` + + +### Client Initialization + +```go +client := backupshorttermretentionpolicies.NewBackupShortTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupShortTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := backupshorttermretentionpolicies.BackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupShortTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `BackupShortTermRetentionPoliciesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BackupShortTermRetentionPoliciesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := backupshorttermretentionpolicies.BackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/client.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/client.go new file mode 100644 index 00000000000..d77d7e4b208 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/client.go @@ -0,0 +1,26 @@ +package backupshorttermretentionpolicies + +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 BackupShortTermRetentionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*BackupShortTermRetentionPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "backupshorttermretentionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BackupShortTermRetentionPoliciesClient: %+v", err) + } + + return &BackupShortTermRetentionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/constants.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/constants.go new file mode 100644 index 00000000000..e1121e14507 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/constants.go @@ -0,0 +1,18 @@ +package backupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiffBackupIntervalInHours int64 + +const ( + DiffBackupIntervalInHoursOneTwo DiffBackupIntervalInHours = 12 + DiffBackupIntervalInHoursTwoFour DiffBackupIntervalInHours = 24 +) + +func PossibleValuesForDiffBackupIntervalInHours() []int64 { + return []int64{ + int64(DiffBackupIntervalInHoursOneTwo), + int64(DiffBackupIntervalInHoursTwoFour), + } +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..70f8ed7aec4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package backupshorttermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BackupShortTermRetentionPolicy +} + +// CreateOrUpdate ... +func (c BackupShortTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input BackupShortTermRetentionPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c BackupShortTermRetentionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input BackupShortTermRetentionPolicy) 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/sql/2023-08-01/backupshorttermretentionpolicies/method_get.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_get.go new file mode 100644 index 00000000000..0a7a2b75778 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_get.go @@ -0,0 +1,55 @@ +package backupshorttermretentionpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BackupShortTermRetentionPolicy +} + +// Get ... +func (c BackupShortTermRetentionPoliciesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 BackupShortTermRetentionPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..7ba5917833b --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,106 @@ +package backupshorttermretentionpolicies + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BackupShortTermRetentionPolicy +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []BackupShortTermRetentionPolicy +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c BackupShortTermRetentionPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies", 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 *[]BackupShortTermRetentionPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c BackupShortTermRetentionPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, BackupShortTermRetentionPolicyOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BackupShortTermRetentionPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate BackupShortTermRetentionPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]BackupShortTermRetentionPolicy, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_update.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_update.go new file mode 100644 index 00000000000..9d4e268ea29 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/method_update.go @@ -0,0 +1,76 @@ +package backupshorttermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BackupShortTermRetentionPolicy +} + +// Update ... +func (c BackupShortTermRetentionPoliciesClient) Update(ctx context.Context, id commonids.SqlDatabaseId, input BackupShortTermRetentionPolicy) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c BackupShortTermRetentionPoliciesClient) UpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input BackupShortTermRetentionPolicy) 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/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go new file mode 100644 index 00000000000..02b0a17fb52 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go @@ -0,0 +1,11 @@ +package backupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupShortTermRetentionPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BackupShortTermRetentionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go new file mode 100644 index 00000000000..039f22762ba --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go @@ -0,0 +1,9 @@ +package backupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupShortTermRetentionPolicyProperties struct { + DiffBackupIntervalInHours *DiffBackupIntervalInHours `json:"diffBackupIntervalInHours,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/predicates.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/predicates.go new file mode 100644 index 00000000000..27cabb2785c --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/predicates.go @@ -0,0 +1,27 @@ +package backupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BackupShortTermRetentionPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BackupShortTermRetentionPolicyOperationPredicate) Matches(input BackupShortTermRetentionPolicy) 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/sql/2023-08-01/backupshorttermretentionpolicies/version.go b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/version.go new file mode 100644 index 00000000000..c999f730a74 --- /dev/null +++ b/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies/version.go @@ -0,0 +1,10 @@ +package backupshorttermretentionpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/backupshorttermretentionpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/README.md b/resource-manager/sql/2023-08-01/blobauditing/README.md new file mode 100644 index 00000000000..2f3c552abcc --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/README.md @@ -0,0 +1,229 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/blobauditing` Documentation + +The `blobauditing` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/blobauditing" +``` + + +### Client Initialization + +```go +client := blobauditing.NewBlobAuditingClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BlobAuditingClient.DatabaseBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := blobauditing.DatabaseBlobAuditingPolicy{ + // ... +} + + +read, err := client.DatabaseBlobAuditingPoliciesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BlobAuditingClient.DatabaseBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.DatabaseBlobAuditingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BlobAuditingClient.DatabaseBlobAuditingPoliciesListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.DatabaseBlobAuditingPoliciesListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.DatabaseBlobAuditingPoliciesListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedDatabaseBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := blobauditing.ExtendedDatabaseBlobAuditingPolicy{ + // ... +} + + +read, err := client.ExtendedDatabaseBlobAuditingPoliciesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedDatabaseBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.ExtendedDatabaseBlobAuditingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedDatabaseBlobAuditingPoliciesListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ExtendedDatabaseBlobAuditingPoliciesListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ExtendedDatabaseBlobAuditingPoliciesListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedServerBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := blobauditing.ExtendedServerBlobAuditingPolicy{ + // ... +} + + +if err := client.ExtendedServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedServerBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.ExtendedServerBlobAuditingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedServerBlobAuditingPoliciesListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ExtendedServerBlobAuditingPoliciesListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ExtendedServerBlobAuditingPoliciesListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BlobAuditingClient.ServerBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := blobauditing.ServerBlobAuditingPolicy{ + // ... +} + + +if err := client.ServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BlobAuditingClient.ServerBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.ServerBlobAuditingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BlobAuditingClient.ServerBlobAuditingPoliciesListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ServerBlobAuditingPoliciesListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ServerBlobAuditingPoliciesListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/blobauditing/client.go b/resource-manager/sql/2023-08-01/blobauditing/client.go new file mode 100644 index 00000000000..d77ae84974a --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/client.go @@ -0,0 +1,26 @@ +package blobauditing + +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 BlobAuditingClient struct { + Client *resourcemanager.Client +} + +func NewBlobAuditingClientWithBaseURI(sdkApi sdkEnv.Api) (*BlobAuditingClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "blobauditing", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BlobAuditingClient: %+v", err) + } + + return &BlobAuditingClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/constants.go b/resource-manager/sql/2023-08-01/blobauditing/constants.go new file mode 100644 index 00000000000..ea5c72e5e3a --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/constants.go @@ -0,0 +1,51 @@ +package blobauditing + +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 BlobAuditingPolicyState string + +const ( + BlobAuditingPolicyStateDisabled BlobAuditingPolicyState = "Disabled" + BlobAuditingPolicyStateEnabled BlobAuditingPolicyState = "Enabled" +) + +func PossibleValuesForBlobAuditingPolicyState() []string { + return []string{ + string(BlobAuditingPolicyStateDisabled), + string(BlobAuditingPolicyStateEnabled), + } +} + +func (s *BlobAuditingPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobAuditingPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBlobAuditingPolicyState(input string) (*BlobAuditingPolicyState, error) { + vals := map[string]BlobAuditingPolicyState{ + "disabled": BlobAuditingPolicyStateDisabled, + "enabled": BlobAuditingPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BlobAuditingPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..69f704a405e --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go @@ -0,0 +1,60 @@ +package blobauditing + +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 DatabaseBlobAuditingPoliciesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseBlobAuditingPolicy +} + +// DatabaseBlobAuditingPoliciesCreateOrUpdate ... +func (c BlobAuditingClient) DatabaseBlobAuditingPoliciesCreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseBlobAuditingPolicy) (result DatabaseBlobAuditingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/auditingSettings/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 DatabaseBlobAuditingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciesget.go b/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciesget.go new file mode 100644 index 00000000000..fbc605bc326 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpoliciesget.go @@ -0,0 +1,55 @@ +package blobauditing + +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 DatabaseBlobAuditingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseBlobAuditingPolicy +} + +// DatabaseBlobAuditingPoliciesGet ... +func (c BlobAuditingClient) DatabaseBlobAuditingPoliciesGet(ctx context.Context, id commonids.SqlDatabaseId) (result DatabaseBlobAuditingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/auditingSettings/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 DatabaseBlobAuditingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go b/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go new file mode 100644 index 00000000000..db3f09927a3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go @@ -0,0 +1,106 @@ +package blobauditing + +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 DatabaseBlobAuditingPoliciesListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseBlobAuditingPolicy +} + +type DatabaseBlobAuditingPoliciesListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseBlobAuditingPolicy +} + +type DatabaseBlobAuditingPoliciesListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DatabaseBlobAuditingPoliciesListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DatabaseBlobAuditingPoliciesListByDatabase ... +func (c BlobAuditingClient) DatabaseBlobAuditingPoliciesListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result DatabaseBlobAuditingPoliciesListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DatabaseBlobAuditingPoliciesListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/auditingSettings", 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 *[]DatabaseBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DatabaseBlobAuditingPoliciesListByDatabaseComplete retrieves all the results into a single object +func (c BlobAuditingClient) DatabaseBlobAuditingPoliciesListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (DatabaseBlobAuditingPoliciesListByDatabaseCompleteResult, error) { + return c.DatabaseBlobAuditingPoliciesListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseBlobAuditingPolicyOperationPredicate{}) +} + +// DatabaseBlobAuditingPoliciesListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BlobAuditingClient) DatabaseBlobAuditingPoliciesListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseBlobAuditingPolicyOperationPredicate) (result DatabaseBlobAuditingPoliciesListByDatabaseCompleteResult, err error) { + items := make([]DatabaseBlobAuditingPolicy, 0) + + resp, err := c.DatabaseBlobAuditingPoliciesListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DatabaseBlobAuditingPoliciesListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..1296c38402d --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go @@ -0,0 +1,60 @@ +package blobauditing + +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 ExtendedDatabaseBlobAuditingPoliciesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtendedDatabaseBlobAuditingPolicy +} + +// ExtendedDatabaseBlobAuditingPoliciesCreateOrUpdate ... +func (c BlobAuditingClient) ExtendedDatabaseBlobAuditingPoliciesCreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input ExtendedDatabaseBlobAuditingPolicy) (result ExtendedDatabaseBlobAuditingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/extendedAuditingSettings/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 ExtendedDatabaseBlobAuditingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go b/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go new file mode 100644 index 00000000000..68921db640e --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go @@ -0,0 +1,55 @@ +package blobauditing + +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 ExtendedDatabaseBlobAuditingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtendedDatabaseBlobAuditingPolicy +} + +// ExtendedDatabaseBlobAuditingPoliciesGet ... +func (c BlobAuditingClient) ExtendedDatabaseBlobAuditingPoliciesGet(ctx context.Context, id commonids.SqlDatabaseId) (result ExtendedDatabaseBlobAuditingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/extendedAuditingSettings/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 ExtendedDatabaseBlobAuditingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go b/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go new file mode 100644 index 00000000000..6b253b81cee --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go @@ -0,0 +1,106 @@ +package blobauditing + +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 ExtendedDatabaseBlobAuditingPoliciesListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtendedDatabaseBlobAuditingPolicy +} + +type ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtendedDatabaseBlobAuditingPolicy +} + +type ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ExtendedDatabaseBlobAuditingPoliciesListByDatabase ... +func (c BlobAuditingClient) ExtendedDatabaseBlobAuditingPoliciesListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ExtendedDatabaseBlobAuditingPoliciesListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/extendedAuditingSettings", 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 *[]ExtendedDatabaseBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExtendedDatabaseBlobAuditingPoliciesListByDatabaseComplete retrieves all the results into a single object +func (c BlobAuditingClient) ExtendedDatabaseBlobAuditingPoliciesListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteResult, error) { + return c.ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteMatchingPredicate(ctx, id, ExtendedDatabaseBlobAuditingPolicyOperationPredicate{}) +} + +// ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BlobAuditingClient) ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate ExtendedDatabaseBlobAuditingPolicyOperationPredicate) (result ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteResult, err error) { + items := make([]ExtendedDatabaseBlobAuditingPolicy, 0) + + resp, err := c.ExtendedDatabaseBlobAuditingPoliciesListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExtendedDatabaseBlobAuditingPoliciesListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..83a36bcc67f --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go @@ -0,0 +1,76 @@ +package blobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedServerBlobAuditingPoliciesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ExtendedServerBlobAuditingPolicy +} + +// ExtendedServerBlobAuditingPoliciesCreateOrUpdate ... +func (c BlobAuditingClient) ExtendedServerBlobAuditingPoliciesCreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ExtendedServerBlobAuditingPolicy) (result ExtendedServerBlobAuditingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/extendedAuditingSettings/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ExtendedServerBlobAuditingPoliciesCreateOrUpdateThenPoll performs ExtendedServerBlobAuditingPoliciesCreateOrUpdate then polls until it's completed +func (c BlobAuditingClient) ExtendedServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ExtendedServerBlobAuditingPolicy) error { + result, err := c.ExtendedServerBlobAuditingPoliciesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ExtendedServerBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ExtendedServerBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciesget.go b/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciesget.go new file mode 100644 index 00000000000..f23d1799caf --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpoliciesget.go @@ -0,0 +1,55 @@ +package blobauditing + +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 ExtendedServerBlobAuditingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtendedServerBlobAuditingPolicy +} + +// ExtendedServerBlobAuditingPoliciesGet ... +func (c BlobAuditingClient) ExtendedServerBlobAuditingPoliciesGet(ctx context.Context, id commonids.SqlServerId) (result ExtendedServerBlobAuditingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/extendedAuditingSettings/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 ExtendedServerBlobAuditingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go b/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go new file mode 100644 index 00000000000..a457eacc4b5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go @@ -0,0 +1,106 @@ +package blobauditing + +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 ExtendedServerBlobAuditingPoliciesListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtendedServerBlobAuditingPolicy +} + +type ExtendedServerBlobAuditingPoliciesListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtendedServerBlobAuditingPolicy +} + +type ExtendedServerBlobAuditingPoliciesListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ExtendedServerBlobAuditingPoliciesListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ExtendedServerBlobAuditingPoliciesListByServer ... +func (c BlobAuditingClient) ExtendedServerBlobAuditingPoliciesListByServer(ctx context.Context, id commonids.SqlServerId) (result ExtendedServerBlobAuditingPoliciesListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ExtendedServerBlobAuditingPoliciesListByServerCustomPager{}, + Path: fmt.Sprintf("%s/extendedAuditingSettings", 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 *[]ExtendedServerBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExtendedServerBlobAuditingPoliciesListByServerComplete retrieves all the results into a single object +func (c BlobAuditingClient) ExtendedServerBlobAuditingPoliciesListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ExtendedServerBlobAuditingPoliciesListByServerCompleteResult, error) { + return c.ExtendedServerBlobAuditingPoliciesListByServerCompleteMatchingPredicate(ctx, id, ExtendedServerBlobAuditingPolicyOperationPredicate{}) +} + +// ExtendedServerBlobAuditingPoliciesListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BlobAuditingClient) ExtendedServerBlobAuditingPoliciesListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ExtendedServerBlobAuditingPolicyOperationPredicate) (result ExtendedServerBlobAuditingPoliciesListByServerCompleteResult, err error) { + items := make([]ExtendedServerBlobAuditingPolicy, 0) + + resp, err := c.ExtendedServerBlobAuditingPoliciesListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExtendedServerBlobAuditingPoliciesListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..4236b2618f4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciescreateorupdate.go @@ -0,0 +1,76 @@ +package blobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerBlobAuditingPoliciesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerBlobAuditingPolicy +} + +// ServerBlobAuditingPoliciesCreateOrUpdate ... +func (c BlobAuditingClient) ServerBlobAuditingPoliciesCreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerBlobAuditingPolicy) (result ServerBlobAuditingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/auditingSettings/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ServerBlobAuditingPoliciesCreateOrUpdateThenPoll performs ServerBlobAuditingPoliciesCreateOrUpdate then polls until it's completed +func (c BlobAuditingClient) ServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerBlobAuditingPolicy) error { + result, err := c.ServerBlobAuditingPoliciesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ServerBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ServerBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciesget.go b/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciesget.go new file mode 100644 index 00000000000..bf9a8ef1b2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpoliciesget.go @@ -0,0 +1,55 @@ +package blobauditing + +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 ServerBlobAuditingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerBlobAuditingPolicy +} + +// ServerBlobAuditingPoliciesGet ... +func (c BlobAuditingClient) ServerBlobAuditingPoliciesGet(ctx context.Context, id commonids.SqlServerId) (result ServerBlobAuditingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/auditingSettings/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 ServerBlobAuditingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpolicieslistbyserver.go b/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpolicieslistbyserver.go new file mode 100644 index 00000000000..31b78fd7086 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/method_serverblobauditingpolicieslistbyserver.go @@ -0,0 +1,106 @@ +package blobauditing + +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 ServerBlobAuditingPoliciesListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerBlobAuditingPolicy +} + +type ServerBlobAuditingPoliciesListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerBlobAuditingPolicy +} + +type ServerBlobAuditingPoliciesListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ServerBlobAuditingPoliciesListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ServerBlobAuditingPoliciesListByServer ... +func (c BlobAuditingClient) ServerBlobAuditingPoliciesListByServer(ctx context.Context, id commonids.SqlServerId) (result ServerBlobAuditingPoliciesListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ServerBlobAuditingPoliciesListByServerCustomPager{}, + Path: fmt.Sprintf("%s/auditingSettings", 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 *[]ServerBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ServerBlobAuditingPoliciesListByServerComplete retrieves all the results into a single object +func (c BlobAuditingClient) ServerBlobAuditingPoliciesListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ServerBlobAuditingPoliciesListByServerCompleteResult, error) { + return c.ServerBlobAuditingPoliciesListByServerCompleteMatchingPredicate(ctx, id, ServerBlobAuditingPolicyOperationPredicate{}) +} + +// ServerBlobAuditingPoliciesListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BlobAuditingClient) ServerBlobAuditingPoliciesListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerBlobAuditingPolicyOperationPredicate) (result ServerBlobAuditingPoliciesListByServerCompleteResult, err error) { + items := make([]ServerBlobAuditingPolicy, 0) + + resp, err := c.ServerBlobAuditingPoliciesListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ServerBlobAuditingPoliciesListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicy.go b/resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicy.go new file mode 100644 index 00000000000..c49c188eb33 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicy.go @@ -0,0 +1,12 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicyproperties.go b/resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicyproperties.go new file mode 100644 index 00000000000..86f368bfaa0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_databaseblobauditingpolicyproperties.go @@ -0,0 +1,17 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicy.go b/resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicy.go new file mode 100644 index 00000000000..89e191ff935 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicy.go @@ -0,0 +1,11 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedDatabaseBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtendedDatabaseBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go b/resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go new file mode 100644 index 00000000000..8b01ff183ba --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go @@ -0,0 +1,18 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedDatabaseBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + PredicateExpression *string `json:"predicateExpression,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicy.go b/resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicy.go new file mode 100644 index 00000000000..7e6cc8e1443 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicy.go @@ -0,0 +1,11 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedServerBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtendedServerBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicyproperties.go b/resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicyproperties.go new file mode 100644 index 00000000000..f206ba4354b --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_extendedserverblobauditingpolicyproperties.go @@ -0,0 +1,19 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedServerBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsDevopsAuditEnabled *bool `json:"isDevopsAuditEnabled,omitempty"` + IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + PredicateExpression *string `json:"predicateExpression,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicy.go b/resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicy.go new file mode 100644 index 00000000000..0b54ee019c4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicy.go @@ -0,0 +1,11 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicyproperties.go b/resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicyproperties.go new file mode 100644 index 00000000000..03316ef462a --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/model_serverblobauditingpolicyproperties.go @@ -0,0 +1,18 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsDevopsAuditEnabled *bool `json:"isDevopsAuditEnabled,omitempty"` + IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/blobauditing/predicates.go b/resource-manager/sql/2023-08-01/blobauditing/predicates.go new file mode 100644 index 00000000000..0515898ea7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/predicates.go @@ -0,0 +1,101 @@ +package blobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseBlobAuditingPolicyOperationPredicate struct { + Id *string + Kind *string + Name *string + Type *string +} + +func (p DatabaseBlobAuditingPolicyOperationPredicate) Matches(input DatabaseBlobAuditingPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ExtendedDatabaseBlobAuditingPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExtendedDatabaseBlobAuditingPolicyOperationPredicate) Matches(input ExtendedDatabaseBlobAuditingPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ExtendedServerBlobAuditingPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExtendedServerBlobAuditingPolicyOperationPredicate) Matches(input ExtendedServerBlobAuditingPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ServerBlobAuditingPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerBlobAuditingPolicyOperationPredicate) Matches(input ServerBlobAuditingPolicy) 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/sql/2023-08-01/blobauditing/version.go b/resource-manager/sql/2023-08-01/blobauditing/version.go new file mode 100644 index 00000000000..f3972674b63 --- /dev/null +++ b/resource-manager/sql/2023-08-01/blobauditing/version.go @@ -0,0 +1,10 @@ +package blobauditing + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/blobauditing/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/client.go b/resource-manager/sql/2023-08-01/client.go new file mode 100644 index 00000000000..bb4778c368c --- /dev/null +++ b/resource-manager/sql/2023-08-01/client.go @@ -0,0 +1,1270 @@ +package v2023_08_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/backupshorttermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/blobauditing" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseadvisors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseautomatictuning" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasecolumns" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseextensions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaserecommendedactions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseschemas" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasetables" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datamaskingpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datamaskingrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datawarehouseuseractivities" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/deletedservers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/distributedavailabilitygroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/elasticpooloperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/elasticpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/encryptionprotectors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/endpointcertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/failovergroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/geobackuppolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/instancefailovergroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/instancepools" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/ipv6firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobagents" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobcredentials" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobexecutions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobprivateendpoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobstepexecutions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobsteps" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobtargetexecutions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobtargetgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/ledgerdigestuploads" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/locationcapabilities" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionbackups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/maintenancewindowoptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/maintenancewindows" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasecolumns" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasemoveoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasequeries" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaserestoredetails" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaseschemas" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesecurityevents" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasetables" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceadministrators" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancedtcs" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancekeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancetdecertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedledgerdigestuploads" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedserverdnsaliases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/outboundfirewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/recoverabledatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/recoverablemanageddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/replicationlinks" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorabledroppeddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorepoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sensitivitylabels" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveradvisors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverautomatictuning" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverazureadadministrators" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverazureadonlyauthentications" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverconfigurationoptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverconnectionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverdevopsaudit" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverdnsaliases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverkeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveroperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serversecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servertrustcertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servertrustgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servervulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlagent" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/subscriptionusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/synapselinkworkspaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncagents" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncmembers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/tdecertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/timezones" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/transparentdataencryptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/usages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/virtualclusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/virtualnetworkrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/workloadclassifiers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/workloadgroups" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + BackupShortTermRetentionPolicies *backupshorttermretentionpolicies.BackupShortTermRetentionPoliciesClient + BlobAuditing *blobauditing.BlobAuditingClient + DataMaskingPolicies *datamaskingpolicies.DataMaskingPoliciesClient + DataMaskingRules *datamaskingrules.DataMaskingRulesClient + DataWarehouseUserActivities *datawarehouseuseractivities.DataWarehouseUserActivitiesClient + DatabaseAdvancedThreatProtectionSettings *databaseadvancedthreatprotectionsettings.DatabaseAdvancedThreatProtectionSettingsClient + DatabaseAdvisors *databaseadvisors.DatabaseAdvisorsClient + DatabaseAutomaticTuning *databaseautomatictuning.DatabaseAutomaticTuningClient + DatabaseColumns *databasecolumns.DatabaseColumnsClient + DatabaseEncryptionProtectorRevalidate *databaseencryptionprotectorrevalidate.DatabaseEncryptionProtectorRevalidateClient + DatabaseEncryptionProtectorRevert *databaseencryptionprotectorrevert.DatabaseEncryptionProtectorRevertClient + DatabaseExtensions *databaseextensions.DatabaseExtensionsClient + DatabaseOperations *databaseoperations.DatabaseOperationsClient + DatabaseRecommendedActions *databaserecommendedactions.DatabaseRecommendedActionsClient + DatabaseSchemas *databaseschemas.DatabaseSchemasClient + DatabaseSecurityAlertPolicies *databasesecurityalertpolicies.DatabaseSecurityAlertPoliciesClient + DatabaseSqlVulnerabilityAssessmentBaselines *databasesqlvulnerabilityassessmentbaselines.DatabaseSqlVulnerabilityAssessmentBaselinesClient + DatabaseSqlVulnerabilityAssessmentExecuteScan *databasesqlvulnerabilityassessmentexecutescan.DatabaseSqlVulnerabilityAssessmentExecuteScanClient + DatabaseSqlVulnerabilityAssessmentRuleBaselines *databasesqlvulnerabilityassessmentrulebaselines.DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient + DatabaseSqlVulnerabilityAssessmentScanResult *databasesqlvulnerabilityassessmentscanresult.DatabaseSqlVulnerabilityAssessmentScanResultClient + DatabaseSqlVulnerabilityAssessmentScans *databasesqlvulnerabilityassessmentscans.DatabaseSqlVulnerabilityAssessmentScansClient + DatabaseSqlVulnerabilityAssessmentsSettings *databasesqlvulnerabilityassessmentssettings.DatabaseSqlVulnerabilityAssessmentsSettingsClient + DatabaseTables *databasetables.DatabaseTablesClient + DatabaseUsages *databaseusages.DatabaseUsagesClient + DatabaseVulnerabilityAssessmentRuleBaselines *databasevulnerabilityassessmentrulebaselines.DatabaseVulnerabilityAssessmentRuleBaselinesClient + DatabaseVulnerabilityAssessmentScans *databasevulnerabilityassessmentscans.DatabaseVulnerabilityAssessmentScansClient + DatabaseVulnerabilityAssessments *databasevulnerabilityassessments.DatabaseVulnerabilityAssessmentsClient + Databases *databases.DatabasesClient + DeletedServers *deletedservers.DeletedServersClient + DistributedAvailabilityGroups *distributedavailabilitygroups.DistributedAvailabilityGroupsClient + ElasticPoolOperations *elasticpooloperations.ElasticPoolOperationsClient + ElasticPools *elasticpools.ElasticPoolsClient + EncryptionProtectors *encryptionprotectors.EncryptionProtectorsClient + EndpointCertificates *endpointcertificates.EndpointCertificatesClient + FailoverGroups *failovergroups.FailoverGroupsClient + FirewallRules *firewallrules.FirewallRulesClient + GeoBackupPolicies *geobackuppolicies.GeoBackupPoliciesClient + IPv6FirewallRules *ipv6firewallrules.IPv6FirewallRulesClient + InstanceFailoverGroups *instancefailovergroups.InstanceFailoverGroupsClient + InstancePools *instancepools.InstancePoolsClient + JobAgents *jobagents.JobAgentsClient + JobCredentials *jobcredentials.JobCredentialsClient + JobExecutions *jobexecutions.JobExecutionsClient + JobPrivateEndpoints *jobprivateendpoints.JobPrivateEndpointsClient + JobStepExecutions *jobstepexecutions.JobStepExecutionsClient + JobSteps *jobsteps.JobStepsClient + JobTargetExecutions *jobtargetexecutions.JobTargetExecutionsClient + JobTargetGroups *jobtargetgroups.JobTargetGroupsClient + JobVersions *jobversions.JobVersionsClient + Jobs *jobs.JobsClient + LedgerDigestUploads *ledgerdigestuploads.LedgerDigestUploadsClient + LocationCapabilities *locationcapabilities.LocationCapabilitiesClient + LongTermRetentionBackups *longtermretentionbackups.LongTermRetentionBackupsClient + LongTermRetentionManagedInstanceBackups *longtermretentionmanagedinstancebackups.LongTermRetentionManagedInstanceBackupsClient + LongTermRetentionPolicies *longtermretentionpolicies.LongTermRetentionPoliciesClient + MaintenanceWindowOptions *maintenancewindowoptions.MaintenanceWindowOptionsClient + MaintenanceWindows *maintenancewindows.MaintenanceWindowsClient + ManagedBackupShortTermRetentionPolicies *managedbackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPoliciesClient + ManagedDatabaseAdvancedThreatProtectionSettings *manageddatabaseadvancedthreatprotectionsettings.ManagedDatabaseAdvancedThreatProtectionSettingsClient + ManagedDatabaseColumns *manageddatabasecolumns.ManagedDatabaseColumnsClient + ManagedDatabaseMoveOperations *manageddatabasemoveoperations.ManagedDatabaseMoveOperationsClient + ManagedDatabaseQueries *manageddatabasequeries.ManagedDatabaseQueriesClient + ManagedDatabaseRestoreDetails *manageddatabaserestoredetails.ManagedDatabaseRestoreDetailsClient + ManagedDatabaseSchemas *manageddatabaseschemas.ManagedDatabaseSchemasClient + ManagedDatabaseSecurityAlertPolicies *manageddatabasesecurityalertpolicies.ManagedDatabaseSecurityAlertPoliciesClient + ManagedDatabaseSecurityEvents *manageddatabasesecurityevents.ManagedDatabaseSecurityEventsClient + ManagedDatabaseSensitivityLabels *manageddatabasesensitivitylabels.ManagedDatabaseSensitivityLabelsClient + ManagedDatabaseTables *manageddatabasetables.ManagedDatabaseTablesClient + ManagedDatabaseTransparentDataEncryption *manageddatabasetransparentdataencryption.ManagedDatabaseTransparentDataEncryptionClient + ManagedDatabaseVulnerabilityAssessmentRuleBaselines *manageddatabasevulnerabilityassessmentrulebaselines.ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient + ManagedDatabaseVulnerabilityAssessmentScans *manageddatabasevulnerabilityassessmentscans.ManagedDatabaseVulnerabilityAssessmentScansClient + ManagedDatabaseVulnerabilityAssessments *manageddatabasevulnerabilityassessments.ManagedDatabaseVulnerabilityAssessmentsClient + ManagedDatabases *manageddatabases.ManagedDatabasesClient + ManagedInstanceAdministrators *managedinstanceadministrators.ManagedInstanceAdministratorsClient + ManagedInstanceAdvancedThreatProtectionSettings *managedinstanceadvancedthreatprotectionsettings.ManagedInstanceAdvancedThreatProtectionSettingsClient + ManagedInstanceAzureADOnlyAuthentications *managedinstanceazureadonlyauthentications.ManagedInstanceAzureADOnlyAuthenticationsClient + ManagedInstanceDtcs *managedinstancedtcs.ManagedInstanceDtcsClient + ManagedInstanceEncryptionProtectors *managedinstanceencryptionprotectors.ManagedInstanceEncryptionProtectorsClient + ManagedInstanceKeys *managedinstancekeys.ManagedInstanceKeysClient + ManagedInstanceLongTermRetentionPolicies *managedinstancelongtermretentionpolicies.ManagedInstanceLongTermRetentionPoliciesClient + ManagedInstanceOperations *managedinstanceoperations.ManagedInstanceOperationsClient + ManagedInstancePrivateEndpointConnections *managedinstanceprivateendpointconnections.ManagedInstancePrivateEndpointConnectionsClient + ManagedInstancePrivateLinkResources *managedinstanceprivatelinkresources.ManagedInstancePrivateLinkResourcesClient + ManagedInstanceTdeCertificates *managedinstancetdecertificates.ManagedInstanceTdeCertificatesClient + ManagedInstanceVulnerabilityAssessments *managedinstancevulnerabilityassessments.ManagedInstanceVulnerabilityAssessmentsClient + ManagedInstances *managedinstances.ManagedInstancesClient + ManagedLedgerDigestUploads *managedledgerdigestuploads.ManagedLedgerDigestUploadsClient + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies *managedrestorabledroppeddatabasebackupshorttermretentionpolicies.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient + ManagedServerDnsAliases *managedserverdnsaliases.ManagedServerDnsAliasesClient + ManagedServerSecurityAlertPolicies *managedserversecurityalertpolicies.ManagedServerSecurityAlertPoliciesClient + NetworkSecurityPerimeterConfigurations *networksecurityperimeterconfigurations.NetworkSecurityPerimeterConfigurationsClient + OutboundFirewallRules *outboundfirewallrules.OutboundFirewallRulesClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + RecoverableDatabases *recoverabledatabases.RecoverableDatabasesClient + RecoverableManagedDatabases *recoverablemanageddatabases.RecoverableManagedDatabasesClient + ReplicationLinks *replicationlinks.ReplicationLinksClient + RestorableDroppedDatabases *restorabledroppeddatabases.RestorableDroppedDatabasesClient + RestorableDroppedManagedDatabases *restorabledroppedmanageddatabases.RestorableDroppedManagedDatabasesClient + RestorePoints *restorepoints.RestorePointsClient + SensitivityLabels *sensitivitylabels.SensitivityLabelsClient + ServerAdvancedThreatProtectionSettings *serveradvancedthreatprotectionsettings.ServerAdvancedThreatProtectionSettingsClient + ServerAdvisors *serveradvisors.ServerAdvisorsClient + ServerAutomaticTuning *serverautomatictuning.ServerAutomaticTuningClient + ServerAzureADAdministrators *serverazureadadministrators.ServerAzureADAdministratorsClient + ServerAzureADOnlyAuthentications *serverazureadonlyauthentications.ServerAzureADOnlyAuthenticationsClient + ServerConfigurationOptions *serverconfigurationoptions.ServerConfigurationOptionsClient + ServerConnectionPolicies *serverconnectionpolicies.ServerConnectionPoliciesClient + ServerDevOpsAudit *serverdevopsaudit.ServerDevOpsAuditClient + ServerDnsAliases *serverdnsaliases.ServerDnsAliasesClient + ServerKeys *serverkeys.ServerKeysClient + ServerOperations *serveroperations.ServerOperationsClient + ServerSecurityAlertPolicies *serversecurityalertpolicies.ServerSecurityAlertPoliciesClient + ServerTrustCertificates *servertrustcertificates.ServerTrustCertificatesClient + ServerTrustGroups *servertrustgroups.ServerTrustGroupsClient + ServerUsages *serverusages.ServerUsagesClient + ServerVulnerabilityAssessments *servervulnerabilityassessments.ServerVulnerabilityAssessmentsClient + Servers *servers.ServersClient + SqlAgent *sqlagent.SqlAgentClient + SqlVulnerabilityAssessmentBaseline *sqlvulnerabilityassessmentbaseline.SqlVulnerabilityAssessmentBaselineClient + SqlVulnerabilityAssessmentExecuteScan *sqlvulnerabilityassessmentexecutescan.SqlVulnerabilityAssessmentExecuteScanClient + SqlVulnerabilityAssessmentRuleBaseline *sqlvulnerabilityassessmentrulebaseline.SqlVulnerabilityAssessmentRuleBaselineClient + SqlVulnerabilityAssessmentScanResult *sqlvulnerabilityassessmentscanresult.SqlVulnerabilityAssessmentScanResultClient + SqlVulnerabilityAssessmentScans *sqlvulnerabilityassessmentscans.SqlVulnerabilityAssessmentScansClient + SqlVulnerabilityAssessmentsSettings *sqlvulnerabilityassessmentssettings.SqlVulnerabilityAssessmentsSettingsClient + StartStopManagedInstanceSchedules *startstopmanagedinstanceschedules.StartStopManagedInstanceSchedulesClient + SubscriptionUsages *subscriptionusages.SubscriptionUsagesClient + SynapseLinkWorkspaces *synapselinkworkspaces.SynapseLinkWorkspacesClient + SyncAgents *syncagents.SyncAgentsClient + SyncGroups *syncgroups.SyncGroupsClient + SyncMembers *syncmembers.SyncMembersClient + TdeCertificates *tdecertificates.TdeCertificatesClient + TimeZones *timezones.TimeZonesClient + TransparentDataEncryptions *transparentdataencryptions.TransparentDataEncryptionsClient + Usages *usages.UsagesClient + VirtualClusters *virtualclusters.VirtualClustersClient + VirtualNetworkRules *virtualnetworkrules.VirtualNetworkRulesClient + WorkloadClassifiers *workloadclassifiers.WorkloadClassifiersClient + WorkloadGroups *workloadgroups.WorkloadGroupsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + backupShortTermRetentionPoliciesClient, err := backupshorttermretentionpolicies.NewBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BackupShortTermRetentionPolicies client: %+v", err) + } + configureFunc(backupShortTermRetentionPoliciesClient.Client) + + blobAuditingClient, err := blobauditing.NewBlobAuditingClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BlobAuditing client: %+v", err) + } + configureFunc(blobAuditingClient.Client) + + dataMaskingPoliciesClient, err := datamaskingpolicies.NewDataMaskingPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataMaskingPolicies client: %+v", err) + } + configureFunc(dataMaskingPoliciesClient.Client) + + dataMaskingRulesClient, err := datamaskingrules.NewDataMaskingRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataMaskingRules client: %+v", err) + } + configureFunc(dataMaskingRulesClient.Client) + + dataWarehouseUserActivitiesClient, err := datawarehouseuseractivities.NewDataWarehouseUserActivitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataWarehouseUserActivities client: %+v", err) + } + configureFunc(dataWarehouseUserActivitiesClient.Client) + + databaseAdvancedThreatProtectionSettingsClient, err := databaseadvancedthreatprotectionsettings.NewDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseAdvancedThreatProtectionSettings client: %+v", err) + } + configureFunc(databaseAdvancedThreatProtectionSettingsClient.Client) + + databaseAdvisorsClient, err := databaseadvisors.NewDatabaseAdvisorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseAdvisors client: %+v", err) + } + configureFunc(databaseAdvisorsClient.Client) + + databaseAutomaticTuningClient, err := databaseautomatictuning.NewDatabaseAutomaticTuningClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseAutomaticTuning client: %+v", err) + } + configureFunc(databaseAutomaticTuningClient.Client) + + databaseColumnsClient, err := databasecolumns.NewDatabaseColumnsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseColumns client: %+v", err) + } + configureFunc(databaseColumnsClient.Client) + + databaseEncryptionProtectorRevalidateClient, err := databaseencryptionprotectorrevalidate.NewDatabaseEncryptionProtectorRevalidateClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseEncryptionProtectorRevalidate client: %+v", err) + } + configureFunc(databaseEncryptionProtectorRevalidateClient.Client) + + databaseEncryptionProtectorRevertClient, err := databaseencryptionprotectorrevert.NewDatabaseEncryptionProtectorRevertClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseEncryptionProtectorRevert client: %+v", err) + } + configureFunc(databaseEncryptionProtectorRevertClient.Client) + + databaseExtensionsClient, err := databaseextensions.NewDatabaseExtensionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseExtensions client: %+v", err) + } + configureFunc(databaseExtensionsClient.Client) + + databaseOperationsClient, err := databaseoperations.NewDatabaseOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseOperations client: %+v", err) + } + configureFunc(databaseOperationsClient.Client) + + databaseRecommendedActionsClient, err := databaserecommendedactions.NewDatabaseRecommendedActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseRecommendedActions client: %+v", err) + } + configureFunc(databaseRecommendedActionsClient.Client) + + databaseSchemasClient, err := databaseschemas.NewDatabaseSchemasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSchemas client: %+v", err) + } + configureFunc(databaseSchemasClient.Client) + + databaseSecurityAlertPoliciesClient, err := databasesecurityalertpolicies.NewDatabaseSecurityAlertPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSecurityAlertPolicies client: %+v", err) + } + configureFunc(databaseSecurityAlertPoliciesClient.Client) + + databaseSqlVulnerabilityAssessmentBaselinesClient, err := databasesqlvulnerabilityassessmentbaselines.NewDatabaseSqlVulnerabilityAssessmentBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSqlVulnerabilityAssessmentBaselines client: %+v", err) + } + configureFunc(databaseSqlVulnerabilityAssessmentBaselinesClient.Client) + + databaseSqlVulnerabilityAssessmentExecuteScanClient, err := databasesqlvulnerabilityassessmentexecutescan.NewDatabaseSqlVulnerabilityAssessmentExecuteScanClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSqlVulnerabilityAssessmentExecuteScan client: %+v", err) + } + configureFunc(databaseSqlVulnerabilityAssessmentExecuteScanClient.Client) + + databaseSqlVulnerabilityAssessmentRuleBaselinesClient, err := databasesqlvulnerabilityassessmentrulebaselines.NewDatabaseSqlVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSqlVulnerabilityAssessmentRuleBaselines client: %+v", err) + } + configureFunc(databaseSqlVulnerabilityAssessmentRuleBaselinesClient.Client) + + databaseSqlVulnerabilityAssessmentScanResultClient, err := databasesqlvulnerabilityassessmentscanresult.NewDatabaseSqlVulnerabilityAssessmentScanResultClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSqlVulnerabilityAssessmentScanResult client: %+v", err) + } + configureFunc(databaseSqlVulnerabilityAssessmentScanResultClient.Client) + + databaseSqlVulnerabilityAssessmentScansClient, err := databasesqlvulnerabilityassessmentscans.NewDatabaseSqlVulnerabilityAssessmentScansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSqlVulnerabilityAssessmentScans client: %+v", err) + } + configureFunc(databaseSqlVulnerabilityAssessmentScansClient.Client) + + databaseSqlVulnerabilityAssessmentsSettingsClient, err := databasesqlvulnerabilityassessmentssettings.NewDatabaseSqlVulnerabilityAssessmentsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseSqlVulnerabilityAssessmentsSettings client: %+v", err) + } + configureFunc(databaseSqlVulnerabilityAssessmentsSettingsClient.Client) + + databaseTablesClient, err := databasetables.NewDatabaseTablesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseTables client: %+v", err) + } + configureFunc(databaseTablesClient.Client) + + databaseUsagesClient, err := databaseusages.NewDatabaseUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseUsages client: %+v", err) + } + configureFunc(databaseUsagesClient.Client) + + databaseVulnerabilityAssessmentRuleBaselinesClient, err := databasevulnerabilityassessmentrulebaselines.NewDatabaseVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseVulnerabilityAssessmentRuleBaselines client: %+v", err) + } + configureFunc(databaseVulnerabilityAssessmentRuleBaselinesClient.Client) + + databaseVulnerabilityAssessmentScansClient, err := databasevulnerabilityassessmentscans.NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseVulnerabilityAssessmentScans client: %+v", err) + } + configureFunc(databaseVulnerabilityAssessmentScansClient.Client) + + databaseVulnerabilityAssessmentsClient, err := databasevulnerabilityassessments.NewDatabaseVulnerabilityAssessmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseVulnerabilityAssessments client: %+v", err) + } + configureFunc(databaseVulnerabilityAssessmentsClient.Client) + + databasesClient, err := databases.NewDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Databases client: %+v", err) + } + configureFunc(databasesClient.Client) + + deletedServersClient, err := deletedservers.NewDeletedServersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeletedServers client: %+v", err) + } + configureFunc(deletedServersClient.Client) + + distributedAvailabilityGroupsClient, err := distributedavailabilitygroups.NewDistributedAvailabilityGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DistributedAvailabilityGroups client: %+v", err) + } + configureFunc(distributedAvailabilityGroupsClient.Client) + + elasticPoolOperationsClient, err := elasticpooloperations.NewElasticPoolOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ElasticPoolOperations client: %+v", err) + } + configureFunc(elasticPoolOperationsClient.Client) + + elasticPoolsClient, err := elasticpools.NewElasticPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ElasticPools client: %+v", err) + } + configureFunc(elasticPoolsClient.Client) + + encryptionProtectorsClient, err := encryptionprotectors.NewEncryptionProtectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EncryptionProtectors client: %+v", err) + } + configureFunc(encryptionProtectorsClient.Client) + + endpointCertificatesClient, err := endpointcertificates.NewEndpointCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EndpointCertificates client: %+v", err) + } + configureFunc(endpointCertificatesClient.Client) + + failoverGroupsClient, err := failovergroups.NewFailoverGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FailoverGroups client: %+v", err) + } + configureFunc(failoverGroupsClient.Client) + + firewallRulesClient, err := firewallrules.NewFirewallRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FirewallRules client: %+v", err) + } + configureFunc(firewallRulesClient.Client) + + geoBackupPoliciesClient, err := geobackuppolicies.NewGeoBackupPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building GeoBackupPolicies client: %+v", err) + } + configureFunc(geoBackupPoliciesClient.Client) + + iPv6FirewallRulesClient, err := ipv6firewallrules.NewIPv6FirewallRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IPv6FirewallRules client: %+v", err) + } + configureFunc(iPv6FirewallRulesClient.Client) + + instanceFailoverGroupsClient, err := instancefailovergroups.NewInstanceFailoverGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building InstanceFailoverGroups client: %+v", err) + } + configureFunc(instanceFailoverGroupsClient.Client) + + instancePoolsClient, err := instancepools.NewInstancePoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building InstancePools client: %+v", err) + } + configureFunc(instancePoolsClient.Client) + + jobAgentsClient, err := jobagents.NewJobAgentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobAgents client: %+v", err) + } + configureFunc(jobAgentsClient.Client) + + jobCredentialsClient, err := jobcredentials.NewJobCredentialsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobCredentials client: %+v", err) + } + configureFunc(jobCredentialsClient.Client) + + jobExecutionsClient, err := jobexecutions.NewJobExecutionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobExecutions client: %+v", err) + } + configureFunc(jobExecutionsClient.Client) + + jobPrivateEndpointsClient, err := jobprivateendpoints.NewJobPrivateEndpointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobPrivateEndpoints client: %+v", err) + } + configureFunc(jobPrivateEndpointsClient.Client) + + jobStepExecutionsClient, err := jobstepexecutions.NewJobStepExecutionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobStepExecutions client: %+v", err) + } + configureFunc(jobStepExecutionsClient.Client) + + jobStepsClient, err := jobsteps.NewJobStepsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobSteps client: %+v", err) + } + configureFunc(jobStepsClient.Client) + + jobTargetExecutionsClient, err := jobtargetexecutions.NewJobTargetExecutionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobTargetExecutions client: %+v", err) + } + configureFunc(jobTargetExecutionsClient.Client) + + jobTargetGroupsClient, err := jobtargetgroups.NewJobTargetGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobTargetGroups client: %+v", err) + } + configureFunc(jobTargetGroupsClient.Client) + + jobVersionsClient, err := jobversions.NewJobVersionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building JobVersions client: %+v", err) + } + configureFunc(jobVersionsClient.Client) + + jobsClient, err := jobs.NewJobsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Jobs client: %+v", err) + } + configureFunc(jobsClient.Client) + + ledgerDigestUploadsClient, err := ledgerdigestuploads.NewLedgerDigestUploadsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LedgerDigestUploads client: %+v", err) + } + configureFunc(ledgerDigestUploadsClient.Client) + + locationCapabilitiesClient, err := locationcapabilities.NewLocationCapabilitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LocationCapabilities client: %+v", err) + } + configureFunc(locationCapabilitiesClient.Client) + + longTermRetentionBackupsClient, err := longtermretentionbackups.NewLongTermRetentionBackupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LongTermRetentionBackups client: %+v", err) + } + configureFunc(longTermRetentionBackupsClient.Client) + + longTermRetentionManagedInstanceBackupsClient, err := longtermretentionmanagedinstancebackups.NewLongTermRetentionManagedInstanceBackupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LongTermRetentionManagedInstanceBackups client: %+v", err) + } + configureFunc(longTermRetentionManagedInstanceBackupsClient.Client) + + longTermRetentionPoliciesClient, err := longtermretentionpolicies.NewLongTermRetentionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LongTermRetentionPolicies client: %+v", err) + } + configureFunc(longTermRetentionPoliciesClient.Client) + + maintenanceWindowOptionsClient, err := maintenancewindowoptions.NewMaintenanceWindowOptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MaintenanceWindowOptions client: %+v", err) + } + configureFunc(maintenanceWindowOptionsClient.Client) + + maintenanceWindowsClient, err := maintenancewindows.NewMaintenanceWindowsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MaintenanceWindows client: %+v", err) + } + configureFunc(maintenanceWindowsClient.Client) + + managedBackupShortTermRetentionPoliciesClient, err := managedbackupshorttermretentionpolicies.NewManagedBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedBackupShortTermRetentionPolicies client: %+v", err) + } + configureFunc(managedBackupShortTermRetentionPoliciesClient.Client) + + managedDatabaseAdvancedThreatProtectionSettingsClient, err := manageddatabaseadvancedthreatprotectionsettings.NewManagedDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseAdvancedThreatProtectionSettings client: %+v", err) + } + configureFunc(managedDatabaseAdvancedThreatProtectionSettingsClient.Client) + + managedDatabaseColumnsClient, err := manageddatabasecolumns.NewManagedDatabaseColumnsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseColumns client: %+v", err) + } + configureFunc(managedDatabaseColumnsClient.Client) + + managedDatabaseMoveOperationsClient, err := manageddatabasemoveoperations.NewManagedDatabaseMoveOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseMoveOperations client: %+v", err) + } + configureFunc(managedDatabaseMoveOperationsClient.Client) + + managedDatabaseQueriesClient, err := manageddatabasequeries.NewManagedDatabaseQueriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseQueries client: %+v", err) + } + configureFunc(managedDatabaseQueriesClient.Client) + + managedDatabaseRestoreDetailsClient, err := manageddatabaserestoredetails.NewManagedDatabaseRestoreDetailsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseRestoreDetails client: %+v", err) + } + configureFunc(managedDatabaseRestoreDetailsClient.Client) + + managedDatabaseSchemasClient, err := manageddatabaseschemas.NewManagedDatabaseSchemasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseSchemas client: %+v", err) + } + configureFunc(managedDatabaseSchemasClient.Client) + + managedDatabaseSecurityAlertPoliciesClient, err := manageddatabasesecurityalertpolicies.NewManagedDatabaseSecurityAlertPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseSecurityAlertPolicies client: %+v", err) + } + configureFunc(managedDatabaseSecurityAlertPoliciesClient.Client) + + managedDatabaseSecurityEventsClient, err := manageddatabasesecurityevents.NewManagedDatabaseSecurityEventsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseSecurityEvents client: %+v", err) + } + configureFunc(managedDatabaseSecurityEventsClient.Client) + + managedDatabaseSensitivityLabelsClient, err := manageddatabasesensitivitylabels.NewManagedDatabaseSensitivityLabelsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseSensitivityLabels client: %+v", err) + } + configureFunc(managedDatabaseSensitivityLabelsClient.Client) + + managedDatabaseTablesClient, err := manageddatabasetables.NewManagedDatabaseTablesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseTables client: %+v", err) + } + configureFunc(managedDatabaseTablesClient.Client) + + managedDatabaseTransparentDataEncryptionClient, err := manageddatabasetransparentdataencryption.NewManagedDatabaseTransparentDataEncryptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseTransparentDataEncryption client: %+v", err) + } + configureFunc(managedDatabaseTransparentDataEncryptionClient.Client) + + managedDatabaseVulnerabilityAssessmentRuleBaselinesClient, err := manageddatabasevulnerabilityassessmentrulebaselines.NewManagedDatabaseVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseVulnerabilityAssessmentRuleBaselines client: %+v", err) + } + configureFunc(managedDatabaseVulnerabilityAssessmentRuleBaselinesClient.Client) + + managedDatabaseVulnerabilityAssessmentScansClient, err := manageddatabasevulnerabilityassessmentscans.NewManagedDatabaseVulnerabilityAssessmentScansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseVulnerabilityAssessmentScans client: %+v", err) + } + configureFunc(managedDatabaseVulnerabilityAssessmentScansClient.Client) + + managedDatabaseVulnerabilityAssessmentsClient, err := manageddatabasevulnerabilityassessments.NewManagedDatabaseVulnerabilityAssessmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabaseVulnerabilityAssessments client: %+v", err) + } + configureFunc(managedDatabaseVulnerabilityAssessmentsClient.Client) + + managedDatabasesClient, err := manageddatabases.NewManagedDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedDatabases client: %+v", err) + } + configureFunc(managedDatabasesClient.Client) + + managedInstanceAdministratorsClient, err := managedinstanceadministrators.NewManagedInstanceAdministratorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceAdministrators client: %+v", err) + } + configureFunc(managedInstanceAdministratorsClient.Client) + + managedInstanceAdvancedThreatProtectionSettingsClient, err := managedinstanceadvancedthreatprotectionsettings.NewManagedInstanceAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceAdvancedThreatProtectionSettings client: %+v", err) + } + configureFunc(managedInstanceAdvancedThreatProtectionSettingsClient.Client) + + managedInstanceAzureADOnlyAuthenticationsClient, err := managedinstanceazureadonlyauthentications.NewManagedInstanceAzureADOnlyAuthenticationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceAzureADOnlyAuthentications client: %+v", err) + } + configureFunc(managedInstanceAzureADOnlyAuthenticationsClient.Client) + + managedInstanceDtcsClient, err := managedinstancedtcs.NewManagedInstanceDtcsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceDtcs client: %+v", err) + } + configureFunc(managedInstanceDtcsClient.Client) + + managedInstanceEncryptionProtectorsClient, err := managedinstanceencryptionprotectors.NewManagedInstanceEncryptionProtectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceEncryptionProtectors client: %+v", err) + } + configureFunc(managedInstanceEncryptionProtectorsClient.Client) + + managedInstanceKeysClient, err := managedinstancekeys.NewManagedInstanceKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceKeys client: %+v", err) + } + configureFunc(managedInstanceKeysClient.Client) + + managedInstanceLongTermRetentionPoliciesClient, err := managedinstancelongtermretentionpolicies.NewManagedInstanceLongTermRetentionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceLongTermRetentionPolicies client: %+v", err) + } + configureFunc(managedInstanceLongTermRetentionPoliciesClient.Client) + + managedInstanceOperationsClient, err := managedinstanceoperations.NewManagedInstanceOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceOperations client: %+v", err) + } + configureFunc(managedInstanceOperationsClient.Client) + + managedInstancePrivateEndpointConnectionsClient, err := managedinstanceprivateendpointconnections.NewManagedInstancePrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstancePrivateEndpointConnections client: %+v", err) + } + configureFunc(managedInstancePrivateEndpointConnectionsClient.Client) + + managedInstancePrivateLinkResourcesClient, err := managedinstanceprivatelinkresources.NewManagedInstancePrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstancePrivateLinkResources client: %+v", err) + } + configureFunc(managedInstancePrivateLinkResourcesClient.Client) + + managedInstanceTdeCertificatesClient, err := managedinstancetdecertificates.NewManagedInstanceTdeCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceTdeCertificates client: %+v", err) + } + configureFunc(managedInstanceTdeCertificatesClient.Client) + + managedInstanceVulnerabilityAssessmentsClient, err := managedinstancevulnerabilityassessments.NewManagedInstanceVulnerabilityAssessmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstanceVulnerabilityAssessments client: %+v", err) + } + configureFunc(managedInstanceVulnerabilityAssessmentsClient.Client) + + managedInstancesClient, err := managedinstances.NewManagedInstancesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedInstances client: %+v", err) + } + configureFunc(managedInstancesClient.Client) + + managedLedgerDigestUploadsClient, err := managedledgerdigestuploads.NewManagedLedgerDigestUploadsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedLedgerDigestUploads client: %+v", err) + } + configureFunc(managedLedgerDigestUploadsClient.Client) + + managedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient, err := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies client: %+v", err) + } + configureFunc(managedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.Client) + + managedServerDnsAliasesClient, err := managedserverdnsaliases.NewManagedServerDnsAliasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedServerDnsAliases client: %+v", err) + } + configureFunc(managedServerDnsAliasesClient.Client) + + managedServerSecurityAlertPoliciesClient, err := managedserversecurityalertpolicies.NewManagedServerSecurityAlertPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManagedServerSecurityAlertPolicies client: %+v", err) + } + configureFunc(managedServerSecurityAlertPoliciesClient.Client) + + networkSecurityPerimeterConfigurationsClient, err := networksecurityperimeterconfigurations.NewNetworkSecurityPerimeterConfigurationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NetworkSecurityPerimeterConfigurations client: %+v", err) + } + configureFunc(networkSecurityPerimeterConfigurationsClient.Client) + + outboundFirewallRulesClient, err := outboundfirewallrules.NewOutboundFirewallRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building OutboundFirewallRules client: %+v", err) + } + configureFunc(outboundFirewallRulesClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + recoverableDatabasesClient, err := recoverabledatabases.NewRecoverableDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RecoverableDatabases client: %+v", err) + } + configureFunc(recoverableDatabasesClient.Client) + + recoverableManagedDatabasesClient, err := recoverablemanageddatabases.NewRecoverableManagedDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RecoverableManagedDatabases client: %+v", err) + } + configureFunc(recoverableManagedDatabasesClient.Client) + + replicationLinksClient, err := replicationlinks.NewReplicationLinksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ReplicationLinks client: %+v", err) + } + configureFunc(replicationLinksClient.Client) + + restorableDroppedDatabasesClient, err := restorabledroppeddatabases.NewRestorableDroppedDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RestorableDroppedDatabases client: %+v", err) + } + configureFunc(restorableDroppedDatabasesClient.Client) + + restorableDroppedManagedDatabasesClient, err := restorabledroppedmanageddatabases.NewRestorableDroppedManagedDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RestorableDroppedManagedDatabases client: %+v", err) + } + configureFunc(restorableDroppedManagedDatabasesClient.Client) + + restorePointsClient, err := restorepoints.NewRestorePointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RestorePoints client: %+v", err) + } + configureFunc(restorePointsClient.Client) + + sensitivityLabelsClient, err := sensitivitylabels.NewSensitivityLabelsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SensitivityLabels client: %+v", err) + } + configureFunc(sensitivityLabelsClient.Client) + + serverAdvancedThreatProtectionSettingsClient, err := serveradvancedthreatprotectionsettings.NewServerAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerAdvancedThreatProtectionSettings client: %+v", err) + } + configureFunc(serverAdvancedThreatProtectionSettingsClient.Client) + + serverAdvisorsClient, err := serveradvisors.NewServerAdvisorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerAdvisors client: %+v", err) + } + configureFunc(serverAdvisorsClient.Client) + + serverAutomaticTuningClient, err := serverautomatictuning.NewServerAutomaticTuningClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerAutomaticTuning client: %+v", err) + } + configureFunc(serverAutomaticTuningClient.Client) + + serverAzureADAdministratorsClient, err := serverazureadadministrators.NewServerAzureADAdministratorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerAzureADAdministrators client: %+v", err) + } + configureFunc(serverAzureADAdministratorsClient.Client) + + serverAzureADOnlyAuthenticationsClient, err := serverazureadonlyauthentications.NewServerAzureADOnlyAuthenticationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerAzureADOnlyAuthentications client: %+v", err) + } + configureFunc(serverAzureADOnlyAuthenticationsClient.Client) + + serverConfigurationOptionsClient, err := serverconfigurationoptions.NewServerConfigurationOptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerConfigurationOptions client: %+v", err) + } + configureFunc(serverConfigurationOptionsClient.Client) + + serverConnectionPoliciesClient, err := serverconnectionpolicies.NewServerConnectionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerConnectionPolicies client: %+v", err) + } + configureFunc(serverConnectionPoliciesClient.Client) + + serverDevOpsAuditClient, err := serverdevopsaudit.NewServerDevOpsAuditClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerDevOpsAudit client: %+v", err) + } + configureFunc(serverDevOpsAuditClient.Client) + + serverDnsAliasesClient, err := serverdnsaliases.NewServerDnsAliasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerDnsAliases client: %+v", err) + } + configureFunc(serverDnsAliasesClient.Client) + + serverKeysClient, err := serverkeys.NewServerKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerKeys client: %+v", err) + } + configureFunc(serverKeysClient.Client) + + serverOperationsClient, err := serveroperations.NewServerOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerOperations client: %+v", err) + } + configureFunc(serverOperationsClient.Client) + + serverSecurityAlertPoliciesClient, err := serversecurityalertpolicies.NewServerSecurityAlertPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerSecurityAlertPolicies client: %+v", err) + } + configureFunc(serverSecurityAlertPoliciesClient.Client) + + serverTrustCertificatesClient, err := servertrustcertificates.NewServerTrustCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerTrustCertificates client: %+v", err) + } + configureFunc(serverTrustCertificatesClient.Client) + + serverTrustGroupsClient, err := servertrustgroups.NewServerTrustGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerTrustGroups client: %+v", err) + } + configureFunc(serverTrustGroupsClient.Client) + + serverUsagesClient, err := serverusages.NewServerUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerUsages client: %+v", err) + } + configureFunc(serverUsagesClient.Client) + + serverVulnerabilityAssessmentsClient, err := servervulnerabilityassessments.NewServerVulnerabilityAssessmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ServerVulnerabilityAssessments client: %+v", err) + } + configureFunc(serverVulnerabilityAssessmentsClient.Client) + + serversClient, err := servers.NewServersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Servers client: %+v", err) + } + configureFunc(serversClient.Client) + + sqlAgentClient, err := sqlagent.NewSqlAgentClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlAgent client: %+v", err) + } + configureFunc(sqlAgentClient.Client) + + sqlVulnerabilityAssessmentBaselineClient, err := sqlvulnerabilityassessmentbaseline.NewSqlVulnerabilityAssessmentBaselineClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVulnerabilityAssessmentBaseline client: %+v", err) + } + configureFunc(sqlVulnerabilityAssessmentBaselineClient.Client) + + sqlVulnerabilityAssessmentExecuteScanClient, err := sqlvulnerabilityassessmentexecutescan.NewSqlVulnerabilityAssessmentExecuteScanClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVulnerabilityAssessmentExecuteScan client: %+v", err) + } + configureFunc(sqlVulnerabilityAssessmentExecuteScanClient.Client) + + sqlVulnerabilityAssessmentRuleBaselineClient, err := sqlvulnerabilityassessmentrulebaseline.NewSqlVulnerabilityAssessmentRuleBaselineClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVulnerabilityAssessmentRuleBaseline client: %+v", err) + } + configureFunc(sqlVulnerabilityAssessmentRuleBaselineClient.Client) + + sqlVulnerabilityAssessmentScanResultClient, err := sqlvulnerabilityassessmentscanresult.NewSqlVulnerabilityAssessmentScanResultClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVulnerabilityAssessmentScanResult client: %+v", err) + } + configureFunc(sqlVulnerabilityAssessmentScanResultClient.Client) + + sqlVulnerabilityAssessmentScansClient, err := sqlvulnerabilityassessmentscans.NewSqlVulnerabilityAssessmentScansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVulnerabilityAssessmentScans client: %+v", err) + } + configureFunc(sqlVulnerabilityAssessmentScansClient.Client) + + sqlVulnerabilityAssessmentsSettingsClient, err := sqlvulnerabilityassessmentssettings.NewSqlVulnerabilityAssessmentsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVulnerabilityAssessmentsSettings client: %+v", err) + } + configureFunc(sqlVulnerabilityAssessmentsSettingsClient.Client) + + startStopManagedInstanceSchedulesClient, err := startstopmanagedinstanceschedules.NewStartStopManagedInstanceSchedulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StartStopManagedInstanceSchedules client: %+v", err) + } + configureFunc(startStopManagedInstanceSchedulesClient.Client) + + subscriptionUsagesClient, err := subscriptionusages.NewSubscriptionUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SubscriptionUsages client: %+v", err) + } + configureFunc(subscriptionUsagesClient.Client) + + synapseLinkWorkspacesClient, err := synapselinkworkspaces.NewSynapseLinkWorkspacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SynapseLinkWorkspaces client: %+v", err) + } + configureFunc(synapseLinkWorkspacesClient.Client) + + syncAgentsClient, err := syncagents.NewSyncAgentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SyncAgents client: %+v", err) + } + configureFunc(syncAgentsClient.Client) + + syncGroupsClient, err := syncgroups.NewSyncGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SyncGroups client: %+v", err) + } + configureFunc(syncGroupsClient.Client) + + syncMembersClient, err := syncmembers.NewSyncMembersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SyncMembers client: %+v", err) + } + configureFunc(syncMembersClient.Client) + + tdeCertificatesClient, err := tdecertificates.NewTdeCertificatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TdeCertificates client: %+v", err) + } + configureFunc(tdeCertificatesClient.Client) + + timeZonesClient, err := timezones.NewTimeZonesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TimeZones client: %+v", err) + } + configureFunc(timeZonesClient.Client) + + transparentDataEncryptionsClient, err := transparentdataencryptions.NewTransparentDataEncryptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TransparentDataEncryptions client: %+v", err) + } + configureFunc(transparentDataEncryptionsClient.Client) + + usagesClient, err := usages.NewUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Usages client: %+v", err) + } + configureFunc(usagesClient.Client) + + virtualClustersClient, err := virtualclusters.NewVirtualClustersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building VirtualClusters client: %+v", err) + } + configureFunc(virtualClustersClient.Client) + + virtualNetworkRulesClient, err := virtualnetworkrules.NewVirtualNetworkRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building VirtualNetworkRules client: %+v", err) + } + configureFunc(virtualNetworkRulesClient.Client) + + workloadClassifiersClient, err := workloadclassifiers.NewWorkloadClassifiersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkloadClassifiers client: %+v", err) + } + configureFunc(workloadClassifiersClient.Client) + + workloadGroupsClient, err := workloadgroups.NewWorkloadGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkloadGroups client: %+v", err) + } + configureFunc(workloadGroupsClient.Client) + + return &Client{ + BackupShortTermRetentionPolicies: backupShortTermRetentionPoliciesClient, + BlobAuditing: blobAuditingClient, + DataMaskingPolicies: dataMaskingPoliciesClient, + DataMaskingRules: dataMaskingRulesClient, + DataWarehouseUserActivities: dataWarehouseUserActivitiesClient, + DatabaseAdvancedThreatProtectionSettings: databaseAdvancedThreatProtectionSettingsClient, + DatabaseAdvisors: databaseAdvisorsClient, + DatabaseAutomaticTuning: databaseAutomaticTuningClient, + DatabaseColumns: databaseColumnsClient, + DatabaseEncryptionProtectorRevalidate: databaseEncryptionProtectorRevalidateClient, + DatabaseEncryptionProtectorRevert: databaseEncryptionProtectorRevertClient, + DatabaseExtensions: databaseExtensionsClient, + DatabaseOperations: databaseOperationsClient, + DatabaseRecommendedActions: databaseRecommendedActionsClient, + DatabaseSchemas: databaseSchemasClient, + DatabaseSecurityAlertPolicies: databaseSecurityAlertPoliciesClient, + DatabaseSqlVulnerabilityAssessmentBaselines: databaseSqlVulnerabilityAssessmentBaselinesClient, + DatabaseSqlVulnerabilityAssessmentExecuteScan: databaseSqlVulnerabilityAssessmentExecuteScanClient, + DatabaseSqlVulnerabilityAssessmentRuleBaselines: databaseSqlVulnerabilityAssessmentRuleBaselinesClient, + DatabaseSqlVulnerabilityAssessmentScanResult: databaseSqlVulnerabilityAssessmentScanResultClient, + DatabaseSqlVulnerabilityAssessmentScans: databaseSqlVulnerabilityAssessmentScansClient, + DatabaseSqlVulnerabilityAssessmentsSettings: databaseSqlVulnerabilityAssessmentsSettingsClient, + DatabaseTables: databaseTablesClient, + DatabaseUsages: databaseUsagesClient, + DatabaseVulnerabilityAssessmentRuleBaselines: databaseVulnerabilityAssessmentRuleBaselinesClient, + DatabaseVulnerabilityAssessmentScans: databaseVulnerabilityAssessmentScansClient, + DatabaseVulnerabilityAssessments: databaseVulnerabilityAssessmentsClient, + Databases: databasesClient, + DeletedServers: deletedServersClient, + DistributedAvailabilityGroups: distributedAvailabilityGroupsClient, + ElasticPoolOperations: elasticPoolOperationsClient, + ElasticPools: elasticPoolsClient, + EncryptionProtectors: encryptionProtectorsClient, + EndpointCertificates: endpointCertificatesClient, + FailoverGroups: failoverGroupsClient, + FirewallRules: firewallRulesClient, + GeoBackupPolicies: geoBackupPoliciesClient, + IPv6FirewallRules: iPv6FirewallRulesClient, + InstanceFailoverGroups: instanceFailoverGroupsClient, + InstancePools: instancePoolsClient, + JobAgents: jobAgentsClient, + JobCredentials: jobCredentialsClient, + JobExecutions: jobExecutionsClient, + JobPrivateEndpoints: jobPrivateEndpointsClient, + JobStepExecutions: jobStepExecutionsClient, + JobSteps: jobStepsClient, + JobTargetExecutions: jobTargetExecutionsClient, + JobTargetGroups: jobTargetGroupsClient, + JobVersions: jobVersionsClient, + Jobs: jobsClient, + LedgerDigestUploads: ledgerDigestUploadsClient, + LocationCapabilities: locationCapabilitiesClient, + LongTermRetentionBackups: longTermRetentionBackupsClient, + LongTermRetentionManagedInstanceBackups: longTermRetentionManagedInstanceBackupsClient, + LongTermRetentionPolicies: longTermRetentionPoliciesClient, + MaintenanceWindowOptions: maintenanceWindowOptionsClient, + MaintenanceWindows: maintenanceWindowsClient, + ManagedBackupShortTermRetentionPolicies: managedBackupShortTermRetentionPoliciesClient, + ManagedDatabaseAdvancedThreatProtectionSettings: managedDatabaseAdvancedThreatProtectionSettingsClient, + ManagedDatabaseColumns: managedDatabaseColumnsClient, + ManagedDatabaseMoveOperations: managedDatabaseMoveOperationsClient, + ManagedDatabaseQueries: managedDatabaseQueriesClient, + ManagedDatabaseRestoreDetails: managedDatabaseRestoreDetailsClient, + ManagedDatabaseSchemas: managedDatabaseSchemasClient, + ManagedDatabaseSecurityAlertPolicies: managedDatabaseSecurityAlertPoliciesClient, + ManagedDatabaseSecurityEvents: managedDatabaseSecurityEventsClient, + ManagedDatabaseSensitivityLabels: managedDatabaseSensitivityLabelsClient, + ManagedDatabaseTables: managedDatabaseTablesClient, + ManagedDatabaseTransparentDataEncryption: managedDatabaseTransparentDataEncryptionClient, + ManagedDatabaseVulnerabilityAssessmentRuleBaselines: managedDatabaseVulnerabilityAssessmentRuleBaselinesClient, + ManagedDatabaseVulnerabilityAssessmentScans: managedDatabaseVulnerabilityAssessmentScansClient, + ManagedDatabaseVulnerabilityAssessments: managedDatabaseVulnerabilityAssessmentsClient, + ManagedDatabases: managedDatabasesClient, + ManagedInstanceAdministrators: managedInstanceAdministratorsClient, + ManagedInstanceAdvancedThreatProtectionSettings: managedInstanceAdvancedThreatProtectionSettingsClient, + ManagedInstanceAzureADOnlyAuthentications: managedInstanceAzureADOnlyAuthenticationsClient, + ManagedInstanceDtcs: managedInstanceDtcsClient, + ManagedInstanceEncryptionProtectors: managedInstanceEncryptionProtectorsClient, + ManagedInstanceKeys: managedInstanceKeysClient, + ManagedInstanceLongTermRetentionPolicies: managedInstanceLongTermRetentionPoliciesClient, + ManagedInstanceOperations: managedInstanceOperationsClient, + ManagedInstancePrivateEndpointConnections: managedInstancePrivateEndpointConnectionsClient, + ManagedInstancePrivateLinkResources: managedInstancePrivateLinkResourcesClient, + ManagedInstanceTdeCertificates: managedInstanceTdeCertificatesClient, + ManagedInstanceVulnerabilityAssessments: managedInstanceVulnerabilityAssessmentsClient, + ManagedInstances: managedInstancesClient, + ManagedLedgerDigestUploads: managedLedgerDigestUploadsClient, + ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies: managedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient, + ManagedServerDnsAliases: managedServerDnsAliasesClient, + ManagedServerSecurityAlertPolicies: managedServerSecurityAlertPoliciesClient, + NetworkSecurityPerimeterConfigurations: networkSecurityPerimeterConfigurationsClient, + OutboundFirewallRules: outboundFirewallRulesClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + RecoverableDatabases: recoverableDatabasesClient, + RecoverableManagedDatabases: recoverableManagedDatabasesClient, + ReplicationLinks: replicationLinksClient, + RestorableDroppedDatabases: restorableDroppedDatabasesClient, + RestorableDroppedManagedDatabases: restorableDroppedManagedDatabasesClient, + RestorePoints: restorePointsClient, + SensitivityLabels: sensitivityLabelsClient, + ServerAdvancedThreatProtectionSettings: serverAdvancedThreatProtectionSettingsClient, + ServerAdvisors: serverAdvisorsClient, + ServerAutomaticTuning: serverAutomaticTuningClient, + ServerAzureADAdministrators: serverAzureADAdministratorsClient, + ServerAzureADOnlyAuthentications: serverAzureADOnlyAuthenticationsClient, + ServerConfigurationOptions: serverConfigurationOptionsClient, + ServerConnectionPolicies: serverConnectionPoliciesClient, + ServerDevOpsAudit: serverDevOpsAuditClient, + ServerDnsAliases: serverDnsAliasesClient, + ServerKeys: serverKeysClient, + ServerOperations: serverOperationsClient, + ServerSecurityAlertPolicies: serverSecurityAlertPoliciesClient, + ServerTrustCertificates: serverTrustCertificatesClient, + ServerTrustGroups: serverTrustGroupsClient, + ServerUsages: serverUsagesClient, + ServerVulnerabilityAssessments: serverVulnerabilityAssessmentsClient, + Servers: serversClient, + SqlAgent: sqlAgentClient, + SqlVulnerabilityAssessmentBaseline: sqlVulnerabilityAssessmentBaselineClient, + SqlVulnerabilityAssessmentExecuteScan: sqlVulnerabilityAssessmentExecuteScanClient, + SqlVulnerabilityAssessmentRuleBaseline: sqlVulnerabilityAssessmentRuleBaselineClient, + SqlVulnerabilityAssessmentScanResult: sqlVulnerabilityAssessmentScanResultClient, + SqlVulnerabilityAssessmentScans: sqlVulnerabilityAssessmentScansClient, + SqlVulnerabilityAssessmentsSettings: sqlVulnerabilityAssessmentsSettingsClient, + StartStopManagedInstanceSchedules: startStopManagedInstanceSchedulesClient, + SubscriptionUsages: subscriptionUsagesClient, + SynapseLinkWorkspaces: synapseLinkWorkspacesClient, + SyncAgents: syncAgentsClient, + SyncGroups: syncGroupsClient, + SyncMembers: syncMembersClient, + TdeCertificates: tdeCertificatesClient, + TimeZones: timeZonesClient, + TransparentDataEncryptions: transparentDataEncryptionsClient, + Usages: usagesClient, + VirtualClusters: virtualClustersClient, + VirtualNetworkRules: virtualNetworkRulesClient, + WorkloadClassifiers: workloadClassifiersClient, + WorkloadGroups: workloadGroupsClient, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..133c1ec8cc7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings` Documentation + +The `databaseadvancedthreatprotectionsettings` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := databaseadvancedthreatprotectionsettings.NewDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databaseadvancedthreatprotectionsettings.DatabaseAdvancedThreatProtection{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseAdvancedThreatProtectionSettingsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DatabaseAdvancedThreatProtectionSettingsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..6d648a65168 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/client.go @@ -0,0 +1,26 @@ +package databaseadvancedthreatprotectionsettings + +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 DatabaseAdvancedThreatProtectionSettingsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseAdvancedThreatProtectionSettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseadvancedthreatprotectionsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseAdvancedThreatProtectionSettingsClient: %+v", err) + } + + return &DatabaseAdvancedThreatProtectionSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..a2ac92a08ac --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/constants.go @@ -0,0 +1,54 @@ +package databaseadvancedthreatprotectionsettings + +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 AdvancedThreatProtectionState string + +const ( + AdvancedThreatProtectionStateDisabled AdvancedThreatProtectionState = "Disabled" + AdvancedThreatProtectionStateEnabled AdvancedThreatProtectionState = "Enabled" + AdvancedThreatProtectionStateNew AdvancedThreatProtectionState = "New" +) + +func PossibleValuesForAdvancedThreatProtectionState() []string { + return []string{ + string(AdvancedThreatProtectionStateDisabled), + string(AdvancedThreatProtectionStateEnabled), + string(AdvancedThreatProtectionStateNew), + } +} + +func (s *AdvancedThreatProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvancedThreatProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvancedThreatProtectionState(input string) (*AdvancedThreatProtectionState, error) { + vals := map[string]AdvancedThreatProtectionState{ + "disabled": AdvancedThreatProtectionStateDisabled, + "enabled": AdvancedThreatProtectionStateEnabled, + "new": AdvancedThreatProtectionStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvancedThreatProtectionState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..81db81d16c9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_createorupdate.go @@ -0,0 +1,60 @@ +package databaseadvancedthreatprotectionsettings + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseAdvancedThreatProtection +} + +// CreateOrUpdate ... +func (c DatabaseAdvancedThreatProtectionSettingsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseAdvancedThreatProtection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 DatabaseAdvancedThreatProtection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..ef215bd4c97 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,55 @@ +package databaseadvancedthreatprotectionsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseAdvancedThreatProtection +} + +// Get ... +func (c DatabaseAdvancedThreatProtectionSettingsClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 DatabaseAdvancedThreatProtection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_listbydatabase.go new file mode 100644 index 00000000000..23cb159b8fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databaseadvancedthreatprotectionsettings + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseAdvancedThreatProtection +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseAdvancedThreatProtection +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseAdvancedThreatProtectionSettingsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings", 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 *[]DatabaseAdvancedThreatProtection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseAdvancedThreatProtectionSettingsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseAdvancedThreatProtectionOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseAdvancedThreatProtectionSettingsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseAdvancedThreatProtectionOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseAdvancedThreatProtection, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..b60bfab85ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go @@ -0,0 +1,27 @@ +package databaseadvancedthreatprotectionsettings + +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 AdvancedThreatProtectionProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + State AdvancedThreatProtectionState `json:"state"` +} + +func (o *AdvancedThreatProtectionProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AdvancedThreatProtectionProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go new file mode 100644 index 00000000000..245d3d3dc9e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go @@ -0,0 +1,16 @@ +package databaseadvancedthreatprotectionsettings + +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 DatabaseAdvancedThreatProtection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvancedThreatProtectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..924364c1b59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/predicates.go @@ -0,0 +1,27 @@ +package databaseadvancedthreatprotectionsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseAdvancedThreatProtectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseAdvancedThreatProtectionOperationPredicate) Matches(input DatabaseAdvancedThreatProtection) 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/sql/2023-08-01/databaseadvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..13e46359dd0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvancedthreatprotectionsettings/version.go @@ -0,0 +1,10 @@ +package databaseadvancedthreatprotectionsettings + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseadvancedthreatprotectionsettings/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/README.md b/resource-manager/sql/2023-08-01/databaseadvisors/README.md new file mode 100644 index 00000000000..37393f7b5e8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseadvisors` Documentation + +The `databaseadvisors` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseadvisors" +``` + + +### Client Initialization + +```go +client := databaseadvisors.NewDatabaseAdvisorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseAdvisorsClient.Get` + +```go +ctx := context.TODO() +id := databaseadvisors.NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName") + +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: `DatabaseAdvisorsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.ListByDatabase(ctx, id, databaseadvisors.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseAdvisorsClient.Update` + +```go +ctx := context.TODO() +id := databaseadvisors.NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName") + +payload := databaseadvisors.Advisor{ + // ... +} + + +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/sql/2023-08-01/databaseadvisors/client.go b/resource-manager/sql/2023-08-01/databaseadvisors/client.go new file mode 100644 index 00000000000..fce41427034 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/client.go @@ -0,0 +1,26 @@ +package databaseadvisors + +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 DatabaseAdvisorsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseAdvisorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseAdvisorsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseadvisors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseAdvisorsClient: %+v", err) + } + + return &DatabaseAdvisorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/constants.go b/resource-manager/sql/2023-08-01/databaseadvisors/constants.go new file mode 100644 index 00000000000..b73254f3b29 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/constants.go @@ -0,0 +1,351 @@ +package databaseadvisors + +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 AdvisorStatus string + +const ( + AdvisorStatusGA AdvisorStatus = "GA" + AdvisorStatusLimitedPublicPreview AdvisorStatus = "LimitedPublicPreview" + AdvisorStatusPrivatePreview AdvisorStatus = "PrivatePreview" + AdvisorStatusPublicPreview AdvisorStatus = "PublicPreview" +) + +func PossibleValuesForAdvisorStatus() []string { + return []string{ + string(AdvisorStatusGA), + string(AdvisorStatusLimitedPublicPreview), + string(AdvisorStatusPrivatePreview), + string(AdvisorStatusPublicPreview), + } +} + +func (s *AdvisorStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvisorStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvisorStatus(input string) (*AdvisorStatus, error) { + vals := map[string]AdvisorStatus{ + "ga": AdvisorStatusGA, + "limitedpublicpreview": AdvisorStatusLimitedPublicPreview, + "privatepreview": AdvisorStatusPrivatePreview, + "publicpreview": AdvisorStatusPublicPreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvisorStatus(input) + return &out, nil +} + +type AutoExecuteStatus string + +const ( + AutoExecuteStatusDefault AutoExecuteStatus = "Default" + AutoExecuteStatusDisabled AutoExecuteStatus = "Disabled" + AutoExecuteStatusEnabled AutoExecuteStatus = "Enabled" +) + +func PossibleValuesForAutoExecuteStatus() []string { + return []string{ + string(AutoExecuteStatusDefault), + string(AutoExecuteStatusDisabled), + string(AutoExecuteStatusEnabled), + } +} + +func (s *AutoExecuteStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoExecuteStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoExecuteStatus(input string) (*AutoExecuteStatus, error) { + vals := map[string]AutoExecuteStatus{ + "default": AutoExecuteStatusDefault, + "disabled": AutoExecuteStatusDisabled, + "enabled": AutoExecuteStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoExecuteStatus(input) + return &out, nil +} + +type AutoExecuteStatusInheritedFrom string + +const ( + AutoExecuteStatusInheritedFromDatabase AutoExecuteStatusInheritedFrom = "Database" + AutoExecuteStatusInheritedFromDefault AutoExecuteStatusInheritedFrom = "Default" + AutoExecuteStatusInheritedFromElasticPool AutoExecuteStatusInheritedFrom = "ElasticPool" + AutoExecuteStatusInheritedFromServer AutoExecuteStatusInheritedFrom = "Server" + AutoExecuteStatusInheritedFromSubscription AutoExecuteStatusInheritedFrom = "Subscription" +) + +func PossibleValuesForAutoExecuteStatusInheritedFrom() []string { + return []string{ + string(AutoExecuteStatusInheritedFromDatabase), + string(AutoExecuteStatusInheritedFromDefault), + string(AutoExecuteStatusInheritedFromElasticPool), + string(AutoExecuteStatusInheritedFromServer), + string(AutoExecuteStatusInheritedFromSubscription), + } +} + +func (s *AutoExecuteStatusInheritedFrom) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoExecuteStatusInheritedFrom(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoExecuteStatusInheritedFrom(input string) (*AutoExecuteStatusInheritedFrom, error) { + vals := map[string]AutoExecuteStatusInheritedFrom{ + "database": AutoExecuteStatusInheritedFromDatabase, + "default": AutoExecuteStatusInheritedFromDefault, + "elasticpool": AutoExecuteStatusInheritedFromElasticPool, + "server": AutoExecuteStatusInheritedFromServer, + "subscription": AutoExecuteStatusInheritedFromSubscription, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoExecuteStatusInheritedFrom(input) + return &out, nil +} + +type ImplementationMethod string + +const ( + ImplementationMethodAzurePowerShell ImplementationMethod = "AzurePowerShell" + ImplementationMethodTSql ImplementationMethod = "TSql" +) + +func PossibleValuesForImplementationMethod() []string { + return []string{ + string(ImplementationMethodAzurePowerShell), + string(ImplementationMethodTSql), + } +} + +func (s *ImplementationMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImplementationMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImplementationMethod(input string) (*ImplementationMethod, error) { + vals := map[string]ImplementationMethod{ + "azurepowershell": ImplementationMethodAzurePowerShell, + "tsql": ImplementationMethodTSql, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImplementationMethod(input) + return &out, nil +} + +type IsRetryable string + +const ( + IsRetryableNo IsRetryable = "No" + IsRetryableYes IsRetryable = "Yes" +) + +func PossibleValuesForIsRetryable() []string { + return []string{ + string(IsRetryableNo), + string(IsRetryableYes), + } +} + +func (s *IsRetryable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsRetryable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsRetryable(input string) (*IsRetryable, error) { + vals := map[string]IsRetryable{ + "no": IsRetryableNo, + "yes": IsRetryableYes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsRetryable(input) + return &out, nil +} + +type RecommendedActionCurrentState string + +const ( + RecommendedActionCurrentStateActive RecommendedActionCurrentState = "Active" + RecommendedActionCurrentStateError RecommendedActionCurrentState = "Error" + RecommendedActionCurrentStateExecuting RecommendedActionCurrentState = "Executing" + RecommendedActionCurrentStateExpired RecommendedActionCurrentState = "Expired" + RecommendedActionCurrentStateIgnored RecommendedActionCurrentState = "Ignored" + RecommendedActionCurrentStateMonitoring RecommendedActionCurrentState = "Monitoring" + RecommendedActionCurrentStatePending RecommendedActionCurrentState = "Pending" + RecommendedActionCurrentStatePendingRevert RecommendedActionCurrentState = "PendingRevert" + RecommendedActionCurrentStateResolved RecommendedActionCurrentState = "Resolved" + RecommendedActionCurrentStateRevertCancelled RecommendedActionCurrentState = "RevertCancelled" + RecommendedActionCurrentStateReverted RecommendedActionCurrentState = "Reverted" + RecommendedActionCurrentStateReverting RecommendedActionCurrentState = "Reverting" + RecommendedActionCurrentStateSuccess RecommendedActionCurrentState = "Success" + RecommendedActionCurrentStateVerifying RecommendedActionCurrentState = "Verifying" +) + +func PossibleValuesForRecommendedActionCurrentState() []string { + return []string{ + string(RecommendedActionCurrentStateActive), + string(RecommendedActionCurrentStateError), + string(RecommendedActionCurrentStateExecuting), + string(RecommendedActionCurrentStateExpired), + string(RecommendedActionCurrentStateIgnored), + string(RecommendedActionCurrentStateMonitoring), + string(RecommendedActionCurrentStatePending), + string(RecommendedActionCurrentStatePendingRevert), + string(RecommendedActionCurrentStateResolved), + string(RecommendedActionCurrentStateRevertCancelled), + string(RecommendedActionCurrentStateReverted), + string(RecommendedActionCurrentStateReverting), + string(RecommendedActionCurrentStateSuccess), + string(RecommendedActionCurrentStateVerifying), + } +} + +func (s *RecommendedActionCurrentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedActionCurrentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedActionCurrentState(input string) (*RecommendedActionCurrentState, error) { + vals := map[string]RecommendedActionCurrentState{ + "active": RecommendedActionCurrentStateActive, + "error": RecommendedActionCurrentStateError, + "executing": RecommendedActionCurrentStateExecuting, + "expired": RecommendedActionCurrentStateExpired, + "ignored": RecommendedActionCurrentStateIgnored, + "monitoring": RecommendedActionCurrentStateMonitoring, + "pending": RecommendedActionCurrentStatePending, + "pendingrevert": RecommendedActionCurrentStatePendingRevert, + "resolved": RecommendedActionCurrentStateResolved, + "revertcancelled": RecommendedActionCurrentStateRevertCancelled, + "reverted": RecommendedActionCurrentStateReverted, + "reverting": RecommendedActionCurrentStateReverting, + "success": RecommendedActionCurrentStateSuccess, + "verifying": RecommendedActionCurrentStateVerifying, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedActionCurrentState(input) + return &out, nil +} + +type RecommendedActionInitiatedBy string + +const ( + RecommendedActionInitiatedBySystem RecommendedActionInitiatedBy = "System" + RecommendedActionInitiatedByUser RecommendedActionInitiatedBy = "User" +) + +func PossibleValuesForRecommendedActionInitiatedBy() []string { + return []string{ + string(RecommendedActionInitiatedBySystem), + string(RecommendedActionInitiatedByUser), + } +} + +func (s *RecommendedActionInitiatedBy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedActionInitiatedBy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedActionInitiatedBy(input string) (*RecommendedActionInitiatedBy, error) { + vals := map[string]RecommendedActionInitiatedBy{ + "system": RecommendedActionInitiatedBySystem, + "user": RecommendedActionInitiatedByUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedActionInitiatedBy(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor.go b/resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor.go new file mode 100644 index 00000000000..f5d4d11fb78 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor.go @@ -0,0 +1,148 @@ +package databaseadvisors + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseAdvisorId{}) +} + +var _ resourceids.ResourceId = &DatabaseAdvisorId{} + +// DatabaseAdvisorId is a struct representing the Resource ID for a Database Advisor +type DatabaseAdvisorId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + AdvisorName string +} + +// NewDatabaseAdvisorID returns a new DatabaseAdvisorId struct +func NewDatabaseAdvisorID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, advisorName string) DatabaseAdvisorId { + return DatabaseAdvisorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + AdvisorName: advisorName, + } +} + +// ParseDatabaseAdvisorID parses 'input' into a DatabaseAdvisorId +func ParseDatabaseAdvisorID(input string) (*DatabaseAdvisorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseAdvisorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseAdvisorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseAdvisorIDInsensitively parses 'input' case-insensitively into a DatabaseAdvisorId +// note: this method should only be used for API response data and not user input +func ParseDatabaseAdvisorIDInsensitively(input string) (*DatabaseAdvisorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseAdvisorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseAdvisorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseAdvisorId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.AdvisorName, ok = input.Parsed["advisorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "advisorName", input) + } + + return nil +} + +// ValidateDatabaseAdvisorID checks that 'input' can be parsed as a Database Advisor ID +func ValidateDatabaseAdvisorID(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 := ParseDatabaseAdvisorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database Advisor ID +func (id DatabaseAdvisorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/advisors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.AdvisorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database Advisor ID +func (id DatabaseAdvisorId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorName"), + } +} + +// String returns a human-readable description of this Database Advisor ID +func (id DatabaseAdvisorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Advisor Name: %q", id.AdvisorName), + } + return fmt.Sprintf("Database Advisor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor_test.go b/resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor_test.go new file mode 100644 index 00000000000..b74cf2d7c66 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/id_databaseadvisor_test.go @@ -0,0 +1,372 @@ +package databaseadvisors + +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 = &DatabaseAdvisorId{} + +func TestNewDatabaseAdvisorID(t *testing.T) { + id := NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.AdvisorName != "advisorName" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorName") + } +} + +func TestFormatDatabaseAdvisorID(t *testing.T) { + actual := NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseAdvisorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseAdvisorId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + AdvisorName: "advisorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseAdvisorID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + } +} + +func TestParseDatabaseAdvisorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseAdvisorId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + AdvisorName: "advisorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + AdvisorName: "aDvIsOrNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseAdvisorIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + } +} + +func TestSegmentsForDatabaseAdvisorId(t *testing.T) { + segments := DatabaseAdvisorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseAdvisorId 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/sql/2023-08-01/databaseadvisors/method_get.go b/resource-manager/sql/2023-08-01/databaseadvisors/method_get.go new file mode 100644 index 00000000000..8d6b2625ec0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/method_get.go @@ -0,0 +1,53 @@ +package databaseadvisors + +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 *Advisor +} + +// Get ... +func (c DatabaseAdvisorsClient) Get(ctx context.Context, id DatabaseAdvisorId) (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 Advisor + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databaseadvisors/method_listbydatabase.go new file mode 100644 index 00000000000..3f50cebdcfc --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/method_listbydatabase.go @@ -0,0 +1,84 @@ +package databaseadvisors + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Advisor +} + +type ListByDatabaseOperationOptions struct { + Expand *string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// ListByDatabase ... +func (c DatabaseAdvisorsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/advisors", 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 []Advisor + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/method_update.go b/resource-manager/sql/2023-08-01/databaseadvisors/method_update.go new file mode 100644 index 00000000000..305e480233e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/method_update.go @@ -0,0 +1,57 @@ +package databaseadvisors + +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 *Advisor +} + +// Update ... +func (c DatabaseAdvisorsClient) Update(ctx context.Context, id DatabaseAdvisorId, input Advisor) (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 Advisor + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_advisor.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_advisor.go new file mode 100644 index 00000000000..ea9c7caf5db --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_advisor.go @@ -0,0 +1,13 @@ +package databaseadvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Advisor struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvisorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_advisorproperties.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_advisorproperties.go new file mode 100644 index 00000000000..54582eead60 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_advisorproperties.go @@ -0,0 +1,31 @@ +package databaseadvisors + +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 AdvisorProperties struct { + AdvisorStatus *AdvisorStatus `json:"advisorStatus,omitempty"` + AutoExecuteStatus AutoExecuteStatus `json:"autoExecuteStatus"` + AutoExecuteStatusInheritedFrom *AutoExecuteStatusInheritedFrom `json:"autoExecuteStatusInheritedFrom,omitempty"` + LastChecked *string `json:"lastChecked,omitempty"` + RecommendationsStatus *string `json:"recommendationsStatus,omitempty"` + RecommendedActions *[]RecommendedAction `json:"recommendedActions,omitempty"` +} + +func (o *AdvisorProperties) GetLastCheckedAsTime() (*time.Time, error) { + if o.LastChecked == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastChecked, "2006-01-02T15:04:05Z07:00") +} + +func (o *AdvisorProperties) SetLastCheckedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastChecked = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedaction.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedaction.go new file mode 100644 index 00000000000..eee447ffdb5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedaction.go @@ -0,0 +1,13 @@ +package databaseadvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedAction struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendedActionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionerrorinfo.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionerrorinfo.go new file mode 100644 index 00000000000..e33f6542a7e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionerrorinfo.go @@ -0,0 +1,9 @@ +package databaseadvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionErrorInfo struct { + ErrorCode *string `json:"errorCode,omitempty"` + IsRetryable *IsRetryable `json:"isRetryable,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimpactrecord.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimpactrecord.go new file mode 100644 index 00000000000..eb279916e7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimpactrecord.go @@ -0,0 +1,12 @@ +package databaseadvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionImpactRecord struct { + AbsoluteValue *float64 `json:"absoluteValue,omitempty"` + ChangeValueAbsolute *float64 `json:"changeValueAbsolute,omitempty"` + ChangeValueRelative *float64 `json:"changeValueRelative,omitempty"` + DimensionName *string `json:"dimensionName,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimplementationinfo.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimplementationinfo.go new file mode 100644 index 00000000000..24777850e7d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionimplementationinfo.go @@ -0,0 +1,9 @@ +package databaseadvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionImplementationInfo struct { + Method *ImplementationMethod `json:"method,omitempty"` + Script *string `json:"script,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionmetricinfo.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionmetricinfo.go new file mode 100644 index 00000000000..80b54ffc4ae --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionmetricinfo.go @@ -0,0 +1,30 @@ +package databaseadvisors + +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 RecommendedActionMetricInfo struct { + MetricName *string `json:"metricName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + TimeGrain *string `json:"timeGrain,omitempty"` + Unit *string `json:"unit,omitempty"` + Value *float64 `json:"value,omitempty"` +} + +func (o *RecommendedActionMetricInfo) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionMetricInfo) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionproperties.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionproperties.go new file mode 100644 index 00000000000..4167060b9a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionproperties.go @@ -0,0 +1,108 @@ +package databaseadvisors + +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 RecommendedActionProperties struct { + Details *map[string]string `json:"details,omitempty"` + ErrorDetails *RecommendedActionErrorInfo `json:"errorDetails,omitempty"` + EstimatedImpact *[]RecommendedActionImpactRecord `json:"estimatedImpact,omitempty"` + ExecuteActionDuration *string `json:"executeActionDuration,omitempty"` + ExecuteActionInitiatedBy *RecommendedActionInitiatedBy `json:"executeActionInitiatedBy,omitempty"` + ExecuteActionInitiatedTime *string `json:"executeActionInitiatedTime,omitempty"` + ExecuteActionStartTime *string `json:"executeActionStartTime,omitempty"` + ImplementationDetails *RecommendedActionImplementationInfo `json:"implementationDetails,omitempty"` + IsArchivedAction *bool `json:"isArchivedAction,omitempty"` + IsExecutableAction *bool `json:"isExecutableAction,omitempty"` + IsRevertableAction *bool `json:"isRevertableAction,omitempty"` + LastRefresh *string `json:"lastRefresh,omitempty"` + LinkedObjects *[]string `json:"linkedObjects,omitempty"` + ObservedImpact *[]RecommendedActionImpactRecord `json:"observedImpact,omitempty"` + RecommendationReason *string `json:"recommendationReason,omitempty"` + RevertActionDuration *string `json:"revertActionDuration,omitempty"` + RevertActionInitiatedBy *RecommendedActionInitiatedBy `json:"revertActionInitiatedBy,omitempty"` + RevertActionInitiatedTime *string `json:"revertActionInitiatedTime,omitempty"` + RevertActionStartTime *string `json:"revertActionStartTime,omitempty"` + Score *int64 `json:"score,omitempty"` + State RecommendedActionStateInfo `json:"state"` + TimeSeries *[]RecommendedActionMetricInfo `json:"timeSeries,omitempty"` + ValidSince *string `json:"validSince,omitempty"` +} + +func (o *RecommendedActionProperties) GetExecuteActionInitiatedTimeAsTime() (*time.Time, error) { + if o.ExecuteActionInitiatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExecuteActionInitiatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetExecuteActionInitiatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExecuteActionInitiatedTime = &formatted +} + +func (o *RecommendedActionProperties) GetExecuteActionStartTimeAsTime() (*time.Time, error) { + if o.ExecuteActionStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExecuteActionStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetExecuteActionStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExecuteActionStartTime = &formatted +} + +func (o *RecommendedActionProperties) GetLastRefreshAsTime() (*time.Time, error) { + if o.LastRefresh == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefresh, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetLastRefreshAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefresh = &formatted +} + +func (o *RecommendedActionProperties) GetRevertActionInitiatedTimeAsTime() (*time.Time, error) { + if o.RevertActionInitiatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RevertActionInitiatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetRevertActionInitiatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevertActionInitiatedTime = &formatted +} + +func (o *RecommendedActionProperties) GetRevertActionStartTimeAsTime() (*time.Time, error) { + if o.RevertActionStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RevertActionStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetRevertActionStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevertActionStartTime = &formatted +} + +func (o *RecommendedActionProperties) GetValidSinceAsTime() (*time.Time, error) { + if o.ValidSince == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidSince, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetValidSinceAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidSince = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionstateinfo.go b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionstateinfo.go new file mode 100644 index 00000000000..d638b212fb6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/model_recommendedactionstateinfo.go @@ -0,0 +1,28 @@ +package databaseadvisors + +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 RecommendedActionStateInfo struct { + ActionInitiatedBy *RecommendedActionInitiatedBy `json:"actionInitiatedBy,omitempty"` + CurrentValue RecommendedActionCurrentState `json:"currentValue"` + LastModified *string `json:"lastModified,omitempty"` +} + +func (o *RecommendedActionStateInfo) GetLastModifiedAsTime() (*time.Time, error) { + if o.LastModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionStateInfo) SetLastModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModified = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaseadvisors/version.go b/resource-manager/sql/2023-08-01/databaseadvisors/version.go new file mode 100644 index 00000000000..9a020b6fb4c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseadvisors/version.go @@ -0,0 +1,10 @@ +package databaseadvisors + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseadvisors/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/README.md b/resource-manager/sql/2023-08-01/databaseautomatictuning/README.md new file mode 100644 index 00000000000..c24b773c09a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseautomatictuning` Documentation + +The `databaseautomatictuning` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseautomatictuning" +``` + + +### Client Initialization + +```go +client := databaseautomatictuning.NewDatabaseAutomaticTuningClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseAutomaticTuningClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DatabaseAutomaticTuningClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databaseautomatictuning.DatabaseAutomaticTuning{ + // ... +} + + +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/sql/2023-08-01/databaseautomatictuning/client.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/client.go new file mode 100644 index 00000000000..64e97a4f9b8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/client.go @@ -0,0 +1,26 @@ +package databaseautomatictuning + +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 DatabaseAutomaticTuningClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseAutomaticTuningClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseAutomaticTuningClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseautomatictuning", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseAutomaticTuningClient: %+v", err) + } + + return &DatabaseAutomaticTuningClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/constants.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/constants.go new file mode 100644 index 00000000000..91ab8d001f9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/constants.go @@ -0,0 +1,198 @@ +package databaseautomatictuning + +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 AutomaticTuningDisabledReason string + +const ( + AutomaticTuningDisabledReasonAutoConfigured AutomaticTuningDisabledReason = "AutoConfigured" + AutomaticTuningDisabledReasonDefault AutomaticTuningDisabledReason = "Default" + AutomaticTuningDisabledReasonDisabled AutomaticTuningDisabledReason = "Disabled" + AutomaticTuningDisabledReasonInheritedFromServer AutomaticTuningDisabledReason = "InheritedFromServer" + AutomaticTuningDisabledReasonNotSupported AutomaticTuningDisabledReason = "NotSupported" + AutomaticTuningDisabledReasonQueryStoreOff AutomaticTuningDisabledReason = "QueryStoreOff" + AutomaticTuningDisabledReasonQueryStoreReadOnly AutomaticTuningDisabledReason = "QueryStoreReadOnly" +) + +func PossibleValuesForAutomaticTuningDisabledReason() []string { + return []string{ + string(AutomaticTuningDisabledReasonAutoConfigured), + string(AutomaticTuningDisabledReasonDefault), + string(AutomaticTuningDisabledReasonDisabled), + string(AutomaticTuningDisabledReasonInheritedFromServer), + string(AutomaticTuningDisabledReasonNotSupported), + string(AutomaticTuningDisabledReasonQueryStoreOff), + string(AutomaticTuningDisabledReasonQueryStoreReadOnly), + } +} + +func (s *AutomaticTuningDisabledReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningDisabledReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningDisabledReason(input string) (*AutomaticTuningDisabledReason, error) { + vals := map[string]AutomaticTuningDisabledReason{ + "autoconfigured": AutomaticTuningDisabledReasonAutoConfigured, + "default": AutomaticTuningDisabledReasonDefault, + "disabled": AutomaticTuningDisabledReasonDisabled, + "inheritedfromserver": AutomaticTuningDisabledReasonInheritedFromServer, + "notsupported": AutomaticTuningDisabledReasonNotSupported, + "querystoreoff": AutomaticTuningDisabledReasonQueryStoreOff, + "querystorereadonly": AutomaticTuningDisabledReasonQueryStoreReadOnly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningDisabledReason(input) + return &out, nil +} + +type AutomaticTuningMode string + +const ( + AutomaticTuningModeAuto AutomaticTuningMode = "Auto" + AutomaticTuningModeCustom AutomaticTuningMode = "Custom" + AutomaticTuningModeInherit AutomaticTuningMode = "Inherit" + AutomaticTuningModeUnspecified AutomaticTuningMode = "Unspecified" +) + +func PossibleValuesForAutomaticTuningMode() []string { + return []string{ + string(AutomaticTuningModeAuto), + string(AutomaticTuningModeCustom), + string(AutomaticTuningModeInherit), + string(AutomaticTuningModeUnspecified), + } +} + +func (s *AutomaticTuningMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningMode(input string) (*AutomaticTuningMode, error) { + vals := map[string]AutomaticTuningMode{ + "auto": AutomaticTuningModeAuto, + "custom": AutomaticTuningModeCustom, + "inherit": AutomaticTuningModeInherit, + "unspecified": AutomaticTuningModeUnspecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningMode(input) + return &out, nil +} + +type AutomaticTuningOptionModeActual string + +const ( + AutomaticTuningOptionModeActualOff AutomaticTuningOptionModeActual = "Off" + AutomaticTuningOptionModeActualOn AutomaticTuningOptionModeActual = "On" +) + +func PossibleValuesForAutomaticTuningOptionModeActual() []string { + return []string{ + string(AutomaticTuningOptionModeActualOff), + string(AutomaticTuningOptionModeActualOn), + } +} + +func (s *AutomaticTuningOptionModeActual) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningOptionModeActual(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningOptionModeActual(input string) (*AutomaticTuningOptionModeActual, error) { + vals := map[string]AutomaticTuningOptionModeActual{ + "off": AutomaticTuningOptionModeActualOff, + "on": AutomaticTuningOptionModeActualOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningOptionModeActual(input) + return &out, nil +} + +type AutomaticTuningOptionModeDesired string + +const ( + AutomaticTuningOptionModeDesiredDefault AutomaticTuningOptionModeDesired = "Default" + AutomaticTuningOptionModeDesiredOff AutomaticTuningOptionModeDesired = "Off" + AutomaticTuningOptionModeDesiredOn AutomaticTuningOptionModeDesired = "On" +) + +func PossibleValuesForAutomaticTuningOptionModeDesired() []string { + return []string{ + string(AutomaticTuningOptionModeDesiredDefault), + string(AutomaticTuningOptionModeDesiredOff), + string(AutomaticTuningOptionModeDesiredOn), + } +} + +func (s *AutomaticTuningOptionModeDesired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningOptionModeDesired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningOptionModeDesired(input string) (*AutomaticTuningOptionModeDesired, error) { + vals := map[string]AutomaticTuningOptionModeDesired{ + "default": AutomaticTuningOptionModeDesiredDefault, + "off": AutomaticTuningOptionModeDesiredOff, + "on": AutomaticTuningOptionModeDesiredOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningOptionModeDesired(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/method_get.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/method_get.go new file mode 100644 index 00000000000..e39c0ed3a61 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/method_get.go @@ -0,0 +1,55 @@ +package databaseautomatictuning + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseAutomaticTuning +} + +// Get ... +func (c DatabaseAutomaticTuningClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/automaticTuning/current", 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 DatabaseAutomaticTuning + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/method_update.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/method_update.go new file mode 100644 index 00000000000..e98f662fd44 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/method_update.go @@ -0,0 +1,59 @@ +package databaseautomatictuning + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseAutomaticTuning +} + +// Update ... +func (c DatabaseAutomaticTuningClient) Update(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseAutomaticTuning) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/automaticTuning/current", 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 DatabaseAutomaticTuning + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/model_automatictuningoptions.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/model_automatictuningoptions.go new file mode 100644 index 00000000000..ff902f8bb94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/model_automatictuningoptions.go @@ -0,0 +1,11 @@ +package databaseautomatictuning + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomaticTuningOptions struct { + ActualState *AutomaticTuningOptionModeActual `json:"actualState,omitempty"` + DesiredState *AutomaticTuningOptionModeDesired `json:"desiredState,omitempty"` + ReasonCode *int64 `json:"reasonCode,omitempty"` + ReasonDesc *AutomaticTuningDisabledReason `json:"reasonDesc,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuning.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuning.go new file mode 100644 index 00000000000..9845914122d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuning.go @@ -0,0 +1,11 @@ +package databaseautomatictuning + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseAutomaticTuning struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseAutomaticTuningProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuningproperties.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuningproperties.go new file mode 100644 index 00000000000..c0d3955a277 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/model_databaseautomatictuningproperties.go @@ -0,0 +1,10 @@ +package databaseautomatictuning + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseAutomaticTuningProperties struct { + ActualState *AutomaticTuningMode `json:"actualState,omitempty"` + DesiredState *AutomaticTuningMode `json:"desiredState,omitempty"` + Options *map[string]AutomaticTuningOptions `json:"options,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseautomatictuning/version.go b/resource-manager/sql/2023-08-01/databaseautomatictuning/version.go new file mode 100644 index 00000000000..8500ed7ffab --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseautomatictuning/version.go @@ -0,0 +1,10 @@ +package databaseautomatictuning + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseautomatictuning/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/README.md b/resource-manager/sql/2023-08-01/databasecolumns/README.md new file mode 100644 index 00000000000..55880ded447 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasecolumns` Documentation + +The `databasecolumns` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasecolumns" +``` + + +### Client Initialization + +```go +client := databasecolumns.NewDatabaseColumnsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseColumnsClient.Get` + +```go +ctx := context.TODO() +id := databasecolumns.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + +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: `DatabaseColumnsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, databasecolumns.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, databasecolumns.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DatabaseColumnsClient.ListByTable` + +```go +ctx := context.TODO() +id := databasecolumns.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName") + +// alternatively `client.ListByTable(ctx, id, databasecolumns.DefaultListByTableOperationOptions())` can be used to do batched pagination +items, err := client.ListByTableComplete(ctx, id, databasecolumns.DefaultListByTableOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasecolumns/client.go b/resource-manager/sql/2023-08-01/databasecolumns/client.go new file mode 100644 index 00000000000..bb6e0d151c9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/client.go @@ -0,0 +1,26 @@ +package databasecolumns + +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 DatabaseColumnsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseColumnsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseColumnsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasecolumns", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseColumnsClient: %+v", err) + } + + return &DatabaseColumnsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/constants.go b/resource-manager/sql/2023-08-01/databasecolumns/constants.go new file mode 100644 index 00000000000..c6771f38254 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/constants.go @@ -0,0 +1,191 @@ +package databasecolumns + +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 ColumnDataType string + +const ( + ColumnDataTypeBigint ColumnDataType = "bigint" + ColumnDataTypeBinary ColumnDataType = "binary" + ColumnDataTypeBit ColumnDataType = "bit" + ColumnDataTypeChar ColumnDataType = "char" + ColumnDataTypeDate ColumnDataType = "date" + ColumnDataTypeDatetime ColumnDataType = "datetime" + ColumnDataTypeDatetimeTwo ColumnDataType = "datetime2" + ColumnDataTypeDatetimeoffset ColumnDataType = "datetimeoffset" + ColumnDataTypeDecimal ColumnDataType = "decimal" + ColumnDataTypeFloat ColumnDataType = "float" + ColumnDataTypeGeography ColumnDataType = "geography" + ColumnDataTypeGeometry ColumnDataType = "geometry" + ColumnDataTypeHierarchyid ColumnDataType = "hierarchyid" + ColumnDataTypeImage ColumnDataType = "image" + ColumnDataTypeInt ColumnDataType = "int" + ColumnDataTypeMoney ColumnDataType = "money" + ColumnDataTypeNchar ColumnDataType = "nchar" + ColumnDataTypeNtext ColumnDataType = "ntext" + ColumnDataTypeNumeric ColumnDataType = "numeric" + ColumnDataTypeNvarchar ColumnDataType = "nvarchar" + ColumnDataTypeReal ColumnDataType = "real" + ColumnDataTypeSmalldatetime ColumnDataType = "smalldatetime" + ColumnDataTypeSmallint ColumnDataType = "smallint" + ColumnDataTypeSmallmoney ColumnDataType = "smallmoney" + ColumnDataTypeSqlVariant ColumnDataType = "sql_variant" + ColumnDataTypeSysname ColumnDataType = "sysname" + ColumnDataTypeText ColumnDataType = "text" + ColumnDataTypeTime ColumnDataType = "time" + ColumnDataTypeTimestamp ColumnDataType = "timestamp" + ColumnDataTypeTinyint ColumnDataType = "tinyint" + ColumnDataTypeUniqueidentifier ColumnDataType = "uniqueidentifier" + ColumnDataTypeVarbinary ColumnDataType = "varbinary" + ColumnDataTypeVarchar ColumnDataType = "varchar" + ColumnDataTypeXml ColumnDataType = "xml" +) + +func PossibleValuesForColumnDataType() []string { + return []string{ + string(ColumnDataTypeBigint), + string(ColumnDataTypeBinary), + string(ColumnDataTypeBit), + string(ColumnDataTypeChar), + string(ColumnDataTypeDate), + string(ColumnDataTypeDatetime), + string(ColumnDataTypeDatetimeTwo), + string(ColumnDataTypeDatetimeoffset), + string(ColumnDataTypeDecimal), + string(ColumnDataTypeFloat), + string(ColumnDataTypeGeography), + string(ColumnDataTypeGeometry), + string(ColumnDataTypeHierarchyid), + string(ColumnDataTypeImage), + string(ColumnDataTypeInt), + string(ColumnDataTypeMoney), + string(ColumnDataTypeNchar), + string(ColumnDataTypeNtext), + string(ColumnDataTypeNumeric), + string(ColumnDataTypeNvarchar), + string(ColumnDataTypeReal), + string(ColumnDataTypeSmalldatetime), + string(ColumnDataTypeSmallint), + string(ColumnDataTypeSmallmoney), + string(ColumnDataTypeSqlVariant), + string(ColumnDataTypeSysname), + string(ColumnDataTypeText), + string(ColumnDataTypeTime), + string(ColumnDataTypeTimestamp), + string(ColumnDataTypeTinyint), + string(ColumnDataTypeUniqueidentifier), + string(ColumnDataTypeVarbinary), + string(ColumnDataTypeVarchar), + string(ColumnDataTypeXml), + } +} + +func (s *ColumnDataType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseColumnDataType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseColumnDataType(input string) (*ColumnDataType, error) { + vals := map[string]ColumnDataType{ + "bigint": ColumnDataTypeBigint, + "binary": ColumnDataTypeBinary, + "bit": ColumnDataTypeBit, + "char": ColumnDataTypeChar, + "date": ColumnDataTypeDate, + "datetime": ColumnDataTypeDatetime, + "datetime2": ColumnDataTypeDatetimeTwo, + "datetimeoffset": ColumnDataTypeDatetimeoffset, + "decimal": ColumnDataTypeDecimal, + "float": ColumnDataTypeFloat, + "geography": ColumnDataTypeGeography, + "geometry": ColumnDataTypeGeometry, + "hierarchyid": ColumnDataTypeHierarchyid, + "image": ColumnDataTypeImage, + "int": ColumnDataTypeInt, + "money": ColumnDataTypeMoney, + "nchar": ColumnDataTypeNchar, + "ntext": ColumnDataTypeNtext, + "numeric": ColumnDataTypeNumeric, + "nvarchar": ColumnDataTypeNvarchar, + "real": ColumnDataTypeReal, + "smalldatetime": ColumnDataTypeSmalldatetime, + "smallint": ColumnDataTypeSmallint, + "smallmoney": ColumnDataTypeSmallmoney, + "sql_variant": ColumnDataTypeSqlVariant, + "sysname": ColumnDataTypeSysname, + "text": ColumnDataTypeText, + "time": ColumnDataTypeTime, + "timestamp": ColumnDataTypeTimestamp, + "tinyint": ColumnDataTypeTinyint, + "uniqueidentifier": ColumnDataTypeUniqueidentifier, + "varbinary": ColumnDataTypeVarbinary, + "varchar": ColumnDataTypeVarchar, + "xml": ColumnDataTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ColumnDataType(input) + return &out, nil +} + +type TableTemporalType string + +const ( + TableTemporalTypeHistoryTable TableTemporalType = "HistoryTable" + TableTemporalTypeNonTemporalTable TableTemporalType = "NonTemporalTable" + TableTemporalTypeSystemVersionedTemporalTable TableTemporalType = "SystemVersionedTemporalTable" +) + +func PossibleValuesForTableTemporalType() []string { + return []string{ + string(TableTemporalTypeHistoryTable), + string(TableTemporalTypeNonTemporalTable), + string(TableTemporalTypeSystemVersionedTemporalTable), + } +} + +func (s *TableTemporalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTableTemporalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTableTemporalType(input string) (*TableTemporalType, error) { + vals := map[string]TableTemporalType{ + "historytable": TableTemporalTypeHistoryTable, + "nontemporaltable": TableTemporalTypeNonTemporalTable, + "systemversionedtemporaltable": TableTemporalTypeSystemVersionedTemporalTable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TableTemporalType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/id_column.go b/resource-manager/sql/2023-08-01/databasecolumns/id_column.go new file mode 100644 index 00000000000..28c662f1283 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/id_column.go @@ -0,0 +1,166 @@ +package databasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ColumnId{}) +} + +var _ resourceids.ResourceId = &ColumnId{} + +// ColumnId is a struct representing the Resource ID for a Column +type ColumnId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string + TableName string + ColumnName string +} + +// NewColumnID returns a new ColumnId struct +func NewColumnID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string, tableName string, columnName string) ColumnId { + return ColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseColumnID parses 'input' into a ColumnId +func ParseColumnID(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseColumnIDInsensitively parses 'input' case-insensitively into a ColumnId +// note: this method should only be used for API response data and not user input +func ParseColumnIDInsensitively(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ColumnId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateColumnID checks that 'input' can be parsed as a Column ID +func ValidateColumnID(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 := ParseColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Column ID +func (id ColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Column ID +func (id ColumnId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnName"), + } +} + +// String returns a human-readable description of this Column ID +func (id ColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/id_column_test.go b/resource-manager/sql/2023-08-01/databasecolumns/id_column_test.go new file mode 100644 index 00000000000..ab827debaa3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/id_column_test.go @@ -0,0 +1,462 @@ +package databasecolumns + +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 = &ColumnId{} + +func TestNewColumnID(t *testing.T) { + id := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } + + if id.ColumnName != "columnName" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnName") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + ColumnName: "cOlUmNnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForColumnId(t *testing.T) { + segments := ColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ColumnId 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/sql/2023-08-01/databasecolumns/id_table.go b/resource-manager/sql/2023-08-01/databasecolumns/id_table.go new file mode 100644 index 00000000000..993fe5b7af9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/id_table.go @@ -0,0 +1,157 @@ +package databasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TableId{}) +} + +var _ resourceids.ResourceId = &TableId{} + +// TableId is a struct representing the Resource ID for a Table +type TableId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string + TableName string +} + +// NewTableID returns a new TableId struct +func NewTableID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string, tableName string) TableId { + return TableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + } +} + +// ParseTableID parses 'input' into a TableId +func ParseTableID(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableIDInsensitively parses 'input' case-insensitively into a TableId +// note: this method should only be used for API response data and not user input +func ParseTableIDInsensitively(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateTableID checks that 'input' can be parsed as a Table ID +func ValidateTableID(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 := ParseTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table ID +func (id TableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table ID +func (id TableId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + } +} + +// String returns a human-readable description of this Table ID +func (id TableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/id_table_test.go b/resource-manager/sql/2023-08-01/databasecolumns/id_table_test.go new file mode 100644 index 00000000000..b4fa64a5c11 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/id_table_test.go @@ -0,0 +1,417 @@ +package databasecolumns + +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 = &TableId{} + +func TestNewTableID(t *testing.T) { + id := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForTableId(t *testing.T) { + segments := TableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableId 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/sql/2023-08-01/databasecolumns/method_get.go b/resource-manager/sql/2023-08-01/databasecolumns/method_get.go new file mode 100644 index 00000000000..7df54396dde --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/method_get.go @@ -0,0 +1,53 @@ +package databasecolumns + +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 *DatabaseColumn +} + +// Get ... +func (c DatabaseColumnsClient) Get(ctx context.Context, id ColumnId) (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 DatabaseColumn + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databasecolumns/method_listbydatabase.go new file mode 100644 index 00000000000..44b8ccd8618 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/method_listbydatabase.go @@ -0,0 +1,147 @@ +package databasecolumns + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseColumn +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseColumn +} + +type ListByDatabaseOperationOptions struct { + Column *[]string + OrderBy *[]string + Schema *[]string + Table *[]string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Column != nil { + out.Append("column", fmt.Sprintf("%v", *o.Column)) + } + if o.OrderBy != nil { + out.Append("orderBy", fmt.Sprintf("%v", *o.OrderBy)) + } + if o.Schema != nil { + out.Append("schema", fmt.Sprintf("%v", *o.Schema)) + } + if o.Table != nil { + out.Append("table", fmt.Sprintf("%v", *o.Table)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseColumnsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/columns", 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 *[]DatabaseColumn `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseColumnsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, DatabaseColumnOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseColumnsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions, predicate DatabaseColumnOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseColumn, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/method_listbytable.go b/resource-manager/sql/2023-08-01/databasecolumns/method_listbytable.go new file mode 100644 index 00000000000..16a76702308 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/method_listbytable.go @@ -0,0 +1,134 @@ +package databasecolumns + +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 ListByTableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseColumn +} + +type ListByTableCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseColumn +} + +type ListByTableOperationOptions struct { + Filter *string +} + +func DefaultListByTableOperationOptions() ListByTableOperationOptions { + return ListByTableOperationOptions{} +} + +func (o ListByTableOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByTableOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByTableOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByTableCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTableCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByTable ... +func (c DatabaseColumnsClient) ListByTable(ctx context.Context, id TableId, options ListByTableOperationOptions) (result ListByTableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByTableCustomPager{}, + Path: fmt.Sprintf("%s/columns", 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 *[]DatabaseColumn `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTableComplete retrieves all the results into a single object +func (c DatabaseColumnsClient) ListByTableComplete(ctx context.Context, id TableId, options ListByTableOperationOptions) (ListByTableCompleteResult, error) { + return c.ListByTableCompleteMatchingPredicate(ctx, id, options, DatabaseColumnOperationPredicate{}) +} + +// ListByTableCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseColumnsClient) ListByTableCompleteMatchingPredicate(ctx context.Context, id TableId, options ListByTableOperationOptions, predicate DatabaseColumnOperationPredicate) (result ListByTableCompleteResult, err error) { + items := make([]DatabaseColumn, 0) + + resp, err := c.ListByTable(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTableCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumn.go b/resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumn.go new file mode 100644 index 00000000000..83f7ad88ffe --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumn.go @@ -0,0 +1,11 @@ +package databasecolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseColumn struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseColumnProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumnproperties.go b/resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumnproperties.go new file mode 100644 index 00000000000..ec6e02c5de0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/model_databasecolumnproperties.go @@ -0,0 +1,11 @@ +package databasecolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseColumnProperties struct { + ColumnType *ColumnDataType `json:"columnType,omitempty"` + IsComputed *bool `json:"isComputed,omitempty"` + MemoryOptimized *bool `json:"memoryOptimized,omitempty"` + TemporalType *TableTemporalType `json:"temporalType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasecolumns/predicates.go b/resource-manager/sql/2023-08-01/databasecolumns/predicates.go new file mode 100644 index 00000000000..bf9217e6d48 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/predicates.go @@ -0,0 +1,27 @@ +package databasecolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseColumnOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseColumnOperationPredicate) Matches(input DatabaseColumn) 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/sql/2023-08-01/databasecolumns/version.go b/resource-manager/sql/2023-08-01/databasecolumns/version.go new file mode 100644 index 00000000000..6e498f9cbe1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasecolumns/version.go @@ -0,0 +1,10 @@ +package databasecolumns + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasecolumns/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/client.go b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/client.go new file mode 100644 index 00000000000..64b1de4d53d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/client.go @@ -0,0 +1,26 @@ +package databaseencryptionprotectorrevalidate + +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 DatabaseEncryptionProtectorRevalidateClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseEncryptionProtectorRevalidateClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseEncryptionProtectorRevalidateClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseencryptionprotectorrevalidate", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseEncryptionProtectorRevalidateClient: %+v", err) + } + + return &DatabaseEncryptionProtectorRevalidateClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go new file mode 100644 index 00000000000..5f2ad93dc28 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go @@ -0,0 +1,71 @@ +package databaseencryptionprotectorrevalidate + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseEncryptionProtectorsRevalidateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabaseEncryptionProtectorsRevalidate ... +func (c DatabaseEncryptionProtectorRevalidateClient) DatabaseEncryptionProtectorsRevalidate(ctx context.Context, id commonids.SqlDatabaseId) (result DatabaseEncryptionProtectorsRevalidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/encryptionProtector/current/revalidate", 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 +} + +// DatabaseEncryptionProtectorsRevalidateThenPoll performs DatabaseEncryptionProtectorsRevalidate then polls until it's completed +func (c DatabaseEncryptionProtectorRevalidateClient) DatabaseEncryptionProtectorsRevalidateThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.DatabaseEncryptionProtectorsRevalidate(ctx, id) + if err != nil { + return fmt.Errorf("performing DatabaseEncryptionProtectorsRevalidate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabaseEncryptionProtectorsRevalidate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/version.go b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/version.go new file mode 100644 index 00000000000..b0888b11d0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevalidate/version.go @@ -0,0 +1,10 @@ +package databaseencryptionprotectorrevalidate + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseencryptionprotectorrevalidate/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/client.go b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/client.go new file mode 100644 index 00000000000..68eea1ecd3e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/client.go @@ -0,0 +1,26 @@ +package databaseencryptionprotectorrevert + +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 DatabaseEncryptionProtectorRevertClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseEncryptionProtectorRevertClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseEncryptionProtectorRevertClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseencryptionprotectorrevert", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseEncryptionProtectorRevertClient: %+v", err) + } + + return &DatabaseEncryptionProtectorRevertClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go new file mode 100644 index 00000000000..e4140eb2d87 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go @@ -0,0 +1,71 @@ +package databaseencryptionprotectorrevert + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseEncryptionProtectorsRevertOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabaseEncryptionProtectorsRevert ... +func (c DatabaseEncryptionProtectorRevertClient) DatabaseEncryptionProtectorsRevert(ctx context.Context, id commonids.SqlDatabaseId) (result DatabaseEncryptionProtectorsRevertOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/encryptionProtector/current/revert", 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 +} + +// DatabaseEncryptionProtectorsRevertThenPoll performs DatabaseEncryptionProtectorsRevert then polls until it's completed +func (c DatabaseEncryptionProtectorRevertClient) DatabaseEncryptionProtectorsRevertThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.DatabaseEncryptionProtectorsRevert(ctx, id) + if err != nil { + return fmt.Errorf("performing DatabaseEncryptionProtectorsRevert: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabaseEncryptionProtectorsRevert: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/version.go b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/version.go new file mode 100644 index 00000000000..1259c6765d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseencryptionprotectorrevert/version.go @@ -0,0 +1,10 @@ +package databaseencryptionprotectorrevert + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseencryptionprotectorrevert/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/README.md b/resource-manager/sql/2023-08-01/databaseextensions/README.md new file mode 100644 index 00000000000..917656b106d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseextensions` Documentation + +The `databaseextensions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseextensions" +``` + + +### Client Initialization + +```go +client := databaseextensions.NewDatabaseExtensionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseExtensionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databaseextensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "extensionName") + +payload := databaseextensions.DatabaseExtensions{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabaseExtensionsClient.Get` + +```go +ctx := context.TODO() +id := databaseextensions.NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "extensionName") + +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: `DatabaseExtensionsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databaseextensions/client.go b/resource-manager/sql/2023-08-01/databaseextensions/client.go new file mode 100644 index 00000000000..329371849d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/client.go @@ -0,0 +1,26 @@ +package databaseextensions + +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 DatabaseExtensionsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseExtensionsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseExtensionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseextensions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseExtensionsClient: %+v", err) + } + + return &DatabaseExtensionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/constants.go b/resource-manager/sql/2023-08-01/databaseextensions/constants.go new file mode 100644 index 00000000000..416e1799abd --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/constants.go @@ -0,0 +1,95 @@ +package databaseextensions + +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 OperationMode string + +const ( + OperationModeExport OperationMode = "Export" + OperationModeImport OperationMode = "Import" + OperationModePolybaseImport OperationMode = "PolybaseImport" +) + +func PossibleValuesForOperationMode() []string { + return []string{ + string(OperationModeExport), + string(OperationModeImport), + string(OperationModePolybaseImport), + } +} + +func (s *OperationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationMode(input string) (*OperationMode, error) { + vals := map[string]OperationMode{ + "export": OperationModeExport, + "import": OperationModeImport, + "polybaseimport": OperationModePolybaseImport, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationMode(input) + return &out, nil +} + +type StorageKeyType string + +const ( + StorageKeyTypeSharedAccessKey StorageKeyType = "SharedAccessKey" + StorageKeyTypeStorageAccessKey StorageKeyType = "StorageAccessKey" +) + +func PossibleValuesForStorageKeyType() []string { + return []string{ + string(StorageKeyTypeSharedAccessKey), + string(StorageKeyTypeStorageAccessKey), + } +} + +func (s *StorageKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageKeyType(input string) (*StorageKeyType, error) { + vals := map[string]StorageKeyType{ + "sharedaccesskey": StorageKeyTypeSharedAccessKey, + "storageaccesskey": StorageKeyTypeStorageAccessKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/id_extension.go b/resource-manager/sql/2023-08-01/databaseextensions/id_extension.go new file mode 100644 index 00000000000..28b0e010247 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/id_extension.go @@ -0,0 +1,148 @@ +package databaseextensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExtensionId{}) +} + +var _ resourceids.ResourceId = &ExtensionId{} + +// ExtensionId is a struct representing the Resource ID for a Extension +type ExtensionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + ExtensionName string +} + +// NewExtensionID returns a new ExtensionId struct +func NewExtensionID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, extensionName string) ExtensionId { + return ExtensionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", 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.Sql/servers/%s/databases/%s/extensions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticExtensions", "extensions", "extensions"), + resourceids.UserSpecifiedSegment("extensionName", "extensionName"), + } +} + +// 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("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Extension Name: %q", id.ExtensionName), + } + return fmt.Sprintf("Extension (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/id_extension_test.go b/resource-manager/sql/2023-08-01/databaseextensions/id_extension_test.go new file mode 100644 index 00000000000..0a10b8d5720 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/id_extension_test.go @@ -0,0 +1,372 @@ +package databaseextensions + +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", "serverName", "databaseName", "extensionName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.ExtensionName != "extensionName" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionName'", id.ExtensionName, "extensionName") + } +} + +func TestFormatExtensionID(t *testing.T) { + actual := NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "extensionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions/extensionName" + 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions/extensionName", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ExtensionName: "extensionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions/extensionName/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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/eXtEnSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions/extensionName", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ExtensionName: "extensionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/extensions/extensionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/eXtEnSiOnS/eXtEnSiOnNaMe", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + ExtensionName: "eXtEnSiOnNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/eXtEnSiOnS/eXtEnSiOnNaMe/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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + 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/sql/2023-08-01/databaseextensions/method_createorupdate.go b/resource-manager/sql/2023-08-01/databaseextensions/method_createorupdate.go new file mode 100644 index 00000000000..92eb336ceca --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/method_createorupdate.go @@ -0,0 +1,75 @@ +package databaseextensions + +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 *ImportExportExtensionsOperationResult +} + +// CreateOrUpdate ... +func (c DatabaseExtensionsClient) CreateOrUpdate(ctx context.Context, id ExtensionId, input DatabaseExtensions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c DatabaseExtensionsClient) CreateOrUpdateThenPoll(ctx context.Context, id ExtensionId, input DatabaseExtensions) 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/sql/2023-08-01/databaseextensions/method_get.go b/resource-manager/sql/2023-08-01/databaseextensions/method_get.go new file mode 100644 index 00000000000..d9a0ae8b685 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/method_get.go @@ -0,0 +1,46 @@ +package databaseextensions + +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 +} + +// Get ... +func (c DatabaseExtensionsClient) 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databaseextensions/method_listbydatabase.go new file mode 100644 index 00000000000..799da49b37e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databaseextensions + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ImportExportExtensionsOperationResult +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ImportExportExtensionsOperationResult +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseExtensionsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + 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 *[]ImportExportExtensionsOperationResult `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseExtensionsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ImportExportExtensionsOperationResultOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseExtensionsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate ImportExportExtensionsOperationResultOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ImportExportExtensionsOperationResult, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensions.go b/resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensions.go new file mode 100644 index 00000000000..a3f8c22d857 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensions.go @@ -0,0 +1,11 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseExtensions struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseExtensionsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensionsproperties.go b/resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensionsproperties.go new file mode 100644 index 00000000000..93b16ccbae9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/model_databaseextensionsproperties.go @@ -0,0 +1,18 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseExtensionsProperties struct { + AdministratorLogin *string `json:"administratorLogin,omitempty"` + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + AuthenticationType *string `json:"authenticationType,omitempty"` + DatabaseEdition *string `json:"databaseEdition,omitempty"` + MaxSizeBytes *string `json:"maxSizeBytes,omitempty"` + NetworkIsolation *NetworkIsolationSettings `json:"networkIsolation,omitempty"` + OperationMode OperationMode `json:"operationMode"` + ServiceObjectiveName *string `json:"serviceObjectiveName,omitempty"` + StorageKey string `json:"storageKey"` + StorageKeyType StorageKeyType `json:"storageKeyType"` + StorageUri string `json:"storageUri"` +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresult.go b/resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresult.go new file mode 100644 index 00000000000..f41657b8229 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresult.go @@ -0,0 +1,11 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportExtensionsOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImportExportExtensionsOperationResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresultproperties.go b/resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresultproperties.go new file mode 100644 index 00000000000..ab5a1f98d7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/model_importexportextensionsoperationresultproperties.go @@ -0,0 +1,17 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportExtensionsOperationResultProperties struct { + BlobUri *string `json:"blobUri,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + LastModifiedTime *string `json:"lastModifiedTime,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnectionRequestStatus `json:"privateEndpointConnections,omitempty"` + QueuedTime *string `json:"queuedTime,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestType *string `json:"requestType,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/model_networkisolationsettings.go b/resource-manager/sql/2023-08-01/databaseextensions/model_networkisolationsettings.go new file mode 100644 index 00000000000..35f540928d8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/model_networkisolationsettings.go @@ -0,0 +1,9 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkIsolationSettings struct { + SqlServerResourceId *string `json:"sqlServerResourceId,omitempty"` + StorageAccountResourceId *string `json:"storageAccountResourceId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/model_privateendpointconnectionrequeststatus.go b/resource-manager/sql/2023-08-01/databaseextensions/model_privateendpointconnectionrequeststatus.go new file mode 100644 index 00000000000..7b02cb1146a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/model_privateendpointconnectionrequeststatus.go @@ -0,0 +1,10 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionRequestStatus struct { + PrivateEndpointConnectionName *string `json:"privateEndpointConnectionName,omitempty"` + PrivateLinkServiceId *string `json:"privateLinkServiceId,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseextensions/predicates.go b/resource-manager/sql/2023-08-01/databaseextensions/predicates.go new file mode 100644 index 00000000000..d2668f629aa --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/predicates.go @@ -0,0 +1,27 @@ +package databaseextensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportExtensionsOperationResultOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ImportExportExtensionsOperationResultOperationPredicate) Matches(input ImportExportExtensionsOperationResult) 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/sql/2023-08-01/databaseextensions/version.go b/resource-manager/sql/2023-08-01/databaseextensions/version.go new file mode 100644 index 00000000000..3d4fa94ca46 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseextensions/version.go @@ -0,0 +1,10 @@ +package databaseextensions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseextensions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/README.md b/resource-manager/sql/2023-08-01/databaseoperations/README.md new file mode 100644 index 00000000000..47f8eb23ead --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseoperations` Documentation + +The `databaseoperations` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseoperations" +``` + + +### Client Initialization + +```go +client := databaseoperations.NewDatabaseOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseOperationsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databaseoperations/client.go b/resource-manager/sql/2023-08-01/databaseoperations/client.go new file mode 100644 index 00000000000..65137fba58a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/client.go @@ -0,0 +1,26 @@ +package databaseoperations + +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 DatabaseOperationsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseOperationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseoperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseOperationsClient: %+v", err) + } + + return &DatabaseOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/constants.go b/resource-manager/sql/2023-08-01/databaseoperations/constants.go new file mode 100644 index 00000000000..101190d73fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/constants.go @@ -0,0 +1,116 @@ +package databaseoperations + +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 ManagementOperationState string + +const ( + ManagementOperationStateCancelInProgress ManagementOperationState = "CancelInProgress" + ManagementOperationStateCancelled ManagementOperationState = "Cancelled" + ManagementOperationStateFailed ManagementOperationState = "Failed" + ManagementOperationStateInProgress ManagementOperationState = "InProgress" + ManagementOperationStatePending ManagementOperationState = "Pending" + ManagementOperationStateSucceeded ManagementOperationState = "Succeeded" +) + +func PossibleValuesForManagementOperationState() []string { + return []string{ + string(ManagementOperationStateCancelInProgress), + string(ManagementOperationStateCancelled), + string(ManagementOperationStateFailed), + string(ManagementOperationStateInProgress), + string(ManagementOperationStatePending), + string(ManagementOperationStateSucceeded), + } +} + +func (s *ManagementOperationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagementOperationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagementOperationState(input string) (*ManagementOperationState, error) { + vals := map[string]ManagementOperationState{ + "cancelinprogress": ManagementOperationStateCancelInProgress, + "cancelled": ManagementOperationStateCancelled, + "failed": ManagementOperationStateFailed, + "inprogress": ManagementOperationStateInProgress, + "pending": ManagementOperationStatePending, + "succeeded": ManagementOperationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagementOperationState(input) + return &out, nil +} + +type Phase string + +const ( + PhaseBuildingHyperscaleComponents Phase = "BuildingHyperscaleComponents" + PhaseCatchup Phase = "Catchup" + PhaseCopying Phase = "Copying" + PhaseCutoverInProgress Phase = "CutoverInProgress" + PhaseLogTransitionInProgress Phase = "LogTransitionInProgress" + PhaseWaitingForCutover Phase = "WaitingForCutover" +) + +func PossibleValuesForPhase() []string { + return []string{ + string(PhaseBuildingHyperscaleComponents), + string(PhaseCatchup), + string(PhaseCopying), + string(PhaseCutoverInProgress), + string(PhaseLogTransitionInProgress), + string(PhaseWaitingForCutover), + } +} + +func (s *Phase) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePhase(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePhase(input string) (*Phase, error) { + vals := map[string]Phase{ + "buildinghyperscalecomponents": PhaseBuildingHyperscaleComponents, + "catchup": PhaseCatchup, + "copying": PhaseCopying, + "cutoverinprogress": PhaseCutoverInProgress, + "logtransitioninprogress": PhaseLogTransitionInProgress, + "waitingforcutover": PhaseWaitingForCutover, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Phase(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databaseoperations/method_listbydatabase.go new file mode 100644 index 00000000000..f475d473277 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databaseoperations + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseOperation +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseOperation +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseOperationsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]DatabaseOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseOperationsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseOperationOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseOperationsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseOperationOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseOperation, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperation.go b/resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperation.go new file mode 100644 index 00000000000..58355f32f2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperation.go @@ -0,0 +1,11 @@ +package databaseoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseOperation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseOperationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperationproperties.go b/resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperationproperties.go new file mode 100644 index 00000000000..5373fb6204c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/model_databaseoperationproperties.go @@ -0,0 +1,52 @@ +package databaseoperations + +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 DatabaseOperationProperties struct { + DatabaseName *string `json:"databaseName,omitempty"` + Description *string `json:"description,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorDescription *string `json:"errorDescription,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + EstimatedCompletionTime *string `json:"estimatedCompletionTime,omitempty"` + IsCancellable *bool `json:"isCancellable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Operation *string `json:"operation,omitempty"` + OperationFriendlyName *string `json:"operationFriendlyName,omitempty"` + OperationPhaseDetails *PhaseDetails `json:"operationPhaseDetails,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + ServerName *string `json:"serverName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *ManagementOperationState `json:"state,omitempty"` +} + +func (o *DatabaseOperationProperties) GetEstimatedCompletionTimeAsTime() (*time.Time, error) { + if o.EstimatedCompletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EstimatedCompletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseOperationProperties) SetEstimatedCompletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EstimatedCompletionTime = &formatted +} + +func (o *DatabaseOperationProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseOperationProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/model_phasedetails.go b/resource-manager/sql/2023-08-01/databaseoperations/model_phasedetails.go new file mode 100644 index 00000000000..34bef9b911e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/model_phasedetails.go @@ -0,0 +1,9 @@ +package databaseoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PhaseDetails struct { + Phase *Phase `json:"phase,omitempty"` + PhaseInformation *map[string]string `json:"phaseInformation,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseoperations/predicates.go b/resource-manager/sql/2023-08-01/databaseoperations/predicates.go new file mode 100644 index 00000000000..89467769b5b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/predicates.go @@ -0,0 +1,27 @@ +package databaseoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseOperationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseOperationOperationPredicate) Matches(input DatabaseOperation) 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/sql/2023-08-01/databaseoperations/version.go b/resource-manager/sql/2023-08-01/databaseoperations/version.go new file mode 100644 index 00000000000..f77235ce50a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseoperations/version.go @@ -0,0 +1,10 @@ +package databaseoperations + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseoperations/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/README.md b/resource-manager/sql/2023-08-01/databaserecommendedactions/README.md new file mode 100644 index 00000000000..8171128e3d6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaserecommendedactions` Documentation + +The `databaserecommendedactions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaserecommendedactions" +``` + + +### Client Initialization + +```go +client := databaserecommendedactions.NewDatabaseRecommendedActionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseRecommendedActionsClient.Get` + +```go +ctx := context.TODO() +id := databaserecommendedactions.NewRecommendedActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName", "recommendedActionName") + +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: `DatabaseRecommendedActionsClient.ListByDatabaseAdvisor` + +```go +ctx := context.TODO() +id := databaserecommendedactions.NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName") + +read, err := client.ListByDatabaseAdvisor(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseRecommendedActionsClient.Update` + +```go +ctx := context.TODO() +id := databaserecommendedactions.NewRecommendedActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName", "recommendedActionName") + +payload := databaserecommendedactions.RecommendedAction{ + // ... +} + + +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/sql/2023-08-01/databaserecommendedactions/client.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/client.go new file mode 100644 index 00000000000..02420960308 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/client.go @@ -0,0 +1,26 @@ +package databaserecommendedactions + +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 DatabaseRecommendedActionsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseRecommendedActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseRecommendedActionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaserecommendedactions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseRecommendedActionsClient: %+v", err) + } + + return &DatabaseRecommendedActionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/constants.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/constants.go new file mode 100644 index 00000000000..cf153226251 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/constants.go @@ -0,0 +1,210 @@ +package databaserecommendedactions + +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 ImplementationMethod string + +const ( + ImplementationMethodAzurePowerShell ImplementationMethod = "AzurePowerShell" + ImplementationMethodTSql ImplementationMethod = "TSql" +) + +func PossibleValuesForImplementationMethod() []string { + return []string{ + string(ImplementationMethodAzurePowerShell), + string(ImplementationMethodTSql), + } +} + +func (s *ImplementationMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImplementationMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImplementationMethod(input string) (*ImplementationMethod, error) { + vals := map[string]ImplementationMethod{ + "azurepowershell": ImplementationMethodAzurePowerShell, + "tsql": ImplementationMethodTSql, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImplementationMethod(input) + return &out, nil +} + +type IsRetryable string + +const ( + IsRetryableNo IsRetryable = "No" + IsRetryableYes IsRetryable = "Yes" +) + +func PossibleValuesForIsRetryable() []string { + return []string{ + string(IsRetryableNo), + string(IsRetryableYes), + } +} + +func (s *IsRetryable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsRetryable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsRetryable(input string) (*IsRetryable, error) { + vals := map[string]IsRetryable{ + "no": IsRetryableNo, + "yes": IsRetryableYes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsRetryable(input) + return &out, nil +} + +type RecommendedActionCurrentState string + +const ( + RecommendedActionCurrentStateActive RecommendedActionCurrentState = "Active" + RecommendedActionCurrentStateError RecommendedActionCurrentState = "Error" + RecommendedActionCurrentStateExecuting RecommendedActionCurrentState = "Executing" + RecommendedActionCurrentStateExpired RecommendedActionCurrentState = "Expired" + RecommendedActionCurrentStateIgnored RecommendedActionCurrentState = "Ignored" + RecommendedActionCurrentStateMonitoring RecommendedActionCurrentState = "Monitoring" + RecommendedActionCurrentStatePending RecommendedActionCurrentState = "Pending" + RecommendedActionCurrentStatePendingRevert RecommendedActionCurrentState = "PendingRevert" + RecommendedActionCurrentStateResolved RecommendedActionCurrentState = "Resolved" + RecommendedActionCurrentStateRevertCancelled RecommendedActionCurrentState = "RevertCancelled" + RecommendedActionCurrentStateReverted RecommendedActionCurrentState = "Reverted" + RecommendedActionCurrentStateReverting RecommendedActionCurrentState = "Reverting" + RecommendedActionCurrentStateSuccess RecommendedActionCurrentState = "Success" + RecommendedActionCurrentStateVerifying RecommendedActionCurrentState = "Verifying" +) + +func PossibleValuesForRecommendedActionCurrentState() []string { + return []string{ + string(RecommendedActionCurrentStateActive), + string(RecommendedActionCurrentStateError), + string(RecommendedActionCurrentStateExecuting), + string(RecommendedActionCurrentStateExpired), + string(RecommendedActionCurrentStateIgnored), + string(RecommendedActionCurrentStateMonitoring), + string(RecommendedActionCurrentStatePending), + string(RecommendedActionCurrentStatePendingRevert), + string(RecommendedActionCurrentStateResolved), + string(RecommendedActionCurrentStateRevertCancelled), + string(RecommendedActionCurrentStateReverted), + string(RecommendedActionCurrentStateReverting), + string(RecommendedActionCurrentStateSuccess), + string(RecommendedActionCurrentStateVerifying), + } +} + +func (s *RecommendedActionCurrentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedActionCurrentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedActionCurrentState(input string) (*RecommendedActionCurrentState, error) { + vals := map[string]RecommendedActionCurrentState{ + "active": RecommendedActionCurrentStateActive, + "error": RecommendedActionCurrentStateError, + "executing": RecommendedActionCurrentStateExecuting, + "expired": RecommendedActionCurrentStateExpired, + "ignored": RecommendedActionCurrentStateIgnored, + "monitoring": RecommendedActionCurrentStateMonitoring, + "pending": RecommendedActionCurrentStatePending, + "pendingrevert": RecommendedActionCurrentStatePendingRevert, + "resolved": RecommendedActionCurrentStateResolved, + "revertcancelled": RecommendedActionCurrentStateRevertCancelled, + "reverted": RecommendedActionCurrentStateReverted, + "reverting": RecommendedActionCurrentStateReverting, + "success": RecommendedActionCurrentStateSuccess, + "verifying": RecommendedActionCurrentStateVerifying, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedActionCurrentState(input) + return &out, nil +} + +type RecommendedActionInitiatedBy string + +const ( + RecommendedActionInitiatedBySystem RecommendedActionInitiatedBy = "System" + RecommendedActionInitiatedByUser RecommendedActionInitiatedBy = "User" +) + +func PossibleValuesForRecommendedActionInitiatedBy() []string { + return []string{ + string(RecommendedActionInitiatedBySystem), + string(RecommendedActionInitiatedByUser), + } +} + +func (s *RecommendedActionInitiatedBy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedActionInitiatedBy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedActionInitiatedBy(input string) (*RecommendedActionInitiatedBy, error) { + vals := map[string]RecommendedActionInitiatedBy{ + "system": RecommendedActionInitiatedBySystem, + "user": RecommendedActionInitiatedByUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedActionInitiatedBy(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor.go new file mode 100644 index 00000000000..a711aa5c490 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor.go @@ -0,0 +1,148 @@ +package databaserecommendedactions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseAdvisorId{}) +} + +var _ resourceids.ResourceId = &DatabaseAdvisorId{} + +// DatabaseAdvisorId is a struct representing the Resource ID for a Database Advisor +type DatabaseAdvisorId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + AdvisorName string +} + +// NewDatabaseAdvisorID returns a new DatabaseAdvisorId struct +func NewDatabaseAdvisorID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, advisorName string) DatabaseAdvisorId { + return DatabaseAdvisorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + AdvisorName: advisorName, + } +} + +// ParseDatabaseAdvisorID parses 'input' into a DatabaseAdvisorId +func ParseDatabaseAdvisorID(input string) (*DatabaseAdvisorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseAdvisorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseAdvisorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseAdvisorIDInsensitively parses 'input' case-insensitively into a DatabaseAdvisorId +// note: this method should only be used for API response data and not user input +func ParseDatabaseAdvisorIDInsensitively(input string) (*DatabaseAdvisorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseAdvisorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseAdvisorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseAdvisorId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.AdvisorName, ok = input.Parsed["advisorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "advisorName", input) + } + + return nil +} + +// ValidateDatabaseAdvisorID checks that 'input' can be parsed as a Database Advisor ID +func ValidateDatabaseAdvisorID(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 := ParseDatabaseAdvisorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database Advisor ID +func (id DatabaseAdvisorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/advisors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.AdvisorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database Advisor ID +func (id DatabaseAdvisorId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorName"), + } +} + +// String returns a human-readable description of this Database Advisor ID +func (id DatabaseAdvisorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Advisor Name: %q", id.AdvisorName), + } + return fmt.Sprintf("Database Advisor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor_test.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor_test.go new file mode 100644 index 00000000000..3062b7a54e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_databaseadvisor_test.go @@ -0,0 +1,372 @@ +package databaserecommendedactions + +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 = &DatabaseAdvisorId{} + +func TestNewDatabaseAdvisorID(t *testing.T) { + id := NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.AdvisorName != "advisorName" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorName") + } +} + +func TestFormatDatabaseAdvisorID(t *testing.T) { + actual := NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseAdvisorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseAdvisorId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + AdvisorName: "advisorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseAdvisorID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + } +} + +func TestParseDatabaseAdvisorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseAdvisorId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + AdvisorName: "advisorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + AdvisorName: "aDvIsOrNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseAdvisorIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + } +} + +func TestSegmentsForDatabaseAdvisorId(t *testing.T) { + segments := DatabaseAdvisorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseAdvisorId 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/sql/2023-08-01/databaserecommendedactions/id_recommendedaction.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction.go new file mode 100644 index 00000000000..3e9fe3e359f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction.go @@ -0,0 +1,157 @@ +package databaserecommendedactions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RecommendedActionId{}) +} + +var _ resourceids.ResourceId = &RecommendedActionId{} + +// RecommendedActionId is a struct representing the Resource ID for a Recommended Action +type RecommendedActionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + AdvisorName string + RecommendedActionName string +} + +// NewRecommendedActionID returns a new RecommendedActionId struct +func NewRecommendedActionID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, advisorName string, recommendedActionName string) RecommendedActionId { + return RecommendedActionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + AdvisorName: advisorName, + RecommendedActionName: recommendedActionName, + } +} + +// ParseRecommendedActionID parses 'input' into a RecommendedActionId +func ParseRecommendedActionID(input string) (*RecommendedActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecommendedActionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecommendedActionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecommendedActionIDInsensitively parses 'input' case-insensitively into a RecommendedActionId +// note: this method should only be used for API response data and not user input +func ParseRecommendedActionIDInsensitively(input string) (*RecommendedActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecommendedActionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecommendedActionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecommendedActionId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.AdvisorName, ok = input.Parsed["advisorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "advisorName", input) + } + + if id.RecommendedActionName, ok = input.Parsed["recommendedActionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recommendedActionName", input) + } + + return nil +} + +// ValidateRecommendedActionID checks that 'input' can be parsed as a Recommended Action ID +func ValidateRecommendedActionID(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 := ParseRecommendedActionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recommended Action ID +func (id RecommendedActionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/advisors/%s/recommendedActions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.AdvisorName, id.RecommendedActionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recommended Action ID +func (id RecommendedActionId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorName"), + resourceids.StaticSegment("staticRecommendedActions", "recommendedActions", "recommendedActions"), + resourceids.UserSpecifiedSegment("recommendedActionName", "recommendedActionName"), + } +} + +// String returns a human-readable description of this Recommended Action ID +func (id RecommendedActionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Advisor Name: %q", id.AdvisorName), + fmt.Sprintf("Recommended Action Name: %q", id.RecommendedActionName), + } + return fmt.Sprintf("Recommended Action (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction_test.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction_test.go new file mode 100644 index 00000000000..71a74785d98 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/id_recommendedaction_test.go @@ -0,0 +1,417 @@ +package databaserecommendedactions + +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 = &RecommendedActionId{} + +func TestNewRecommendedActionID(t *testing.T) { + id := NewRecommendedActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName", "recommendedActionName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.AdvisorName != "advisorName" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorName") + } + + if id.RecommendedActionName != "recommendedActionName" { + t.Fatalf("Expected %q but got %q for Segment 'RecommendedActionName'", id.RecommendedActionName, "recommendedActionName") + } +} + +func TestFormatRecommendedActionID(t *testing.T) { + actual := NewRecommendedActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "advisorName", "recommendedActionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions/recommendedActionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecommendedActionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecommendedActionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions/recommendedActionName", + Expected: &RecommendedActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + AdvisorName: "advisorName", + RecommendedActionName: "recommendedActionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions/recommendedActionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecommendedActionID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + if actual.RecommendedActionName != v.Expected.RecommendedActionName { + t.Fatalf("Expected %q but got %q for RecommendedActionName", v.Expected.RecommendedActionName, actual.RecommendedActionName) + } + + } +} + +func TestParseRecommendedActionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecommendedActionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe/rEcOmMeNdEdAcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions/recommendedActionName", + Expected: &RecommendedActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + AdvisorName: "advisorName", + RecommendedActionName: "recommendedActionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/advisors/advisorName/recommendedActions/recommendedActionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe/rEcOmMeNdEdAcTiOnS/rEcOmMeNdEdAcTiOnNaMe", + Expected: &RecommendedActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + AdvisorName: "aDvIsOrNaMe", + RecommendedActionName: "rEcOmMeNdEdAcTiOnNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/aDvIsOrS/aDvIsOrNaMe/rEcOmMeNdEdAcTiOnS/rEcOmMeNdEdAcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecommendedActionIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + if actual.RecommendedActionName != v.Expected.RecommendedActionName { + t.Fatalf("Expected %q but got %q for RecommendedActionName", v.Expected.RecommendedActionName, actual.RecommendedActionName) + } + + } +} + +func TestSegmentsForRecommendedActionId(t *testing.T) { + segments := RecommendedActionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecommendedActionId 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/sql/2023-08-01/databaserecommendedactions/method_get.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/method_get.go new file mode 100644 index 00000000000..746442a33bd --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/method_get.go @@ -0,0 +1,53 @@ +package databaserecommendedactions + +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 *RecommendedAction +} + +// Get ... +func (c DatabaseRecommendedActionsClient) Get(ctx context.Context, id RecommendedActionId) (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 RecommendedAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/method_listbydatabaseadvisor.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/method_listbydatabaseadvisor.go new file mode 100644 index 00000000000..7ee295f95c4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/method_listbydatabaseadvisor.go @@ -0,0 +1,54 @@ +package databaserecommendedactions + +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 ListByDatabaseAdvisorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecommendedAction +} + +// ListByDatabaseAdvisor ... +func (c DatabaseRecommendedActionsClient) ListByDatabaseAdvisor(ctx context.Context, id DatabaseAdvisorId) (result ListByDatabaseAdvisorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/recommendedActions", 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 []RecommendedAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/method_update.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/method_update.go new file mode 100644 index 00000000000..f2b6314e21d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/method_update.go @@ -0,0 +1,57 @@ +package databaserecommendedactions + +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 *RecommendedAction +} + +// Update ... +func (c DatabaseRecommendedActionsClient) Update(ctx context.Context, id RecommendedActionId, input RecommendedAction) (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 RecommendedAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedaction.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedaction.go new file mode 100644 index 00000000000..0ef18cd29be --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedaction.go @@ -0,0 +1,13 @@ +package databaserecommendedactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedAction struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendedActionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionerrorinfo.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionerrorinfo.go new file mode 100644 index 00000000000..351084214e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionerrorinfo.go @@ -0,0 +1,9 @@ +package databaserecommendedactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionErrorInfo struct { + ErrorCode *string `json:"errorCode,omitempty"` + IsRetryable *IsRetryable `json:"isRetryable,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimpactrecord.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimpactrecord.go new file mode 100644 index 00000000000..d3269199b1b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimpactrecord.go @@ -0,0 +1,12 @@ +package databaserecommendedactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionImpactRecord struct { + AbsoluteValue *float64 `json:"absoluteValue,omitempty"` + ChangeValueAbsolute *float64 `json:"changeValueAbsolute,omitempty"` + ChangeValueRelative *float64 `json:"changeValueRelative,omitempty"` + DimensionName *string `json:"dimensionName,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimplementationinfo.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimplementationinfo.go new file mode 100644 index 00000000000..c29ddc69ebf --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionimplementationinfo.go @@ -0,0 +1,9 @@ +package databaserecommendedactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionImplementationInfo struct { + Method *ImplementationMethod `json:"method,omitempty"` + Script *string `json:"script,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionmetricinfo.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionmetricinfo.go new file mode 100644 index 00000000000..3a2614cc8a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionmetricinfo.go @@ -0,0 +1,30 @@ +package databaserecommendedactions + +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 RecommendedActionMetricInfo struct { + MetricName *string `json:"metricName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + TimeGrain *string `json:"timeGrain,omitempty"` + Unit *string `json:"unit,omitempty"` + Value *float64 `json:"value,omitempty"` +} + +func (o *RecommendedActionMetricInfo) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionMetricInfo) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionproperties.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionproperties.go new file mode 100644 index 00000000000..e8cdf622129 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionproperties.go @@ -0,0 +1,108 @@ +package databaserecommendedactions + +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 RecommendedActionProperties struct { + Details *map[string]string `json:"details,omitempty"` + ErrorDetails *RecommendedActionErrorInfo `json:"errorDetails,omitempty"` + EstimatedImpact *[]RecommendedActionImpactRecord `json:"estimatedImpact,omitempty"` + ExecuteActionDuration *string `json:"executeActionDuration,omitempty"` + ExecuteActionInitiatedBy *RecommendedActionInitiatedBy `json:"executeActionInitiatedBy,omitempty"` + ExecuteActionInitiatedTime *string `json:"executeActionInitiatedTime,omitempty"` + ExecuteActionStartTime *string `json:"executeActionStartTime,omitempty"` + ImplementationDetails *RecommendedActionImplementationInfo `json:"implementationDetails,omitempty"` + IsArchivedAction *bool `json:"isArchivedAction,omitempty"` + IsExecutableAction *bool `json:"isExecutableAction,omitempty"` + IsRevertableAction *bool `json:"isRevertableAction,omitempty"` + LastRefresh *string `json:"lastRefresh,omitempty"` + LinkedObjects *[]string `json:"linkedObjects,omitempty"` + ObservedImpact *[]RecommendedActionImpactRecord `json:"observedImpact,omitempty"` + RecommendationReason *string `json:"recommendationReason,omitempty"` + RevertActionDuration *string `json:"revertActionDuration,omitempty"` + RevertActionInitiatedBy *RecommendedActionInitiatedBy `json:"revertActionInitiatedBy,omitempty"` + RevertActionInitiatedTime *string `json:"revertActionInitiatedTime,omitempty"` + RevertActionStartTime *string `json:"revertActionStartTime,omitempty"` + Score *int64 `json:"score,omitempty"` + State RecommendedActionStateInfo `json:"state"` + TimeSeries *[]RecommendedActionMetricInfo `json:"timeSeries,omitempty"` + ValidSince *string `json:"validSince,omitempty"` +} + +func (o *RecommendedActionProperties) GetExecuteActionInitiatedTimeAsTime() (*time.Time, error) { + if o.ExecuteActionInitiatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExecuteActionInitiatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetExecuteActionInitiatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExecuteActionInitiatedTime = &formatted +} + +func (o *RecommendedActionProperties) GetExecuteActionStartTimeAsTime() (*time.Time, error) { + if o.ExecuteActionStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExecuteActionStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetExecuteActionStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExecuteActionStartTime = &formatted +} + +func (o *RecommendedActionProperties) GetLastRefreshAsTime() (*time.Time, error) { + if o.LastRefresh == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefresh, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetLastRefreshAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefresh = &formatted +} + +func (o *RecommendedActionProperties) GetRevertActionInitiatedTimeAsTime() (*time.Time, error) { + if o.RevertActionInitiatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RevertActionInitiatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetRevertActionInitiatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevertActionInitiatedTime = &formatted +} + +func (o *RecommendedActionProperties) GetRevertActionStartTimeAsTime() (*time.Time, error) { + if o.RevertActionStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RevertActionStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetRevertActionStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevertActionStartTime = &formatted +} + +func (o *RecommendedActionProperties) GetValidSinceAsTime() (*time.Time, error) { + if o.ValidSince == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidSince, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetValidSinceAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidSince = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionstateinfo.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionstateinfo.go new file mode 100644 index 00000000000..ed649289ec8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/model_recommendedactionstateinfo.go @@ -0,0 +1,28 @@ +package databaserecommendedactions + +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 RecommendedActionStateInfo struct { + ActionInitiatedBy *RecommendedActionInitiatedBy `json:"actionInitiatedBy,omitempty"` + CurrentValue RecommendedActionCurrentState `json:"currentValue"` + LastModified *string `json:"lastModified,omitempty"` +} + +func (o *RecommendedActionStateInfo) GetLastModifiedAsTime() (*time.Time, error) { + if o.LastModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionStateInfo) SetLastModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModified = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databaserecommendedactions/version.go b/resource-manager/sql/2023-08-01/databaserecommendedactions/version.go new file mode 100644 index 00000000000..8443eba4319 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaserecommendedactions/version.go @@ -0,0 +1,10 @@ +package databaserecommendedactions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaserecommendedactions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databases/README.md b/resource-manager/sql/2023-08-01/databases/README.md new file mode 100644 index 00000000000..6226ac47c6f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/README.md @@ -0,0 +1,237 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databases` Documentation + +The `databases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databases" +``` + + +### Client Initialization + +```go +client := databases.NewDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabasesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databases.Database{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Export` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databases.ExportDatabaseDefinition{ + // ... +} + + +if err := client.ExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Failover` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +if err := client.FailoverThenPoll(ctx, id, databases.DefaultFailoverOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.Get(ctx, id, databases.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabasesClient.Import` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databases.ImportExistingDatabaseDefinition{ + // ... +} + + +if err := client.ImportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ListByElasticPool` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +// alternatively `client.ListByElasticPool(ctx, id)` can be used to do batched pagination +items, err := client.ListByElasticPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DatabasesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DatabasesClient.ListInaccessibleByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListInaccessibleByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListInaccessibleByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DatabasesClient.Pause` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +if err := client.PauseThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Rename` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databases.ResourceMoveDefinition{ + // ... +} + + +read, err := client.Rename(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabasesClient.Resume` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +if err := client.ResumeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databases.DatabaseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.UpgradeDataWarehouse` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +if err := client.UpgradeDataWarehouseThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/databases/client.go b/resource-manager/sql/2023-08-01/databases/client.go new file mode 100644 index 00000000000..87de2d4fe59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/client.go @@ -0,0 +1,26 @@ +package databases + +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 DatabasesClient struct { + Client *resourcemanager.Client +} + +func NewDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabasesClient: %+v", err) + } + + return &DatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databases/constants.go b/resource-manager/sql/2023-08-01/databases/constants.go new file mode 100644 index 00000000000..103d7fcf638 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/constants.go @@ -0,0 +1,689 @@ +package databases + +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 AlwaysEncryptedEnclaveType string + +const ( + AlwaysEncryptedEnclaveTypeDefault AlwaysEncryptedEnclaveType = "Default" + AlwaysEncryptedEnclaveTypeVBS AlwaysEncryptedEnclaveType = "VBS" +) + +func PossibleValuesForAlwaysEncryptedEnclaveType() []string { + return []string{ + string(AlwaysEncryptedEnclaveTypeDefault), + string(AlwaysEncryptedEnclaveTypeVBS), + } +} + +func (s *AlwaysEncryptedEnclaveType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlwaysEncryptedEnclaveType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlwaysEncryptedEnclaveType(input string) (*AlwaysEncryptedEnclaveType, error) { + vals := map[string]AlwaysEncryptedEnclaveType{ + "default": AlwaysEncryptedEnclaveTypeDefault, + "vbs": AlwaysEncryptedEnclaveTypeVBS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlwaysEncryptedEnclaveType(input) + return &out, nil +} + +type AvailabilityZoneType string + +const ( + AvailabilityZoneTypeNoPreference AvailabilityZoneType = "NoPreference" + AvailabilityZoneTypeOne AvailabilityZoneType = "1" + AvailabilityZoneTypeThree AvailabilityZoneType = "3" + AvailabilityZoneTypeTwo AvailabilityZoneType = "2" +) + +func PossibleValuesForAvailabilityZoneType() []string { + return []string{ + string(AvailabilityZoneTypeNoPreference), + string(AvailabilityZoneTypeOne), + string(AvailabilityZoneTypeThree), + string(AvailabilityZoneTypeTwo), + } +} + +func (s *AvailabilityZoneType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAvailabilityZoneType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAvailabilityZoneType(input string) (*AvailabilityZoneType, error) { + vals := map[string]AvailabilityZoneType{ + "nopreference": AvailabilityZoneTypeNoPreference, + "1": AvailabilityZoneTypeOne, + "3": AvailabilityZoneTypeThree, + "2": AvailabilityZoneTypeTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AvailabilityZoneType(input) + return &out, nil +} + +type BackupStorageRedundancy string + +const ( + BackupStorageRedundancyGeo BackupStorageRedundancy = "Geo" + BackupStorageRedundancyGeoZone BackupStorageRedundancy = "GeoZone" + BackupStorageRedundancyLocal BackupStorageRedundancy = "Local" + BackupStorageRedundancyZone BackupStorageRedundancy = "Zone" +) + +func PossibleValuesForBackupStorageRedundancy() []string { + return []string{ + string(BackupStorageRedundancyGeo), + string(BackupStorageRedundancyGeoZone), + string(BackupStorageRedundancyLocal), + string(BackupStorageRedundancyZone), + } +} + +func (s *BackupStorageRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageRedundancy(input string) (*BackupStorageRedundancy, error) { + vals := map[string]BackupStorageRedundancy{ + "geo": BackupStorageRedundancyGeo, + "geozone": BackupStorageRedundancyGeoZone, + "local": BackupStorageRedundancyLocal, + "zone": BackupStorageRedundancyZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageRedundancy(input) + return &out, nil +} + +type CatalogCollationType string + +const ( + CatalogCollationTypeDATABASEDEFAULT CatalogCollationType = "DATABASE_DEFAULT" + CatalogCollationTypeSQLLatinOneGeneralCPOneCIAS CatalogCollationType = "SQL_Latin1_General_CP1_CI_AS" +) + +func PossibleValuesForCatalogCollationType() []string { + return []string{ + string(CatalogCollationTypeDATABASEDEFAULT), + string(CatalogCollationTypeSQLLatinOneGeneralCPOneCIAS), + } +} + +func (s *CatalogCollationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogCollationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogCollationType(input string) (*CatalogCollationType, error) { + vals := map[string]CatalogCollationType{ + "database_default": CatalogCollationTypeDATABASEDEFAULT, + "sql_latin1_general_cp1_ci_as": CatalogCollationTypeSQLLatinOneGeneralCPOneCIAS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogCollationType(input) + return &out, nil +} + +type CreateMode string + +const ( + CreateModeCopy CreateMode = "Copy" + CreateModeDefault CreateMode = "Default" + CreateModeOnlineSecondary CreateMode = "OnlineSecondary" + CreateModePointInTimeRestore CreateMode = "PointInTimeRestore" + CreateModeRecovery CreateMode = "Recovery" + CreateModeRestore CreateMode = "Restore" + CreateModeRestoreExternalBackup CreateMode = "RestoreExternalBackup" + CreateModeRestoreExternalBackupSecondary CreateMode = "RestoreExternalBackupSecondary" + CreateModeRestoreLongTermRetentionBackup CreateMode = "RestoreLongTermRetentionBackup" + CreateModeSecondary CreateMode = "Secondary" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeCopy), + string(CreateModeDefault), + string(CreateModeOnlineSecondary), + string(CreateModePointInTimeRestore), + string(CreateModeRecovery), + string(CreateModeRestore), + string(CreateModeRestoreExternalBackup), + string(CreateModeRestoreExternalBackupSecondary), + string(CreateModeRestoreLongTermRetentionBackup), + string(CreateModeSecondary), + } +} + +func (s *CreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "copy": CreateModeCopy, + "default": CreateModeDefault, + "onlinesecondary": CreateModeOnlineSecondary, + "pointintimerestore": CreateModePointInTimeRestore, + "recovery": CreateModeRecovery, + "restore": CreateModeRestore, + "restoreexternalbackup": CreateModeRestoreExternalBackup, + "restoreexternalbackupsecondary": CreateModeRestoreExternalBackupSecondary, + "restorelongtermretentionbackup": CreateModeRestoreLongTermRetentionBackup, + "secondary": CreateModeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateMode(input) + return &out, nil +} + +type DatabaseKeyType string + +const ( + DatabaseKeyTypeAzureKeyVault DatabaseKeyType = "AzureKeyVault" +) + +func PossibleValuesForDatabaseKeyType() []string { + return []string{ + string(DatabaseKeyTypeAzureKeyVault), + } +} + +func (s *DatabaseKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseKeyType(input string) (*DatabaseKeyType, error) { + vals := map[string]DatabaseKeyType{ + "azurekeyvault": DatabaseKeyTypeAzureKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseKeyType(input) + return &out, nil +} + +type DatabaseLicenseType string + +const ( + DatabaseLicenseTypeBasePrice DatabaseLicenseType = "BasePrice" + DatabaseLicenseTypeLicenseIncluded DatabaseLicenseType = "LicenseIncluded" +) + +func PossibleValuesForDatabaseLicenseType() []string { + return []string{ + string(DatabaseLicenseTypeBasePrice), + string(DatabaseLicenseTypeLicenseIncluded), + } +} + +func (s *DatabaseLicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseLicenseType(input string) (*DatabaseLicenseType, error) { + vals := map[string]DatabaseLicenseType{ + "baseprice": DatabaseLicenseTypeBasePrice, + "licenseincluded": DatabaseLicenseTypeLicenseIncluded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseLicenseType(input) + return &out, nil +} + +type DatabaseReadScale string + +const ( + DatabaseReadScaleDisabled DatabaseReadScale = "Disabled" + DatabaseReadScaleEnabled DatabaseReadScale = "Enabled" +) + +func PossibleValuesForDatabaseReadScale() []string { + return []string{ + string(DatabaseReadScaleDisabled), + string(DatabaseReadScaleEnabled), + } +} + +func (s *DatabaseReadScale) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseReadScale(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseReadScale(input string) (*DatabaseReadScale, error) { + vals := map[string]DatabaseReadScale{ + "disabled": DatabaseReadScaleDisabled, + "enabled": DatabaseReadScaleEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseReadScale(input) + return &out, nil +} + +type DatabaseStatus string + +const ( + DatabaseStatusAutoClosed DatabaseStatus = "AutoClosed" + DatabaseStatusCopying DatabaseStatus = "Copying" + DatabaseStatusCreating DatabaseStatus = "Creating" + DatabaseStatusDisabled DatabaseStatus = "Disabled" + DatabaseStatusEmergencyMode DatabaseStatus = "EmergencyMode" + DatabaseStatusInaccessible DatabaseStatus = "Inaccessible" + DatabaseStatusOffline DatabaseStatus = "Offline" + DatabaseStatusOfflineChangingDwPerformanceTiers DatabaseStatus = "OfflineChangingDwPerformanceTiers" + DatabaseStatusOfflineSecondary DatabaseStatus = "OfflineSecondary" + DatabaseStatusOnline DatabaseStatus = "Online" + DatabaseStatusOnlineChangingDwPerformanceTiers DatabaseStatus = "OnlineChangingDwPerformanceTiers" + DatabaseStatusPaused DatabaseStatus = "Paused" + DatabaseStatusPausing DatabaseStatus = "Pausing" + DatabaseStatusRecovering DatabaseStatus = "Recovering" + DatabaseStatusRecoveryPending DatabaseStatus = "RecoveryPending" + DatabaseStatusRestoring DatabaseStatus = "Restoring" + DatabaseStatusResuming DatabaseStatus = "Resuming" + DatabaseStatusScaling DatabaseStatus = "Scaling" + DatabaseStatusShutdown DatabaseStatus = "Shutdown" + DatabaseStatusStandby DatabaseStatus = "Standby" + DatabaseStatusStarting DatabaseStatus = "Starting" + DatabaseStatusStopped DatabaseStatus = "Stopped" + DatabaseStatusStopping DatabaseStatus = "Stopping" + DatabaseStatusSuspect DatabaseStatus = "Suspect" +) + +func PossibleValuesForDatabaseStatus() []string { + return []string{ + string(DatabaseStatusAutoClosed), + string(DatabaseStatusCopying), + string(DatabaseStatusCreating), + string(DatabaseStatusDisabled), + string(DatabaseStatusEmergencyMode), + string(DatabaseStatusInaccessible), + string(DatabaseStatusOffline), + string(DatabaseStatusOfflineChangingDwPerformanceTiers), + string(DatabaseStatusOfflineSecondary), + string(DatabaseStatusOnline), + string(DatabaseStatusOnlineChangingDwPerformanceTiers), + string(DatabaseStatusPaused), + string(DatabaseStatusPausing), + string(DatabaseStatusRecovering), + string(DatabaseStatusRecoveryPending), + string(DatabaseStatusRestoring), + string(DatabaseStatusResuming), + string(DatabaseStatusScaling), + string(DatabaseStatusShutdown), + string(DatabaseStatusStandby), + string(DatabaseStatusStarting), + string(DatabaseStatusStopped), + string(DatabaseStatusStopping), + string(DatabaseStatusSuspect), + } +} + +func (s *DatabaseStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseStatus(input string) (*DatabaseStatus, error) { + vals := map[string]DatabaseStatus{ + "autoclosed": DatabaseStatusAutoClosed, + "copying": DatabaseStatusCopying, + "creating": DatabaseStatusCreating, + "disabled": DatabaseStatusDisabled, + "emergencymode": DatabaseStatusEmergencyMode, + "inaccessible": DatabaseStatusInaccessible, + "offline": DatabaseStatusOffline, + "offlinechangingdwperformancetiers": DatabaseStatusOfflineChangingDwPerformanceTiers, + "offlinesecondary": DatabaseStatusOfflineSecondary, + "online": DatabaseStatusOnline, + "onlinechangingdwperformancetiers": DatabaseStatusOnlineChangingDwPerformanceTiers, + "paused": DatabaseStatusPaused, + "pausing": DatabaseStatusPausing, + "recovering": DatabaseStatusRecovering, + "recoverypending": DatabaseStatusRecoveryPending, + "restoring": DatabaseStatusRestoring, + "resuming": DatabaseStatusResuming, + "scaling": DatabaseStatusScaling, + "shutdown": DatabaseStatusShutdown, + "standby": DatabaseStatusStandby, + "starting": DatabaseStatusStarting, + "stopped": DatabaseStatusStopped, + "stopping": DatabaseStatusStopping, + "suspect": DatabaseStatusSuspect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseStatus(input) + return &out, nil +} + +type FreeLimitExhaustionBehavior string + +const ( + FreeLimitExhaustionBehaviorAutoPause FreeLimitExhaustionBehavior = "AutoPause" + FreeLimitExhaustionBehaviorBillOverUsage FreeLimitExhaustionBehavior = "BillOverUsage" +) + +func PossibleValuesForFreeLimitExhaustionBehavior() []string { + return []string{ + string(FreeLimitExhaustionBehaviorAutoPause), + string(FreeLimitExhaustionBehaviorBillOverUsage), + } +} + +func (s *FreeLimitExhaustionBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFreeLimitExhaustionBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFreeLimitExhaustionBehavior(input string) (*FreeLimitExhaustionBehavior, error) { + vals := map[string]FreeLimitExhaustionBehavior{ + "autopause": FreeLimitExhaustionBehaviorAutoPause, + "billoverusage": FreeLimitExhaustionBehaviorBillOverUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FreeLimitExhaustionBehavior(input) + return &out, nil +} + +type ReplicaType string + +const ( + ReplicaTypePrimary ReplicaType = "Primary" + ReplicaTypeReadableSecondary ReplicaType = "ReadableSecondary" +) + +func PossibleValuesForReplicaType() []string { + return []string{ + string(ReplicaTypePrimary), + string(ReplicaTypeReadableSecondary), + } +} + +func (s *ReplicaType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicaType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicaType(input string) (*ReplicaType, error) { + vals := map[string]ReplicaType{ + "primary": ReplicaTypePrimary, + "readablesecondary": ReplicaTypeReadableSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicaType(input) + return &out, nil +} + +type SampleName string + +const ( + SampleNameAdventureWorksLT SampleName = "AdventureWorksLT" + SampleNameWideWorldImportersFull SampleName = "WideWorldImportersFull" + SampleNameWideWorldImportersStd SampleName = "WideWorldImportersStd" +) + +func PossibleValuesForSampleName() []string { + return []string{ + string(SampleNameAdventureWorksLT), + string(SampleNameWideWorldImportersFull), + string(SampleNameWideWorldImportersStd), + } +} + +func (s *SampleName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSampleName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSampleName(input string) (*SampleName, error) { + vals := map[string]SampleName{ + "adventureworkslt": SampleNameAdventureWorksLT, + "wideworldimportersfull": SampleNameWideWorldImportersFull, + "wideworldimportersstd": SampleNameWideWorldImportersStd, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SampleName(input) + return &out, nil +} + +type SecondaryType string + +const ( + SecondaryTypeGeo SecondaryType = "Geo" + SecondaryTypeNamed SecondaryType = "Named" + SecondaryTypeStandby SecondaryType = "Standby" +) + +func PossibleValuesForSecondaryType() []string { + return []string{ + string(SecondaryTypeGeo), + string(SecondaryTypeNamed), + string(SecondaryTypeStandby), + } +} + +func (s *SecondaryType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecondaryType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecondaryType(input string) (*SecondaryType, error) { + vals := map[string]SecondaryType{ + "geo": SecondaryTypeGeo, + "named": SecondaryTypeNamed, + "standby": SecondaryTypeStandby, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecondaryType(input) + return &out, nil +} + +type StorageKeyType string + +const ( + StorageKeyTypeSharedAccessKey StorageKeyType = "SharedAccessKey" + StorageKeyTypeStorageAccessKey StorageKeyType = "StorageAccessKey" +) + +func PossibleValuesForStorageKeyType() []string { + return []string{ + string(StorageKeyTypeSharedAccessKey), + string(StorageKeyTypeStorageAccessKey), + } +} + +func (s *StorageKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageKeyType(input string) (*StorageKeyType, error) { + vals := map[string]StorageKeyType{ + "sharedaccesskey": StorageKeyTypeSharedAccessKey, + "storageaccesskey": StorageKeyTypeStorageAccessKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databases/method_createorupdate.go b/resource-manager/sql/2023-08-01/databases/method_createorupdate.go new file mode 100644 index 00000000000..4edea095cec --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_createorupdate.go @@ -0,0 +1,77 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// CreateOrUpdate ... +func (c DatabasesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input Database) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 DatabasesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input Database) 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/sql/2023-08-01/databases/method_delete.go b/resource-manager/sql/2023-08-01/databases/method_delete.go new file mode 100644 index 00000000000..ee7372eb094 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_delete.go @@ -0,0 +1,72 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DatabasesClient) Delete(ctx context.Context, id commonids.SqlDatabaseId) (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 DatabasesClient) DeleteThenPoll(ctx context.Context, id commonids.SqlDatabaseId) 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/sql/2023-08-01/databases/method_export.go b/resource-manager/sql/2023-08-01/databases/method_export.go new file mode 100644 index 00000000000..c3a4d53610d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_export.go @@ -0,0 +1,76 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ImportExportOperationResult +} + +// Export ... +func (c DatabasesClient) Export(ctx context.Context, id commonids.SqlDatabaseId, input ExportDatabaseDefinition) (result ExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", 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 +} + +// ExportThenPoll performs Export then polls until it's completed +func (c DatabasesClient) ExportThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input ExportDatabaseDefinition) error { + result, err := c.Export(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Export: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Export: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databases/method_failover.go b/resource-manager/sql/2023-08-01/databases/method_failover.go new file mode 100644 index 00000000000..8de72667a50 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_failover.go @@ -0,0 +1,100 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type FailoverOperationOptions struct { + ReplicaType *ReplicaType +} + +func DefaultFailoverOperationOptions() FailoverOperationOptions { + return FailoverOperationOptions{} +} + +func (o FailoverOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o FailoverOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o FailoverOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ReplicaType != nil { + out.Append("replicaType", fmt.Sprintf("%v", *o.ReplicaType)) + } + return &out +} + +// Failover ... +func (c DatabasesClient) Failover(ctx context.Context, id commonids.SqlDatabaseId, options FailoverOperationOptions) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c DatabasesClient) FailoverThenPoll(ctx context.Context, id commonids.SqlDatabaseId, options FailoverOperationOptions) error { + result, err := c.Failover(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databases/method_get.go b/resource-manager/sql/2023-08-01/databases/method_get.go new file mode 100644 index 00000000000..1009685d61e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_get.go @@ -0,0 +1,88 @@ +package databases + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +type GetOperationOptions struct { + Expand *string + Filter *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)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// Get ... +func (c DatabasesClient) Get(ctx context.Context, id commonids.SqlDatabaseId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 Database + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databases/method_import.go b/resource-manager/sql/2023-08-01/databases/method_import.go new file mode 100644 index 00000000000..32c44883cb4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_import.go @@ -0,0 +1,76 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ImportExportOperationResult +} + +// Import ... +func (c DatabasesClient) Import(ctx context.Context, id commonids.SqlDatabaseId, input ImportExistingDatabaseDefinition) (result ImportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/import", 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 +} + +// ImportThenPoll performs Import then polls until it's completed +func (c DatabasesClient) ImportThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input ImportExistingDatabaseDefinition) error { + result, err := c.Import(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Import: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Import: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databases/method_listbyelasticpool.go b/resource-manager/sql/2023-08-01/databases/method_listbyelasticpool.go new file mode 100644 index 00000000000..3e93e091c33 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_listbyelasticpool.go @@ -0,0 +1,106 @@ +package databases + +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 ListByElasticPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Database +} + +type ListByElasticPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type ListByElasticPoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByElasticPoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByElasticPool ... +func (c DatabasesClient) ListByElasticPool(ctx context.Context, id commonids.SqlElasticPoolId) (result ListByElasticPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByElasticPoolCustomPager{}, + Path: fmt.Sprintf("%s/databases", 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 *[]Database `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByElasticPoolComplete retrieves all the results into a single object +func (c DatabasesClient) ListByElasticPoolComplete(ctx context.Context, id commonids.SqlElasticPoolId) (ListByElasticPoolCompleteResult, error) { + return c.ListByElasticPoolCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// ListByElasticPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabasesClient) ListByElasticPoolCompleteMatchingPredicate(ctx context.Context, id commonids.SqlElasticPoolId, predicate DatabaseOperationPredicate) (result ListByElasticPoolCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.ListByElasticPool(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByElasticPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databases/method_listbyserver.go b/resource-manager/sql/2023-08-01/databases/method_listbyserver.go new file mode 100644 index 00000000000..fc07bd1705f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_listbyserver.go @@ -0,0 +1,106 @@ +package databases + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Database +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c DatabasesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/databases", 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 *[]Database `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c DatabasesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabasesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate DatabaseOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databases/method_listinaccessiblebyserver.go b/resource-manager/sql/2023-08-01/databases/method_listinaccessiblebyserver.go new file mode 100644 index 00000000000..f0b388a51d8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_listinaccessiblebyserver.go @@ -0,0 +1,106 @@ +package databases + +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 ListInaccessibleByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Database +} + +type ListInaccessibleByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type ListInaccessibleByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListInaccessibleByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListInaccessibleByServer ... +func (c DatabasesClient) ListInaccessibleByServer(ctx context.Context, id commonids.SqlServerId) (result ListInaccessibleByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListInaccessibleByServerCustomPager{}, + Path: fmt.Sprintf("%s/inaccessibleDatabases", 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 *[]Database `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListInaccessibleByServerComplete retrieves all the results into a single object +func (c DatabasesClient) ListInaccessibleByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListInaccessibleByServerCompleteResult, error) { + return c.ListInaccessibleByServerCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// ListInaccessibleByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabasesClient) ListInaccessibleByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate DatabaseOperationPredicate) (result ListInaccessibleByServerCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.ListInaccessibleByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListInaccessibleByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databases/method_pause.go b/resource-manager/sql/2023-08-01/databases/method_pause.go new file mode 100644 index 00000000000..cebf09ec30b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_pause.go @@ -0,0 +1,72 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PauseOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// Pause ... +func (c DatabasesClient) Pause(ctx context.Context, id commonids.SqlDatabaseId) (result PauseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/pause", 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 +} + +// PauseThenPoll performs Pause then polls until it's completed +func (c DatabasesClient) PauseThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.Pause(ctx, id) + if err != nil { + return fmt.Errorf("performing Pause: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Pause: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databases/method_rename.go b/resource-manager/sql/2023-08-01/databases/method_rename.go new file mode 100644 index 00000000000..bb9f138f107 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_rename.go @@ -0,0 +1,52 @@ +package databases + +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 RenameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Rename ... +func (c DatabasesClient) Rename(ctx context.Context, id commonids.SqlDatabaseId, input ResourceMoveDefinition) (result RenameOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/move", 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databases/method_resume.go b/resource-manager/sql/2023-08-01/databases/method_resume.go new file mode 100644 index 00000000000..42e71a824cf --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_resume.go @@ -0,0 +1,72 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// Resume ... +func (c DatabasesClient) Resume(ctx context.Context, id commonids.SqlDatabaseId) (result ResumeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resume", 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 +} + +// ResumeThenPoll performs Resume then polls until it's completed +func (c DatabasesClient) ResumeThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.Resume(ctx, id) + if err != nil { + return fmt.Errorf("performing Resume: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Resume: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databases/method_update.go b/resource-manager/sql/2023-08-01/databases/method_update.go new file mode 100644 index 00000000000..821a7212d01 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_update.go @@ -0,0 +1,76 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// Update ... +func (c DatabasesClient) Update(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseUpdate) (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 DatabasesClient) UpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseUpdate) 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/sql/2023-08-01/databases/method_upgradedatawarehouse.go b/resource-manager/sql/2023-08-01/databases/method_upgradedatawarehouse.go new file mode 100644 index 00000000000..a2c0e27e304 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/method_upgradedatawarehouse.go @@ -0,0 +1,71 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpgradeDataWarehouseOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// UpgradeDataWarehouse ... +func (c DatabasesClient) UpgradeDataWarehouse(ctx context.Context, id commonids.SqlDatabaseId) (result UpgradeDataWarehouseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgradeDataWarehouse", 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 +} + +// UpgradeDataWarehouseThenPoll performs UpgradeDataWarehouse then polls until it's completed +func (c DatabasesClient) UpgradeDataWarehouseThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.UpgradeDataWarehouse(ctx, id) + if err != nil { + return fmt.Errorf("performing UpgradeDataWarehouse: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpgradeDataWarehouse: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databases/model_database.go b/resource-manager/sql/2023-08-01/databases/model_database.go new file mode 100644 index 00000000000..8fd11ab0bad --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_database.go @@ -0,0 +1,21 @@ +package databases + +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 Database struct { + Id *string `json:"id,omitempty"` + Identity *identity.UserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_databasekey.go b/resource-manager/sql/2023-08-01/databases/model_databasekey.go new file mode 100644 index 00000000000..182fefa3301 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_databasekey.go @@ -0,0 +1,29 @@ +package databases + +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 DatabaseKey struct { + CreationDate *string `json:"creationDate,omitempty"` + Subregion *string `json:"subregion,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Type *DatabaseKeyType `json:"type,omitempty"` +} + +func (o *DatabaseKey) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseKey) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databases/model_databaseproperties.go b/resource-manager/sql/2023-08-01/databases/model_databaseproperties.go new file mode 100644 index 00000000000..b0f2db382c3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_databaseproperties.go @@ -0,0 +1,133 @@ +package databases + +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 DatabaseProperties struct { + AutoPauseDelay *int64 `json:"autoPauseDelay,omitempty"` + AvailabilityZone *AvailabilityZoneType `json:"availabilityZone,omitempty"` + CatalogCollation *CatalogCollationType `json:"catalogCollation,omitempty"` + Collation *string `json:"collation,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + CurrentBackupStorageRedundancy *BackupStorageRedundancy `json:"currentBackupStorageRedundancy,omitempty"` + CurrentServiceObjectiveName *string `json:"currentServiceObjectiveName,omitempty"` + CurrentSku *Sku `json:"currentSku,omitempty"` + DatabaseId *string `json:"databaseId,omitempty"` + DefaultSecondaryLocation *string `json:"defaultSecondaryLocation,omitempty"` + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + ElasticPoolId *string `json:"elasticPoolId,omitempty"` + EncryptionProtector *string `json:"encryptionProtector,omitempty"` + EncryptionProtectorAutoRotation *bool `json:"encryptionProtectorAutoRotation,omitempty"` + FailoverGroupId *string `json:"failoverGroupId,omitempty"` + FederatedClientId *string `json:"federatedClientId,omitempty"` + FreeLimitExhaustionBehavior *FreeLimitExhaustionBehavior `json:"freeLimitExhaustionBehavior,omitempty"` + HighAvailabilityReplicaCount *int64 `json:"highAvailabilityReplicaCount,omitempty"` + IsInfraEncryptionEnabled *bool `json:"isInfraEncryptionEnabled,omitempty"` + IsLedgerOn *bool `json:"isLedgerOn,omitempty"` + Keys *map[string]DatabaseKey `json:"keys,omitempty"` + LicenseType *DatabaseLicenseType `json:"licenseType,omitempty"` + LongTermRetentionBackupResourceId *string `json:"longTermRetentionBackupResourceId,omitempty"` + MaintenanceConfigurationId *string `json:"maintenanceConfigurationId,omitempty"` + ManualCutover *bool `json:"manualCutover,omitempty"` + MaxLogSizeBytes *int64 `json:"maxLogSizeBytes,omitempty"` + MaxSizeBytes *int64 `json:"maxSizeBytes,omitempty"` + MinCapacity *float64 `json:"minCapacity,omitempty"` + PausedDate *string `json:"pausedDate,omitempty"` + PerformCutover *bool `json:"performCutover,omitempty"` + PreferredEnclaveType *AlwaysEncryptedEnclaveType `json:"preferredEnclaveType,omitempty"` + ReadScale *DatabaseReadScale `json:"readScale,omitempty"` + RecoverableDatabaseId *string `json:"recoverableDatabaseId,omitempty"` + RecoveryServicesRecoveryPointId *string `json:"recoveryServicesRecoveryPointId,omitempty"` + RequestedBackupStorageRedundancy *BackupStorageRedundancy `json:"requestedBackupStorageRedundancy,omitempty"` + RequestedServiceObjectiveName *string `json:"requestedServiceObjectiveName,omitempty"` + RestorableDroppedDatabaseId *string `json:"restorableDroppedDatabaseId,omitempty"` + RestorePointInTime *string `json:"restorePointInTime,omitempty"` + ResumedDate *string `json:"resumedDate,omitempty"` + SampleName *SampleName `json:"sampleName,omitempty"` + SecondaryType *SecondaryType `json:"secondaryType,omitempty"` + SourceDatabaseDeletionDate *string `json:"sourceDatabaseDeletionDate,omitempty"` + SourceDatabaseId *string `json:"sourceDatabaseId,omitempty"` + SourceResourceId *string `json:"sourceResourceId,omitempty"` + Status *DatabaseStatus `json:"status,omitempty"` + UseFreeLimit *bool `json:"useFreeLimit,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} + +func (o *DatabaseProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *DatabaseProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} + +func (o *DatabaseProperties) GetPausedDateAsTime() (*time.Time, error) { + if o.PausedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PausedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseProperties) SetPausedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PausedDate = &formatted +} + +func (o *DatabaseProperties) GetRestorePointInTimeAsTime() (*time.Time, error) { + if o.RestorePointInTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointInTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseProperties) SetRestorePointInTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointInTime = &formatted +} + +func (o *DatabaseProperties) GetResumedDateAsTime() (*time.Time, error) { + if o.ResumedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResumedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseProperties) SetResumedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResumedDate = &formatted +} + +func (o *DatabaseProperties) GetSourceDatabaseDeletionDateAsTime() (*time.Time, error) { + if o.SourceDatabaseDeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SourceDatabaseDeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseProperties) SetSourceDatabaseDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SourceDatabaseDeletionDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databases/model_databaseupdate.go b/resource-manager/sql/2023-08-01/databases/model_databaseupdate.go new file mode 100644 index 00000000000..e49e06c94e2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_databaseupdate.go @@ -0,0 +1,15 @@ +package databases + +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 DatabaseUpdate struct { + Identity *identity.UserAssignedMap `json:"identity,omitempty"` + Properties *DatabaseUpdateProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_databaseupdateproperties.go b/resource-manager/sql/2023-08-01/databases/model_databaseupdateproperties.go new file mode 100644 index 00000000000..d9263ad99db --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_databaseupdateproperties.go @@ -0,0 +1,131 @@ +package databases + +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 DatabaseUpdateProperties struct { + AutoPauseDelay *int64 `json:"autoPauseDelay,omitempty"` + CatalogCollation *CatalogCollationType `json:"catalogCollation,omitempty"` + Collation *string `json:"collation,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + CurrentBackupStorageRedundancy *BackupStorageRedundancy `json:"currentBackupStorageRedundancy,omitempty"` + CurrentServiceObjectiveName *string `json:"currentServiceObjectiveName,omitempty"` + CurrentSku *Sku `json:"currentSku,omitempty"` + DatabaseId *string `json:"databaseId,omitempty"` + DefaultSecondaryLocation *string `json:"defaultSecondaryLocation,omitempty"` + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + ElasticPoolId *string `json:"elasticPoolId,omitempty"` + EncryptionProtector *string `json:"encryptionProtector,omitempty"` + EncryptionProtectorAutoRotation *bool `json:"encryptionProtectorAutoRotation,omitempty"` + FailoverGroupId *string `json:"failoverGroupId,omitempty"` + FederatedClientId *string `json:"federatedClientId,omitempty"` + FreeLimitExhaustionBehavior *FreeLimitExhaustionBehavior `json:"freeLimitExhaustionBehavior,omitempty"` + HighAvailabilityReplicaCount *int64 `json:"highAvailabilityReplicaCount,omitempty"` + IsInfraEncryptionEnabled *bool `json:"isInfraEncryptionEnabled,omitempty"` + IsLedgerOn *bool `json:"isLedgerOn,omitempty"` + Keys *map[string]DatabaseKey `json:"keys,omitempty"` + LicenseType *DatabaseLicenseType `json:"licenseType,omitempty"` + LongTermRetentionBackupResourceId *string `json:"longTermRetentionBackupResourceId,omitempty"` + MaintenanceConfigurationId *string `json:"maintenanceConfigurationId,omitempty"` + ManualCutover *bool `json:"manualCutover,omitempty"` + MaxLogSizeBytes *int64 `json:"maxLogSizeBytes,omitempty"` + MaxSizeBytes *int64 `json:"maxSizeBytes,omitempty"` + MinCapacity *float64 `json:"minCapacity,omitempty"` + PausedDate *string `json:"pausedDate,omitempty"` + PerformCutover *bool `json:"performCutover,omitempty"` + PreferredEnclaveType *AlwaysEncryptedEnclaveType `json:"preferredEnclaveType,omitempty"` + ReadScale *DatabaseReadScale `json:"readScale,omitempty"` + RecoverableDatabaseId *string `json:"recoverableDatabaseId,omitempty"` + RecoveryServicesRecoveryPointId *string `json:"recoveryServicesRecoveryPointId,omitempty"` + RequestedBackupStorageRedundancy *BackupStorageRedundancy `json:"requestedBackupStorageRedundancy,omitempty"` + RequestedServiceObjectiveName *string `json:"requestedServiceObjectiveName,omitempty"` + RestorableDroppedDatabaseId *string `json:"restorableDroppedDatabaseId,omitempty"` + RestorePointInTime *string `json:"restorePointInTime,omitempty"` + ResumedDate *string `json:"resumedDate,omitempty"` + SampleName *SampleName `json:"sampleName,omitempty"` + SecondaryType *SecondaryType `json:"secondaryType,omitempty"` + SourceDatabaseDeletionDate *string `json:"sourceDatabaseDeletionDate,omitempty"` + SourceDatabaseId *string `json:"sourceDatabaseId,omitempty"` + Status *DatabaseStatus `json:"status,omitempty"` + UseFreeLimit *bool `json:"useFreeLimit,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} + +func (o *DatabaseUpdateProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseUpdateProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *DatabaseUpdateProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseUpdateProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} + +func (o *DatabaseUpdateProperties) GetPausedDateAsTime() (*time.Time, error) { + if o.PausedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PausedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseUpdateProperties) SetPausedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PausedDate = &formatted +} + +func (o *DatabaseUpdateProperties) GetRestorePointInTimeAsTime() (*time.Time, error) { + if o.RestorePointInTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointInTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseUpdateProperties) SetRestorePointInTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointInTime = &formatted +} + +func (o *DatabaseUpdateProperties) GetResumedDateAsTime() (*time.Time, error) { + if o.ResumedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ResumedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseUpdateProperties) SetResumedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ResumedDate = &formatted +} + +func (o *DatabaseUpdateProperties) GetSourceDatabaseDeletionDateAsTime() (*time.Time, error) { + if o.SourceDatabaseDeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SourceDatabaseDeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseUpdateProperties) SetSourceDatabaseDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SourceDatabaseDeletionDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databases/model_exportdatabasedefinition.go b/resource-manager/sql/2023-08-01/databases/model_exportdatabasedefinition.go new file mode 100644 index 00000000000..13ef51ae1e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_exportdatabasedefinition.go @@ -0,0 +1,14 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDatabaseDefinition struct { + AdministratorLogin string `json:"administratorLogin"` + AdministratorLoginPassword string `json:"administratorLoginPassword"` + AuthenticationType *string `json:"authenticationType,omitempty"` + NetworkIsolation *NetworkIsolationSettings `json:"networkIsolation,omitempty"` + StorageKey string `json:"storageKey"` + StorageKeyType StorageKeyType `json:"storageKeyType"` + StorageUri string `json:"storageUri"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_importexistingdatabasedefinition.go b/resource-manager/sql/2023-08-01/databases/model_importexistingdatabasedefinition.go new file mode 100644 index 00000000000..f4f6749faab --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_importexistingdatabasedefinition.go @@ -0,0 +1,14 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExistingDatabaseDefinition struct { + AdministratorLogin string `json:"administratorLogin"` + AdministratorLoginPassword string `json:"administratorLoginPassword"` + AuthenticationType *string `json:"authenticationType,omitempty"` + NetworkIsolation *NetworkIsolationSettings `json:"networkIsolation,omitempty"` + StorageKey string `json:"storageKey"` + StorageKeyType StorageKeyType `json:"storageKeyType"` + StorageUri string `json:"storageUri"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_importexportoperationresult.go b/resource-manager/sql/2023-08-01/databases/model_importexportoperationresult.go new file mode 100644 index 00000000000..a0502e0f547 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_importexportoperationresult.go @@ -0,0 +1,11 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImportExportOperationResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_importexportoperationresultproperties.go b/resource-manager/sql/2023-08-01/databases/model_importexportoperationresultproperties.go new file mode 100644 index 00000000000..ec3ac778684 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_importexportoperationresultproperties.go @@ -0,0 +1,17 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportOperationResultProperties struct { + BlobUri *string `json:"blobUri,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + LastModifiedTime *string `json:"lastModifiedTime,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnectionRequestStatus `json:"privateEndpointConnections,omitempty"` + QueuedTime *string `json:"queuedTime,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestType *string `json:"requestType,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_networkisolationsettings.go b/resource-manager/sql/2023-08-01/databases/model_networkisolationsettings.go new file mode 100644 index 00000000000..ee040779a2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_networkisolationsettings.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkIsolationSettings struct { + SqlServerResourceId *string `json:"sqlServerResourceId,omitempty"` + StorageAccountResourceId *string `json:"storageAccountResourceId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_privateendpointconnectionrequeststatus.go b/resource-manager/sql/2023-08-01/databases/model_privateendpointconnectionrequeststatus.go new file mode 100644 index 00000000000..3ab1cbadb08 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_privateendpointconnectionrequeststatus.go @@ -0,0 +1,10 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionRequestStatus struct { + PrivateEndpointConnectionName *string `json:"privateEndpointConnectionName,omitempty"` + PrivateLinkServiceId *string `json:"privateLinkServiceId,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_resourcemovedefinition.go b/resource-manager/sql/2023-08-01/databases/model_resourcemovedefinition.go new file mode 100644 index 00000000000..a55554d3878 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_resourcemovedefinition.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceMoveDefinition struct { + Id string `json:"id"` +} diff --git a/resource-manager/sql/2023-08-01/databases/model_sku.go b/resource-manager/sql/2023-08-01/databases/model_sku.go new file mode 100644 index 00000000000..ed100829bd4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/model_sku.go @@ -0,0 +1,12 @@ +package databases + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databases/predicates.go b/resource-manager/sql/2023-08-01/databases/predicates.go new file mode 100644 index 00000000000..4f005cd2158 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/predicates.go @@ -0,0 +1,42 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseOperationPredicate struct { + Id *string + Kind *string + Location *string + ManagedBy *string + Name *string + Type *string +} + +func (p DatabaseOperationPredicate) Matches(input Database) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + 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/sql/2023-08-01/databases/version.go b/resource-manager/sql/2023-08-01/databases/version.go new file mode 100644 index 00000000000..b3c80f941f2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databases/version.go @@ -0,0 +1,10 @@ +package databases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseschemas/README.md b/resource-manager/sql/2023-08-01/databaseschemas/README.md new file mode 100644 index 00000000000..a74ad9a2db1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseschemas` Documentation + +The `databaseschemas` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseschemas" +``` + + +### Client Initialization + +```go +client := databaseschemas.NewDatabaseSchemasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSchemasClient.Get` + +```go +ctx := context.TODO() +id := databaseschemas.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName") + +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: `DatabaseSchemasClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, databaseschemas.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, databaseschemas.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databaseschemas/client.go b/resource-manager/sql/2023-08-01/databaseschemas/client.go new file mode 100644 index 00000000000..9b66a11cbc9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/client.go @@ -0,0 +1,26 @@ +package databaseschemas + +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 DatabaseSchemasClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSchemasClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSchemasClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseschemas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSchemasClient: %+v", err) + } + + return &DatabaseSchemasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseschemas/id_schema.go b/resource-manager/sql/2023-08-01/databaseschemas/id_schema.go new file mode 100644 index 00000000000..9a8c3b2738c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/id_schema.go @@ -0,0 +1,148 @@ +package databaseschemas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SchemaId{}) +} + +var _ resourceids.ResourceId = &SchemaId{} + +// SchemaId is a struct representing the Resource ID for a Schema +type SchemaId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string +} + +// NewSchemaID returns a new SchemaId struct +func NewSchemaID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string) SchemaId { + return SchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + } +} + +// ParseSchemaID parses 'input' into a SchemaId +func ParseSchemaID(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaIDInsensitively parses 'input' case-insensitively into a SchemaId +// note: this method should only be used for API response data and not user input +func ParseSchemaIDInsensitively(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + return nil +} + +// ValidateSchemaID checks that 'input' can be parsed as a Schema ID +func ValidateSchemaID(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 := ParseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema ID +func (id SchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema ID +func (id SchemaId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + } +} + +// String returns a human-readable description of this Schema ID +func (id SchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + } + return fmt.Sprintf("Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databaseschemas/id_schema_test.go b/resource-manager/sql/2023-08-01/databaseschemas/id_schema_test.go new file mode 100644 index 00000000000..7867ca37e94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/id_schema_test.go @@ -0,0 +1,372 @@ +package databaseschemas + +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 = &SchemaId{} + +func TestNewSchemaID(t *testing.T) { + id := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestParseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestSegmentsForSchemaId(t *testing.T) { + segments := SchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaId 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/sql/2023-08-01/databaseschemas/method_get.go b/resource-manager/sql/2023-08-01/databaseschemas/method_get.go new file mode 100644 index 00000000000..27c1d7d7b3d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/method_get.go @@ -0,0 +1,53 @@ +package databaseschemas + +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 *Resource +} + +// Get ... +func (c DatabaseSchemasClient) Get(ctx context.Context, id SchemaId) (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 Resource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databaseschemas/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databaseschemas/method_listbydatabase.go new file mode 100644 index 00000000000..e3ff05c63bb --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/method_listbydatabase.go @@ -0,0 +1,135 @@ +package databaseschemas + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type ListByDatabaseOperationOptions struct { + Filter *string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseSchemasClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/schemas", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseSchemasClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSchemasClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions, predicate ResourceOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databaseschemas/model_resource.go b/resource-manager/sql/2023-08-01/databaseschemas/model_resource.go new file mode 100644 index 00000000000..5ca0db99241 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/model_resource.go @@ -0,0 +1,10 @@ +package databaseschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseschemas/predicates.go b/resource-manager/sql/2023-08-01/databaseschemas/predicates.go new file mode 100644 index 00000000000..641b6fac20c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/predicates.go @@ -0,0 +1,27 @@ +package databaseschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/sql/2023-08-01/databaseschemas/version.go b/resource-manager/sql/2023-08-01/databaseschemas/version.go new file mode 100644 index 00000000000..d6fc4a13036 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseschemas/version.go @@ -0,0 +1,10 @@ +package databaseschemas + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseschemas/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/README.md b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/README.md new file mode 100644 index 00000000000..7b7e0152d59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesecurityalertpolicies` Documentation + +The `databasesecurityalertpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := databasesecurityalertpolicies.NewDatabaseSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databasesecurityalertpolicies.DatabaseSecurityAlertPolicy{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseSecurityAlertPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DatabaseSecurityAlertPoliciesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/client.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/client.go new file mode 100644 index 00000000000..5dc5a476ce2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/client.go @@ -0,0 +1,26 @@ +package databasesecurityalertpolicies + +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 DatabaseSecurityAlertPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSecurityAlertPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSecurityAlertPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesecurityalertpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSecurityAlertPoliciesClient: %+v", err) + } + + return &DatabaseSecurityAlertPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/constants.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/constants.go new file mode 100644 index 00000000000..e781f48bb46 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/constants.go @@ -0,0 +1,51 @@ +package databasesecurityalertpolicies + +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 SecurityAlertsPolicyState string + +const ( + SecurityAlertsPolicyStateDisabled SecurityAlertsPolicyState = "Disabled" + SecurityAlertsPolicyStateEnabled SecurityAlertsPolicyState = "Enabled" +) + +func PossibleValuesForSecurityAlertsPolicyState() []string { + return []string{ + string(SecurityAlertsPolicyStateDisabled), + string(SecurityAlertsPolicyStateEnabled), + } +} + +func (s *SecurityAlertsPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityAlertsPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityAlertsPolicyState(input string) (*SecurityAlertsPolicyState, error) { + vals := map[string]SecurityAlertsPolicyState{ + "disabled": SecurityAlertsPolicyStateDisabled, + "enabled": SecurityAlertsPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityAlertsPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..0752c0334f8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_createorupdate.go @@ -0,0 +1,60 @@ +package databasesecurityalertpolicies + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSecurityAlertPolicy +} + +// CreateOrUpdate ... +func (c DatabaseSecurityAlertPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseSecurityAlertPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 DatabaseSecurityAlertPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_get.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..ad2feedc3e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_get.go @@ -0,0 +1,55 @@ +package databasesecurityalertpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSecurityAlertPolicy +} + +// Get ... +func (c DatabaseSecurityAlertPoliciesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 DatabaseSecurityAlertPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..8a840d331aa --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databasesecurityalertpolicies + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseSecurityAlertPolicy +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseSecurityAlertPolicy +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseSecurityAlertPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/securityAlertPolicies", 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 *[]DatabaseSecurityAlertPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseSecurityAlertPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseSecurityAlertPolicyOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSecurityAlertPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseSecurityAlertPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseSecurityAlertPolicy, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go new file mode 100644 index 00000000000..c6c9fd92146 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go @@ -0,0 +1,16 @@ +package databasesecurityalertpolicies + +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 DatabaseSecurityAlertPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityAlertsPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_securityalertspolicyproperties.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_securityalertspolicyproperties.go new file mode 100644 index 00000000000..cd9c06b811b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/model_securityalertspolicyproperties.go @@ -0,0 +1,33 @@ +package databasesecurityalertpolicies + +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 SecurityAlertsPolicyProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + DisabledAlerts *[]string `json:"disabledAlerts,omitempty"` + EmailAccountAdmins *bool `json:"emailAccountAdmins,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State SecurityAlertsPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} + +func (o *SecurityAlertsPolicyProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertsPolicyProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/predicates.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..e1a8e1f4274 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/predicates.go @@ -0,0 +1,27 @@ +package databasesecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSecurityAlertPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseSecurityAlertPolicyOperationPredicate) Matches(input DatabaseSecurityAlertPolicy) 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/sql/2023-08-01/databasesecurityalertpolicies/version.go b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/version.go new file mode 100644 index 00000000000..d102b812b34 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesecurityalertpolicies/version.go @@ -0,0 +1,10 @@ +package databasesecurityalertpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesecurityalertpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/README.md b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/README.md new file mode 100644 index 00000000000..5f2c7b812ae --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines` Documentation + +The `databasesqlvulnerabilityassessmentbaselines` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentbaselines.NewDatabaseSqlVulnerabilityAssessmentBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentBaselinesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databasesqlvulnerabilityassessmentbaselines.DatabaseSqlVulnerabilityAssessmentRuleBaselineListInput{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentBaselinesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DatabaseSqlVulnerabilityAssessmentBaselinesClient.ListBySqlVulnerabilityAssessment` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListBySqlVulnerabilityAssessment(ctx, id)` can be used to do batched pagination +items, err := client.ListBySqlVulnerabilityAssessmentComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/client.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/client.go new file mode 100644 index 00000000000..197aac9464b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/client.go @@ -0,0 +1,26 @@ +package databasesqlvulnerabilityassessmentbaselines + +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 DatabaseSqlVulnerabilityAssessmentBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSqlVulnerabilityAssessmentBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSqlVulnerabilityAssessmentBaselinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesqlvulnerabilityassessmentbaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSqlVulnerabilityAssessmentBaselinesClient: %+v", err) + } + + return &DatabaseSqlVulnerabilityAssessmentBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go new file mode 100644 index 00000000000..aab3068bda5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go @@ -0,0 +1,59 @@ +package databasesqlvulnerabilityassessmentbaselines + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +// CreateOrUpdate ... +func (c DatabaseSqlVulnerabilityAssessmentBaselinesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseSqlVulnerabilityAssessmentRuleBaselineListInput) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/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 DatabaseSqlVulnerabilityAssessmentBaselineSet + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_get.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_get.go new file mode 100644 index 00000000000..f3afb88df0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_get.go @@ -0,0 +1,55 @@ +package databasesqlvulnerabilityassessmentbaselines + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +// Get ... +func (c DatabaseSqlVulnerabilityAssessmentBaselinesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/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 DatabaseSqlVulnerabilityAssessmentBaselineSet + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go new file mode 100644 index 00000000000..6413a42ca96 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go @@ -0,0 +1,106 @@ +package databasesqlvulnerabilityassessmentbaselines + +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 ListBySqlVulnerabilityAssessmentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +type ListBySqlVulnerabilityAssessmentCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +type ListBySqlVulnerabilityAssessmentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySqlVulnerabilityAssessmentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySqlVulnerabilityAssessment ... +func (c DatabaseSqlVulnerabilityAssessmentBaselinesClient) ListBySqlVulnerabilityAssessment(ctx context.Context, id commonids.SqlDatabaseId) (result ListBySqlVulnerabilityAssessmentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySqlVulnerabilityAssessmentCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines", 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 *[]DatabaseSqlVulnerabilityAssessmentBaselineSet `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySqlVulnerabilityAssessmentComplete retrieves all the results into a single object +func (c DatabaseSqlVulnerabilityAssessmentBaselinesClient) ListBySqlVulnerabilityAssessmentComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListBySqlVulnerabilityAssessmentCompleteResult, error) { + return c.ListBySqlVulnerabilityAssessmentCompleteMatchingPredicate(ctx, id, DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate{}) +} + +// ListBySqlVulnerabilityAssessmentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSqlVulnerabilityAssessmentBaselinesClient) ListBySqlVulnerabilityAssessmentCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate) (result ListBySqlVulnerabilityAssessmentCompleteResult, err error) { + items := make([]DatabaseSqlVulnerabilityAssessmentBaselineSet, 0) + + resp, err := c.ListBySqlVulnerabilityAssessment(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySqlVulnerabilityAssessmentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go new file mode 100644 index 00000000000..73718f1671b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentbaselines + +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 DatabaseSqlVulnerabilityAssessmentBaselineSet struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentBaselineSetProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go new file mode 100644 index 00000000000..853ddd86f71 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go @@ -0,0 +1,8 @@ +package databasesqlvulnerabilityassessmentbaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentBaselineSetProperties struct { + Results map[string][][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go new file mode 100644 index 00000000000..7a03b91e57d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentbaselines + +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 DatabaseSqlVulnerabilityAssessmentRuleBaselineListInput struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentRuleBaselineListInputProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go new file mode 100644 index 00000000000..3983c1ac77a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go @@ -0,0 +1,9 @@ +package databasesqlvulnerabilityassessmentbaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineListInputProperties struct { + LatestScan bool `json:"latestScan"` + Results map[string][][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/predicates.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/predicates.go new file mode 100644 index 00000000000..0ea25284814 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/predicates.go @@ -0,0 +1,27 @@ +package databasesqlvulnerabilityassessmentbaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate) Matches(input DatabaseSqlVulnerabilityAssessmentBaselineSet) 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/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/version.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/version.go new file mode 100644 index 00000000000..65a73f9f9a8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentbaselines/version.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentbaselines + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentbaselines/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/client.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/client.go new file mode 100644 index 00000000000..505fdee6215 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/client.go @@ -0,0 +1,26 @@ +package databasesqlvulnerabilityassessmentexecutescan + +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 DatabaseSqlVulnerabilityAssessmentExecuteScanClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSqlVulnerabilityAssessmentExecuteScanClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSqlVulnerabilityAssessmentExecuteScanClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesqlvulnerabilityassessmentexecutescan", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSqlVulnerabilityAssessmentExecuteScanClient: %+v", err) + } + + return &DatabaseSqlVulnerabilityAssessmentExecuteScanClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/method_execute.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/method_execute.go new file mode 100644 index 00000000000..cfcea89c185 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/method_execute.go @@ -0,0 +1,71 @@ +package databasesqlvulnerabilityassessmentexecutescan + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExecuteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Execute ... +func (c DatabaseSqlVulnerabilityAssessmentExecuteScanClient) Execute(ctx context.Context, id commonids.SqlDatabaseId) (result ExecuteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/initiateScan", 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 +} + +// ExecuteThenPoll performs Execute then polls until it's completed +func (c DatabaseSqlVulnerabilityAssessmentExecuteScanClient) ExecuteThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.Execute(ctx, id) + if err != nil { + return fmt.Errorf("performing Execute: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Execute: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/version.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/version.go new file mode 100644 index 00000000000..b2bdcabb322 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentexecutescan/version.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentexecutescan + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentexecutescan/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/README.md b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/README.md new file mode 100644 index 00000000000..89fb977e670 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines` Documentation + +The `databasesqlvulnerabilityassessmentrulebaselines` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentrulebaselines.NewDatabaseSqlVulnerabilityAssessmentRuleBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentrulebaselines.NewBaselineRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId") + +payload := databasesqlvulnerabilityassessmentrulebaselines.DatabaseSqlVulnerabilityAssessmentRuleBaselineInput{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient.Delete` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentrulebaselines.NewBaselineRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient.Get` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentrulebaselines.NewBaselineRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId") + +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: `DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient.ListByBaseline` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByBaseline(ctx, id)` can be used to do batched pagination +items, err := client.ListByBaselineComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/client.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/client.go new file mode 100644 index 00000000000..617524c8b4b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/client.go @@ -0,0 +1,26 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSqlVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesqlvulnerabilityassessmentrulebaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient: %+v", err) + } + + return &DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go new file mode 100644 index 00000000000..346c90617cc --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go @@ -0,0 +1,152 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BaselineRuleId{}) +} + +var _ resourceids.ResourceId = &BaselineRuleId{} + +// BaselineRuleId is a struct representing the Resource ID for a Baseline Rule +type BaselineRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + RuleId string +} + +// NewBaselineRuleID returns a new BaselineRuleId struct +func NewBaselineRuleID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, ruleId string) BaselineRuleId { + return BaselineRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + RuleId: ruleId, + } +} + +// ParseBaselineRuleID parses 'input' into a BaselineRuleId +func ParseBaselineRuleID(input string) (*BaselineRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBaselineRuleIDInsensitively parses 'input' case-insensitively into a BaselineRuleId +// note: this method should only be used for API response data and not user input +func ParseBaselineRuleIDInsensitively(input string) (*BaselineRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BaselineRuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + return nil +} + +// ValidateBaselineRuleID checks that 'input' can be parsed as a Baseline Rule ID +func ValidateBaselineRuleID(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 := ParseBaselineRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Baseline Rule ID +func (id BaselineRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/sqlVulnerabilityAssessments/default/baselines/default/rules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.RuleId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Baseline Rule ID +func (id BaselineRuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.StaticSegment("baselineName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleId"), + } +} + +// String returns a human-readable description of this Baseline Rule ID +func (id BaselineRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Rule: %q", id.RuleId), + } + return fmt.Sprintf("Baseline Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go new file mode 100644 index 00000000000..e0ef184378b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go @@ -0,0 +1,432 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 = &BaselineRuleId{} + +func TestNewBaselineRuleID(t *testing.T) { + id := NewBaselineRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.RuleId != "ruleId" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleId") + } +} + +func TestFormatBaselineRuleID(t *testing.T) { + actual := NewBaselineRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBaselineRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId", + Expected: &BaselineRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RuleId: "ruleId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestParseBaselineRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId", + Expected: &BaselineRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RuleId: "ruleId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiD", + Expected: &BaselineRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + RuleId: "rUlEiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestSegmentsForBaselineRuleId(t *testing.T) { + segments := BaselineRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BaselineRuleId 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/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go new file mode 100644 index 00000000000..8d6e076da5c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go @@ -0,0 +1,57 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +// CreateOrUpdate ... +func (c DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdate(ctx context.Context, id BaselineRuleId, input DatabaseSqlVulnerabilityAssessmentRuleBaselineInput) (result CreateOrUpdateOperationResponse, 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 DatabaseSqlVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go new file mode 100644 index 00000000000..2e6e94f412e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go @@ -0,0 +1,47 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient) Delete(ctx context.Context, id BaselineRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_get.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_get.go new file mode 100644 index 00000000000..bb85540e3c6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_get.go @@ -0,0 +1,53 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 *DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +// Get ... +func (c DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient) Get(ctx context.Context, id BaselineRuleId) (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 DatabaseSqlVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go new file mode 100644 index 00000000000..d1f64e0e286 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go @@ -0,0 +1,106 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 ListByBaselineOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +type ListByBaselineCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +type ListByBaselineCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByBaselineCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByBaseline ... +func (c DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient) ListByBaseline(ctx context.Context, id commonids.SqlDatabaseId) (result ListByBaselineOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByBaselineCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/default/rules", 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 *[]DatabaseSqlVulnerabilityAssessmentRuleBaseline `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByBaselineComplete retrieves all the results into a single object +func (c DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient) ListByBaselineComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByBaselineCompleteResult, error) { + return c.ListByBaselineCompleteMatchingPredicate(ctx, id, DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate{}) +} + +// ListByBaselineCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSqlVulnerabilityAssessmentRuleBaselinesClient) ListByBaselineCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate) (result ListByBaselineCompleteResult, err error) { + items := make([]DatabaseSqlVulnerabilityAssessmentRuleBaseline, 0) + + resp, err := c.ListByBaseline(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByBaselineCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..997f10b0ebe --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 DatabaseSqlVulnerabilityAssessmentRuleBaseline struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentRuleBaselineProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go new file mode 100644 index 00000000000..c3a8ab509f7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +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 DatabaseSqlVulnerabilityAssessmentRuleBaselineInput struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentRuleBaselineInputProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go new file mode 100644 index 00000000000..3b07be7f510 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go @@ -0,0 +1,9 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineInputProperties struct { + LatestScan bool `json:"latestScan"` + Results [][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..cbcc880ef03 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go @@ -0,0 +1,8 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineProperties struct { + Results [][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/predicates.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/predicates.go new file mode 100644 index 00000000000..50353e789a0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/predicates.go @@ -0,0 +1,27 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate) Matches(input DatabaseSqlVulnerabilityAssessmentRuleBaseline) 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/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/version.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/version.go new file mode 100644 index 00000000000..e9ba07a1133 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentrulebaselines/version.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentrulebaselines/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/README.md b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/README.md new file mode 100644 index 00000000000..1d68583ac91 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult` Documentation + +The `databasesqlvulnerabilityassessmentscanresult` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentscanresult.NewDatabaseSqlVulnerabilityAssessmentScanResultClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentScanResultClient.Get` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentscanresult.NewScanScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId", "scanResultId") + +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: `DatabaseSqlVulnerabilityAssessmentScanResultClient.ListByScan` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentscanresult.NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + +// alternatively `client.ListByScan(ctx, id)` can be used to do batched pagination +items, err := client.ListByScanComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/client.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/client.go new file mode 100644 index 00000000000..5b2f1d85b93 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/client.go @@ -0,0 +1,26 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 DatabaseSqlVulnerabilityAssessmentScanResultClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSqlVulnerabilityAssessmentScanResultClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSqlVulnerabilityAssessmentScanResultClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesqlvulnerabilityassessmentscanresult", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSqlVulnerabilityAssessmentScanResultClient: %+v", err) + } + + return &DatabaseSqlVulnerabilityAssessmentScanResultClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/constants.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/constants.go new file mode 100644 index 00000000000..df56b3c1891 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/constants.go @@ -0,0 +1,151 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 RuleSeverity string + +const ( + RuleSeverityHigh RuleSeverity = "High" + RuleSeverityInformational RuleSeverity = "Informational" + RuleSeverityLow RuleSeverity = "Low" + RuleSeverityMedium RuleSeverity = "Medium" + RuleSeverityObsolete RuleSeverity = "Obsolete" +) + +func PossibleValuesForRuleSeverity() []string { + return []string{ + string(RuleSeverityHigh), + string(RuleSeverityInformational), + string(RuleSeverityLow), + string(RuleSeverityMedium), + string(RuleSeverityObsolete), + } +} + +func (s *RuleSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleSeverity(input string) (*RuleSeverity, error) { + vals := map[string]RuleSeverity{ + "high": RuleSeverityHigh, + "informational": RuleSeverityInformational, + "low": RuleSeverityLow, + "medium": RuleSeverityMedium, + "obsolete": RuleSeverityObsolete, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleSeverity(input) + return &out, nil +} + +type RuleStatus string + +const ( + RuleStatusFinding RuleStatus = "Finding" + RuleStatusInternalError RuleStatus = "InternalError" + RuleStatusNonFinding RuleStatus = "NonFinding" +) + +func PossibleValuesForRuleStatus() []string { + return []string{ + string(RuleStatusFinding), + string(RuleStatusInternalError), + string(RuleStatusNonFinding), + } +} + +func (s *RuleStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleStatus(input string) (*RuleStatus, error) { + vals := map[string]RuleStatus{ + "finding": RuleStatusFinding, + "internalerror": RuleStatusInternalError, + "nonfinding": RuleStatusNonFinding, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleStatus(input) + return &out, nil +} + +type RuleType string + +const ( + RuleTypeBaselineExpected RuleType = "BaselineExpected" + RuleTypeBinary RuleType = "Binary" + RuleTypeNegativeList RuleType = "NegativeList" + RuleTypePositiveList RuleType = "PositiveList" +) + +func PossibleValuesForRuleType() []string { + return []string{ + string(RuleTypeBaselineExpected), + string(RuleTypeBinary), + string(RuleTypeNegativeList), + string(RuleTypePositiveList), + } +} + +func (s *RuleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleType(input string) (*RuleType, error) { + vals := map[string]RuleType{ + "baselineexpected": RuleTypeBaselineExpected, + "binary": RuleTypeBinary, + "negativelist": RuleTypeNegativeList, + "positivelist": RuleTypePositiveList, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go new file mode 100644 index 00000000000..704f6258f99 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go @@ -0,0 +1,159 @@ +package databasesqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScanScanResultId{}) +} + +var _ resourceids.ResourceId = &ScanScanResultId{} + +// ScanScanResultId is a struct representing the Resource ID for a Scan Scan Result +type ScanScanResultId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + ScanId string + ScanResultId string +} + +// NewScanScanResultID returns a new ScanScanResultId struct +func NewScanScanResultID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, scanId string, scanResultId string) ScanScanResultId { + return ScanScanResultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + ScanId: scanId, + ScanResultId: scanResultId, + } +} + +// ParseScanScanResultID parses 'input' into a ScanScanResultId +func ParseScanScanResultID(input string) (*ScanScanResultId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanScanResultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanScanResultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanScanResultIDInsensitively parses 'input' case-insensitively into a ScanScanResultId +// note: this method should only be used for API response data and not user input +func ParseScanScanResultIDInsensitively(input string) (*ScanScanResultId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanScanResultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanScanResultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanScanResultId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + if id.ScanResultId, ok = input.Parsed["scanResultId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanResultId", input) + } + + return nil +} + +// ValidateScanScanResultID checks that 'input' can be parsed as a Scan Scan Result ID +func ValidateScanScanResultID(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 := ParseScanScanResultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan Scan Result ID +func (id ScanScanResultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/sqlVulnerabilityAssessments/default/scans/%s/scanResults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.ScanId, id.ScanResultId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan Scan Result ID +func (id ScanScanResultId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + resourceids.StaticSegment("staticScanResults", "scanResults", "scanResults"), + resourceids.UserSpecifiedSegment("scanResultId", "scanResultId"), + } +} + +// String returns a human-readable description of this Scan Scan Result ID +func (id ScanScanResultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Scan: %q", id.ScanId), + fmt.Sprintf("Scan Result: %q", id.ScanResultId), + } + return fmt.Sprintf("Scan Scan Result (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go new file mode 100644 index 00000000000..3202a77ccab --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go @@ -0,0 +1,447 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 = &ScanScanResultId{} + +func TestNewScanScanResultID(t *testing.T) { + id := NewScanScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId", "scanResultId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } + + if id.ScanResultId != "scanResultId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanResultId'", id.ScanResultId, "scanResultId") + } +} + +func TestFormatScanScanResultID(t *testing.T) { + actual := NewScanScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId", "scanResultId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanScanResultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanScanResultId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId", + Expected: &ScanScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + ScanResultId: "scanResultId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanScanResultID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + if actual.ScanResultId != v.Expected.ScanResultId { + t.Fatalf("Expected %q but got %q for ScanResultId", v.Expected.ScanResultId, actual.ScanResultId) + } + + } +} + +func TestParseScanScanResultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanScanResultId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/sCaNrEsUlTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId", + Expected: &ScanScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + ScanResultId: "scanResultId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/sCaNrEsUlTs/sCaNrEsUlTiD", + Expected: &ScanScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + ScanId: "sCaNiD", + ScanResultId: "sCaNrEsUlTiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/sCaNrEsUlTs/sCaNrEsUlTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanScanResultIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + if actual.ScanResultId != v.Expected.ScanResultId { + t.Fatalf("Expected %q but got %q for ScanResultId", v.Expected.ScanResultId, actual.ScanResultId) + } + + } +} + +func TestSegmentsForScanScanResultId(t *testing.T) { + segments := ScanScanResultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanScanResultId 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/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go new file mode 100644 index 00000000000..b2db0167fe7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go @@ -0,0 +1,150 @@ +package databasesqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}) +} + +var _ resourceids.ResourceId = &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + +// SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId is a struct representing the Resource ID for a Sql Vulnerability Assessment Vulnerability Assessment Scan +type SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + ScanId string +} + +// NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID returns a new SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId struct +func NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, scanId string) SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId { + return SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + ScanId: scanId, + } +} + +// ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID parses 'input' into a SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId +func ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(input string) (*SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively parses 'input' case-insensitively into a SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId +// note: this method should only be used for API response data and not user input +func ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(input string) (*SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID checks that 'input' can be parsed as a Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func ValidateSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(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 := ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func (id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/sqlVulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func (id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + } +} + +// String returns a human-readable description of this Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func (id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Sql Vulnerability Assessment Vulnerability Assessment Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..565b42cae40 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go @@ -0,0 +1,402 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 = &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + +func TestNewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + id := NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } +} + +func TestFormatSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + ScanId: "sCaNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForSqlVulnerabilityAssessmentVulnerabilityAssessmentScanId(t *testing.T) { + segments := SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId 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/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_get.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_get.go new file mode 100644 index 00000000000..b51d6882b18 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_get.go @@ -0,0 +1,53 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 *SqlVulnerabilityAssessmentScanResults +} + +// Get ... +func (c DatabaseSqlVulnerabilityAssessmentScanResultClient) Get(ctx context.Context, id ScanScanResultId) (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 SqlVulnerabilityAssessmentScanResults + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go new file mode 100644 index 00000000000..731625dcfbe --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go @@ -0,0 +1,105 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 ListByScanOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVulnerabilityAssessmentScanResults +} + +type ListByScanCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVulnerabilityAssessmentScanResults +} + +type ListByScanCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByScanCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByScan ... +func (c DatabaseSqlVulnerabilityAssessmentScanResultClient) ListByScan(ctx context.Context, id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) (result ListByScanOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByScanCustomPager{}, + Path: fmt.Sprintf("%s/scanResults", 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 *[]SqlVulnerabilityAssessmentScanResults `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByScanComplete retrieves all the results into a single object +func (c DatabaseSqlVulnerabilityAssessmentScanResultClient) ListByScanComplete(ctx context.Context, id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) (ListByScanCompleteResult, error) { + return c.ListByScanCompleteMatchingPredicate(ctx, id, SqlVulnerabilityAssessmentScanResultsOperationPredicate{}) +} + +// ListByScanCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSqlVulnerabilityAssessmentScanResultClient) ListByScanCompleteMatchingPredicate(ctx context.Context, id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId, predicate SqlVulnerabilityAssessmentScanResultsOperationPredicate) (result ListByScanCompleteResult, err error) { + items := make([]SqlVulnerabilityAssessmentScanResults, 0) + + resp, err := c.ListByScan(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByScanCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baseline.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baseline.go new file mode 100644 index 00000000000..571516e9c7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baseline.go @@ -0,0 +1,27 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 Baseline struct { + ExpectedResults *[][]string `json:"expectedResults,omitempty"` + UpdatedTime *string `json:"updatedTime,omitempty"` +} + +func (o *Baseline) GetUpdatedTimeAsTime() (*time.Time, error) { + if o.UpdatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *Baseline) SetUpdatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go new file mode 100644 index 00000000000..d2aeb9faaf0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go @@ -0,0 +1,11 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaselineAdjustedResult struct { + Baseline *Baseline `json:"baseline,omitempty"` + ResultsNotInBaseline *[][]string `json:"resultsNotInBaseline,omitempty"` + ResultsOnlyInBaseline *[][]string `json:"resultsOnlyInBaseline,omitempty"` + Status *RuleStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go new file mode 100644 index 00000000000..4c46da7bc05 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go @@ -0,0 +1,9 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenchmarkReference struct { + Benchmark *string `json:"benchmark,omitempty"` + Reference *string `json:"reference,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go new file mode 100644 index 00000000000..67feee6a500 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryCheck struct { + ColumnNames *[]string `json:"columnNames,omitempty"` + ExpectedResult *[][]string `json:"expectedResult,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_remediation.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_remediation.go new file mode 100644 index 00000000000..07b0861ae01 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_remediation.go @@ -0,0 +1,11 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Remediation struct { + Automated *bool `json:"automated,omitempty"` + Description *string `json:"description,omitempty"` + PortalLink *string `json:"portalLink,omitempty"` + Scripts *[]string `json:"scripts,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go new file mode 100644 index 00000000000..3439b05f585 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go @@ -0,0 +1,15 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanResultProperties struct { + BaselineAdjustedResult *BaselineAdjustedResult `json:"baselineAdjustedResult,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + IsTrimmed *bool `json:"isTrimmed,omitempty"` + QueryResults *[][]string `json:"queryResults,omitempty"` + Remediation *Remediation `json:"remediation,omitempty"` + RuleId *string `json:"ruleId,omitempty"` + RuleMetadata *VaRule `json:"ruleMetadata,omitempty"` + Status *RuleStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go new file mode 100644 index 00000000000..d41adfac8e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentscanresult + +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 SqlVulnerabilityAssessmentScanResults struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlVulnerabilityAssessmentScanResultProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_varule.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_varule.go new file mode 100644 index 00000000000..62089686882 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/model_varule.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaRule struct { + BenchmarkReferences *[]BenchmarkReference `json:"benchmarkReferences,omitempty"` + Category *string `json:"category,omitempty"` + Description *string `json:"description,omitempty"` + QueryCheck *QueryCheck `json:"queryCheck,omitempty"` + Rationale *string `json:"rationale,omitempty"` + RuleId *string `json:"ruleId,omitempty"` + RuleType *RuleType `json:"ruleType,omitempty"` + Severity *RuleSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/predicates.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/predicates.go new file mode 100644 index 00000000000..83f835443de --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/predicates.go @@ -0,0 +1,27 @@ +package databasesqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanResultsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlVulnerabilityAssessmentScanResultsOperationPredicate) Matches(input SqlVulnerabilityAssessmentScanResults) 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/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/version.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/version.go new file mode 100644 index 00000000000..cbe56c8761c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscanresult/version.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentscanresult + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentscanresult/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..9f884cb880e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans` Documentation + +The `databasesqlvulnerabilityassessmentscans` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentscans.NewDatabaseSqlVulnerabilityAssessmentScansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentScansClient.Get` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentscans.NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + +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: `DatabaseSqlVulnerabilityAssessmentScansClient.ListBySqlVulnerabilityAssessments` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListBySqlVulnerabilityAssessments(ctx, id)` can be used to do batched pagination +items, err := client.ListBySqlVulnerabilityAssessmentsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..d170cc753df --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/client.go @@ -0,0 +1,26 @@ +package databasesqlvulnerabilityassessmentscans + +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 DatabaseSqlVulnerabilityAssessmentScansClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSqlVulnerabilityAssessmentScansClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSqlVulnerabilityAssessmentScansClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesqlvulnerabilityassessmentscans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSqlVulnerabilityAssessmentScansClient: %+v", err) + } + + return &DatabaseSqlVulnerabilityAssessmentScansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..70a73b690ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/constants.go @@ -0,0 +1,98 @@ +package databasesqlvulnerabilityassessmentscans + +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 VulnerabilityAssessmentScanState string + +const ( + VulnerabilityAssessmentScanStateFailed VulnerabilityAssessmentScanState = "Failed" + VulnerabilityAssessmentScanStateFailedToRun VulnerabilityAssessmentScanState = "FailedToRun" + VulnerabilityAssessmentScanStateInProgress VulnerabilityAssessmentScanState = "InProgress" + VulnerabilityAssessmentScanStatePassed VulnerabilityAssessmentScanState = "Passed" +) + +func PossibleValuesForVulnerabilityAssessmentScanState() []string { + return []string{ + string(VulnerabilityAssessmentScanStateFailed), + string(VulnerabilityAssessmentScanStateFailedToRun), + string(VulnerabilityAssessmentScanStateInProgress), + string(VulnerabilityAssessmentScanStatePassed), + } +} + +func (s *VulnerabilityAssessmentScanState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanState(input string) (*VulnerabilityAssessmentScanState, error) { + vals := map[string]VulnerabilityAssessmentScanState{ + "failed": VulnerabilityAssessmentScanStateFailed, + "failedtorun": VulnerabilityAssessmentScanStateFailedToRun, + "inprogress": VulnerabilityAssessmentScanStateInProgress, + "passed": VulnerabilityAssessmentScanStatePassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanState(input) + return &out, nil +} + +type VulnerabilityAssessmentScanTriggerType string + +const ( + VulnerabilityAssessmentScanTriggerTypeOnDemand VulnerabilityAssessmentScanTriggerType = "OnDemand" + VulnerabilityAssessmentScanTriggerTypeRecurring VulnerabilityAssessmentScanTriggerType = "Recurring" +) + +func PossibleValuesForVulnerabilityAssessmentScanTriggerType() []string { + return []string{ + string(VulnerabilityAssessmentScanTriggerTypeOnDemand), + string(VulnerabilityAssessmentScanTriggerTypeRecurring), + } +} + +func (s *VulnerabilityAssessmentScanTriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanTriggerType(input string) (*VulnerabilityAssessmentScanTriggerType, error) { + vals := map[string]VulnerabilityAssessmentScanTriggerType{ + "ondemand": VulnerabilityAssessmentScanTriggerTypeOnDemand, + "recurring": VulnerabilityAssessmentScanTriggerTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanTriggerType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go new file mode 100644 index 00000000000..8428b5aacaa --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go @@ -0,0 +1,150 @@ +package databasesqlvulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}) +} + +var _ resourceids.ResourceId = &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + +// SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId is a struct representing the Resource ID for a Sql Vulnerability Assessment Vulnerability Assessment Scan +type SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + ScanId string +} + +// NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID returns a new SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId struct +func NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, scanId string) SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId { + return SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + ScanId: scanId, + } +} + +// ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID parses 'input' into a SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId +func ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(input string) (*SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively parses 'input' case-insensitively into a SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId +// note: this method should only be used for API response data and not user input +func ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(input string) (*SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID checks that 'input' can be parsed as a Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func ValidateSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(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 := ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func (id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/sqlVulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func (id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + } +} + +// String returns a human-readable description of this Sql Vulnerability Assessment Vulnerability Assessment Scan ID +func (id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Sql Vulnerability Assessment Vulnerability Assessment Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..5d7099cef6f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go @@ -0,0 +1,402 @@ +package databasesqlvulnerabilityassessmentscans + +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 = &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{} + +func TestNewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + id := NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } +} + +func TestFormatSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + ScanId: "sCaNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForSqlVulnerabilityAssessmentVulnerabilityAssessmentScanId(t *testing.T) { + segments := SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId 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/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..52aec5920e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_get.go @@ -0,0 +1,53 @@ +package databasesqlvulnerabilityassessmentscans + +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 *SqlVulnerabilityAssessmentScanRecord +} + +// Get ... +func (c DatabaseSqlVulnerabilityAssessmentScansClient) Get(ctx context.Context, id SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId) (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 SqlVulnerabilityAssessmentScanRecord + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go new file mode 100644 index 00000000000..126311fb464 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go @@ -0,0 +1,106 @@ +package databasesqlvulnerabilityassessmentscans + +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 ListBySqlVulnerabilityAssessmentsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVulnerabilityAssessmentScanRecord +} + +type ListBySqlVulnerabilityAssessmentsCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVulnerabilityAssessmentScanRecord +} + +type ListBySqlVulnerabilityAssessmentsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySqlVulnerabilityAssessmentsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySqlVulnerabilityAssessments ... +func (c DatabaseSqlVulnerabilityAssessmentScansClient) ListBySqlVulnerabilityAssessments(ctx context.Context, id commonids.SqlDatabaseId) (result ListBySqlVulnerabilityAssessmentsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySqlVulnerabilityAssessmentsCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/scans", 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 *[]SqlVulnerabilityAssessmentScanRecord `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySqlVulnerabilityAssessmentsComplete retrieves all the results into a single object +func (c DatabaseSqlVulnerabilityAssessmentScansClient) ListBySqlVulnerabilityAssessmentsComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListBySqlVulnerabilityAssessmentsCompleteResult, error) { + return c.ListBySqlVulnerabilityAssessmentsCompleteMatchingPredicate(ctx, id, SqlVulnerabilityAssessmentScanRecordOperationPredicate{}) +} + +// ListBySqlVulnerabilityAssessmentsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSqlVulnerabilityAssessmentScansClient) ListBySqlVulnerabilityAssessmentsCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate SqlVulnerabilityAssessmentScanRecordOperationPredicate) (result ListBySqlVulnerabilityAssessmentsCompleteResult, err error) { + items := make([]SqlVulnerabilityAssessmentScanRecord, 0) + + resp, err := c.ListBySqlVulnerabilityAssessments(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySqlVulnerabilityAssessmentsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..44a0d371209 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go @@ -0,0 +1,9 @@ +package databasesqlvulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..92ce73f2903 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentscans + +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 SqlVulnerabilityAssessmentScanRecord struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlVulnerabilityAssessmentScanRecordProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..ae8c05c09e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go @@ -0,0 +1,66 @@ +package databasesqlvulnerabilityassessmentscans + +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 SqlVulnerabilityAssessmentScanRecordProperties struct { + Database *string `json:"database,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Errors *[]SqlVulnerabilityAssessmentScanError `json:"errors,omitempty"` + HighSeverityFailedRulesCount *int64 `json:"highSeverityFailedRulesCount,omitempty"` + IsBaselineApplied *bool `json:"isBaselineApplied,omitempty"` + LastScanTime *string `json:"lastScanTime,omitempty"` + LowSeverityFailedRulesCount *int64 `json:"lowSeverityFailedRulesCount,omitempty"` + MediumSeverityFailedRulesCount *int64 `json:"mediumSeverityFailedRulesCount,omitempty"` + ScanId *string `json:"scanId,omitempty"` + Server *string `json:"server,omitempty"` + SqlVersion *string `json:"sqlVersion,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *VulnerabilityAssessmentScanState `json:"state,omitempty"` + TotalFailedRulesCount *int64 `json:"totalFailedRulesCount,omitempty"` + TotalPassedRulesCount *int64 `json:"totalPassedRulesCount,omitempty"` + TotalRulesCount *int64 `json:"totalRulesCount,omitempty"` + TriggerType *VulnerabilityAssessmentScanTriggerType `json:"triggerType,omitempty"` +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) GetLastScanTimeAsTime() (*time.Time, error) { + if o.LastScanTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastScanTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) SetLastScanTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastScanTime = &formatted +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..0d95495f278 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/predicates.go @@ -0,0 +1,27 @@ +package databasesqlvulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanRecordOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlVulnerabilityAssessmentScanRecordOperationPredicate) Matches(input SqlVulnerabilityAssessmentScanRecord) 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/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..97949ce448b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentscans/version.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentscans + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentscans/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/README.md b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/README.md new file mode 100644 index 00000000000..6c398793420 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings` Documentation + +The `databasesqlvulnerabilityassessmentssettings` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentssettings.NewDatabaseSqlVulnerabilityAssessmentsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentsSettingsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DatabaseSqlVulnerabilityAssessmentsSettingsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/client.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/client.go new file mode 100644 index 00000000000..e0602c99331 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/client.go @@ -0,0 +1,26 @@ +package databasesqlvulnerabilityassessmentssettings + +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 DatabaseSqlVulnerabilityAssessmentsSettingsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseSqlVulnerabilityAssessmentsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseSqlVulnerabilityAssessmentsSettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasesqlvulnerabilityassessmentssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseSqlVulnerabilityAssessmentsSettingsClient: %+v", err) + } + + return &DatabaseSqlVulnerabilityAssessmentsSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/constants.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/constants.go new file mode 100644 index 00000000000..a133d380214 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/constants.go @@ -0,0 +1,51 @@ +package databasesqlvulnerabilityassessmentssettings + +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 SqlVulnerabilityAssessmentState string + +const ( + SqlVulnerabilityAssessmentStateDisabled SqlVulnerabilityAssessmentState = "Disabled" + SqlVulnerabilityAssessmentStateEnabled SqlVulnerabilityAssessmentState = "Enabled" +) + +func PossibleValuesForSqlVulnerabilityAssessmentState() []string { + return []string{ + string(SqlVulnerabilityAssessmentStateDisabled), + string(SqlVulnerabilityAssessmentStateEnabled), + } +} + +func (s *SqlVulnerabilityAssessmentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlVulnerabilityAssessmentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSqlVulnerabilityAssessmentState(input string) (*SqlVulnerabilityAssessmentState, error) { + vals := map[string]SqlVulnerabilityAssessmentState{ + "disabled": SqlVulnerabilityAssessmentStateDisabled, + "enabled": SqlVulnerabilityAssessmentStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SqlVulnerabilityAssessmentState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_get.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_get.go new file mode 100644 index 00000000000..16e3cee1c42 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_get.go @@ -0,0 +1,55 @@ +package databasesqlvulnerabilityassessmentssettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlVulnerabilityAssessment +} + +// Get ... +func (c DatabaseSqlVulnerabilityAssessmentsSettingsClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/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 SqlVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go new file mode 100644 index 00000000000..3fb4122366d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databasesqlvulnerabilityassessmentssettings + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVulnerabilityAssessment +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVulnerabilityAssessment +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseSqlVulnerabilityAssessmentsSettingsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments", 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 *[]SqlVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseSqlVulnerabilityAssessmentsSettingsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, SqlVulnerabilityAssessmentOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseSqlVulnerabilityAssessmentsSettingsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate SqlVulnerabilityAssessmentOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]SqlVulnerabilityAssessment, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go new file mode 100644 index 00000000000..bcd1d00e9d2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go @@ -0,0 +1,16 @@ +package databasesqlvulnerabilityassessmentssettings + +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 SqlVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlVulnerabilityAssessmentPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go new file mode 100644 index 00000000000..27487940860 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go @@ -0,0 +1,8 @@ +package databasesqlvulnerabilityassessmentssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentPolicyProperties struct { + State *SqlVulnerabilityAssessmentState `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/predicates.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/predicates.go new file mode 100644 index 00000000000..cf36e70c15a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/predicates.go @@ -0,0 +1,27 @@ +package databasesqlvulnerabilityassessmentssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlVulnerabilityAssessmentOperationPredicate) Matches(input SqlVulnerabilityAssessment) 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/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/version.go b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/version.go new file mode 100644 index 00000000000..07b3455dd9c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasesqlvulnerabilityassessmentssettings/version.go @@ -0,0 +1,10 @@ +package databasesqlvulnerabilityassessmentssettings + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentssettings/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasetables/README.md b/resource-manager/sql/2023-08-01/databasetables/README.md new file mode 100644 index 00000000000..ae4253b5d49 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasetables` Documentation + +The `databasetables` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasetables" +``` + + +### Client Initialization + +```go +client := databasetables.NewDatabaseTablesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseTablesClient.Get` + +```go +ctx := context.TODO() +id := databasetables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName") + +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: `DatabaseTablesClient.ListBySchema` + +```go +ctx := context.TODO() +id := databasetables.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName") + +// alternatively `client.ListBySchema(ctx, id, databasetables.DefaultListBySchemaOperationOptions())` can be used to do batched pagination +items, err := client.ListBySchemaComplete(ctx, id, databasetables.DefaultListBySchemaOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasetables/client.go b/resource-manager/sql/2023-08-01/databasetables/client.go new file mode 100644 index 00000000000..3e10e7dcbee --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/client.go @@ -0,0 +1,26 @@ +package databasetables + +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 DatabaseTablesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseTablesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseTablesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasetables", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseTablesClient: %+v", err) + } + + return &DatabaseTablesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasetables/constants.go b/resource-manager/sql/2023-08-01/databasetables/constants.go new file mode 100644 index 00000000000..0a6e1aab7e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/constants.go @@ -0,0 +1,54 @@ +package databasetables + +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 TableTemporalType string + +const ( + TableTemporalTypeHistoryTable TableTemporalType = "HistoryTable" + TableTemporalTypeNonTemporalTable TableTemporalType = "NonTemporalTable" + TableTemporalTypeSystemVersionedTemporalTable TableTemporalType = "SystemVersionedTemporalTable" +) + +func PossibleValuesForTableTemporalType() []string { + return []string{ + string(TableTemporalTypeHistoryTable), + string(TableTemporalTypeNonTemporalTable), + string(TableTemporalTypeSystemVersionedTemporalTable), + } +} + +func (s *TableTemporalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTableTemporalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTableTemporalType(input string) (*TableTemporalType, error) { + vals := map[string]TableTemporalType{ + "historytable": TableTemporalTypeHistoryTable, + "nontemporaltable": TableTemporalTypeNonTemporalTable, + "systemversionedtemporaltable": TableTemporalTypeSystemVersionedTemporalTable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TableTemporalType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasetables/id_schema.go b/resource-manager/sql/2023-08-01/databasetables/id_schema.go new file mode 100644 index 00000000000..5a1e8320ee6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/id_schema.go @@ -0,0 +1,148 @@ +package databasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SchemaId{}) +} + +var _ resourceids.ResourceId = &SchemaId{} + +// SchemaId is a struct representing the Resource ID for a Schema +type SchemaId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string +} + +// NewSchemaID returns a new SchemaId struct +func NewSchemaID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string) SchemaId { + return SchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + } +} + +// ParseSchemaID parses 'input' into a SchemaId +func ParseSchemaID(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaIDInsensitively parses 'input' case-insensitively into a SchemaId +// note: this method should only be used for API response data and not user input +func ParseSchemaIDInsensitively(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + return nil +} + +// ValidateSchemaID checks that 'input' can be parsed as a Schema ID +func ValidateSchemaID(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 := ParseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema ID +func (id SchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema ID +func (id SchemaId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + } +} + +// String returns a human-readable description of this Schema ID +func (id SchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + } + return fmt.Sprintf("Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasetables/id_schema_test.go b/resource-manager/sql/2023-08-01/databasetables/id_schema_test.go new file mode 100644 index 00000000000..faa2f372a1e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/id_schema_test.go @@ -0,0 +1,372 @@ +package databasetables + +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 = &SchemaId{} + +func TestNewSchemaID(t *testing.T) { + id := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestParseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestSegmentsForSchemaId(t *testing.T) { + segments := SchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaId 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/sql/2023-08-01/databasetables/id_table.go b/resource-manager/sql/2023-08-01/databasetables/id_table.go new file mode 100644 index 00000000000..ee53f02d2d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/id_table.go @@ -0,0 +1,157 @@ +package databasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TableId{}) +} + +var _ resourceids.ResourceId = &TableId{} + +// TableId is a struct representing the Resource ID for a Table +type TableId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string + TableName string +} + +// NewTableID returns a new TableId struct +func NewTableID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string, tableName string) TableId { + return TableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + } +} + +// ParseTableID parses 'input' into a TableId +func ParseTableID(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableIDInsensitively parses 'input' case-insensitively into a TableId +// note: this method should only be used for API response data and not user input +func ParseTableIDInsensitively(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateTableID checks that 'input' can be parsed as a Table ID +func ValidateTableID(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 := ParseTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table ID +func (id TableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table ID +func (id TableId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + } +} + +// String returns a human-readable description of this Table ID +func (id TableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasetables/id_table_test.go b/resource-manager/sql/2023-08-01/databasetables/id_table_test.go new file mode 100644 index 00000000000..8edf583a88c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/id_table_test.go @@ -0,0 +1,417 @@ +package databasetables + +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 = &TableId{} + +func TestNewTableID(t *testing.T) { + id := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForTableId(t *testing.T) { + segments := TableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableId 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/sql/2023-08-01/databasetables/method_get.go b/resource-manager/sql/2023-08-01/databasetables/method_get.go new file mode 100644 index 00000000000..00d41f2f7a5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/method_get.go @@ -0,0 +1,53 @@ +package databasetables + +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 *DatabaseTable +} + +// Get ... +func (c DatabaseTablesClient) Get(ctx context.Context, id TableId) (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 DatabaseTable + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasetables/method_listbyschema.go b/resource-manager/sql/2023-08-01/databasetables/method_listbyschema.go new file mode 100644 index 00000000000..27cef7ab7cc --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/method_listbyschema.go @@ -0,0 +1,134 @@ +package databasetables + +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 ListBySchemaOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseTable +} + +type ListBySchemaCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseTable +} + +type ListBySchemaOperationOptions struct { + Filter *string +} + +func DefaultListBySchemaOperationOptions() ListBySchemaOperationOptions { + return ListBySchemaOperationOptions{} +} + +func (o ListBySchemaOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySchemaOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySchemaOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListBySchemaCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySchemaCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySchema ... +func (c DatabaseTablesClient) ListBySchema(ctx context.Context, id SchemaId, options ListBySchemaOperationOptions) (result ListBySchemaOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySchemaCustomPager{}, + Path: fmt.Sprintf("%s/tables", 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 *[]DatabaseTable `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySchemaComplete retrieves all the results into a single object +func (c DatabaseTablesClient) ListBySchemaComplete(ctx context.Context, id SchemaId, options ListBySchemaOperationOptions) (ListBySchemaCompleteResult, error) { + return c.ListBySchemaCompleteMatchingPredicate(ctx, id, options, DatabaseTableOperationPredicate{}) +} + +// ListBySchemaCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseTablesClient) ListBySchemaCompleteMatchingPredicate(ctx context.Context, id SchemaId, options ListBySchemaOperationOptions, predicate DatabaseTableOperationPredicate) (result ListBySchemaCompleteResult, err error) { + items := make([]DatabaseTable, 0) + + resp, err := c.ListBySchema(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySchemaCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasetables/model_databasetable.go b/resource-manager/sql/2023-08-01/databasetables/model_databasetable.go new file mode 100644 index 00000000000..b1194f9c6b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/model_databasetable.go @@ -0,0 +1,11 @@ +package databasetables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseTable struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseTableProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasetables/model_databasetableproperties.go b/resource-manager/sql/2023-08-01/databasetables/model_databasetableproperties.go new file mode 100644 index 00000000000..eaa51ed2455 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/model_databasetableproperties.go @@ -0,0 +1,9 @@ +package databasetables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseTableProperties struct { + MemoryOptimized *bool `json:"memoryOptimized,omitempty"` + TemporalType *TableTemporalType `json:"temporalType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasetables/predicates.go b/resource-manager/sql/2023-08-01/databasetables/predicates.go new file mode 100644 index 00000000000..2c942a576ba --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/predicates.go @@ -0,0 +1,27 @@ +package databasetables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseTableOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseTableOperationPredicate) Matches(input DatabaseTable) 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/sql/2023-08-01/databasetables/version.go b/resource-manager/sql/2023-08-01/databasetables/version.go new file mode 100644 index 00000000000..276276283d0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasetables/version.go @@ -0,0 +1,10 @@ +package databasetables + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasetables/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databaseusages/README.md b/resource-manager/sql/2023-08-01/databaseusages/README.md new file mode 100644 index 00000000000..f1e1d9312cc --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseusages` Documentation + +The `databaseusages` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databaseusages" +``` + + +### Client Initialization + +```go +client := databaseusages.NewDatabaseUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseUsagesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databaseusages/client.go b/resource-manager/sql/2023-08-01/databaseusages/client.go new file mode 100644 index 00000000000..d79c504a7f5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/client.go @@ -0,0 +1,26 @@ +package databaseusages + +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 DatabaseUsagesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseUsagesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databaseusages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseUsagesClient: %+v", err) + } + + return &DatabaseUsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databaseusages/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databaseusages/method_listbydatabase.go new file mode 100644 index 00000000000..4b0299b00f1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databaseusages + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseUsage +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseUsage +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseUsagesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatabaseUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseUsagesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseUsageOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseUsagesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseUsageOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseUsage, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databaseusages/model_databaseusage.go b/resource-manager/sql/2023-08-01/databaseusages/model_databaseusage.go new file mode 100644 index 00000000000..a7020ded2ef --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/model_databaseusage.go @@ -0,0 +1,11 @@ +package databaseusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUsage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseUsageProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseusages/model_databaseusageproperties.go b/resource-manager/sql/2023-08-01/databaseusages/model_databaseusageproperties.go new file mode 100644 index 00000000000..92c383a80f4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/model_databaseusageproperties.go @@ -0,0 +1,11 @@ +package databaseusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUsageProperties struct { + CurrentValue *float64 `json:"currentValue,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databaseusages/predicates.go b/resource-manager/sql/2023-08-01/databaseusages/predicates.go new file mode 100644 index 00000000000..0ae433ca19e --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/predicates.go @@ -0,0 +1,27 @@ +package databaseusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUsageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseUsageOperationPredicate) Matches(input DatabaseUsage) 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/sql/2023-08-01/databaseusages/version.go b/resource-manager/sql/2023-08-01/databaseusages/version.go new file mode 100644 index 00000000000..8b98ffbc71c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databaseusages/version.go @@ -0,0 +1,10 @@ +package databaseusages + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databaseusages/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/README.md b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/README.md new file mode 100644 index 00000000000..2141683e1b8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines` Documentation + +The `databasevulnerabilityassessmentrulebaselines` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines" +``` + + +### Client Initialization + +```go +client := databasevulnerabilityassessmentrulebaselines.NewDatabaseVulnerabilityAssessmentRuleBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentRuleBaselinesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentrulebaselines.NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId", "default") + +payload := databasevulnerabilityassessmentrulebaselines.DatabaseVulnerabilityAssessmentRuleBaseline{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentRuleBaselinesClient.Delete` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentrulebaselines.NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId", "default") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentRuleBaselinesClient.Get` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentrulebaselines.NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId", "default") + +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 +} +``` diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/client.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/client.go new file mode 100644 index 00000000000..9d705cb0169 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/client.go @@ -0,0 +1,26 @@ +package databasevulnerabilityassessmentrulebaselines + +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 DatabaseVulnerabilityAssessmentRuleBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseVulnerabilityAssessmentRuleBaselinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasevulnerabilityassessmentrulebaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseVulnerabilityAssessmentRuleBaselinesClient: %+v", err) + } + + return &DatabaseVulnerabilityAssessmentRuleBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/constants.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/constants.go new file mode 100644 index 00000000000..fcface1c5a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/constants.go @@ -0,0 +1,51 @@ +package databasevulnerabilityassessmentrulebaselines + +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 VulnerabilityAssessmentPolicyBaselineName string + +const ( + VulnerabilityAssessmentPolicyBaselineNameDefault VulnerabilityAssessmentPolicyBaselineName = "default" + VulnerabilityAssessmentPolicyBaselineNameMaster VulnerabilityAssessmentPolicyBaselineName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentPolicyBaselineName() []string { + return []string{ + string(VulnerabilityAssessmentPolicyBaselineNameDefault), + string(VulnerabilityAssessmentPolicyBaselineNameMaster), + } +} + +func (s *VulnerabilityAssessmentPolicyBaselineName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentPolicyBaselineName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentPolicyBaselineName(input string) (*VulnerabilityAssessmentPolicyBaselineName, error) { + vals := map[string]VulnerabilityAssessmentPolicyBaselineName{ + "default": VulnerabilityAssessmentPolicyBaselineNameDefault, + "master": VulnerabilityAssessmentPolicyBaselineNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentPolicyBaselineName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline.go new file mode 100644 index 00000000000..c1529c9615a --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline.go @@ -0,0 +1,167 @@ +package databasevulnerabilityassessmentrulebaselines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BaselineId{}) +} + +var _ resourceids.ResourceId = &BaselineId{} + +// BaselineId is a struct representing the Resource ID for a Baseline +type BaselineId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + RuleId string + BaselineName VulnerabilityAssessmentPolicyBaselineName +} + +// NewBaselineID returns a new BaselineId struct +func NewBaselineID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, ruleId string, baselineName VulnerabilityAssessmentPolicyBaselineName) BaselineId { + return BaselineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + RuleId: ruleId, + BaselineName: baselineName, + } +} + +// ParseBaselineID parses 'input' into a BaselineId +func ParseBaselineID(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBaselineIDInsensitively parses 'input' case-insensitively into a BaselineId +// note: this method should only be used for API response data and not user input +func ParseBaselineIDInsensitively(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BaselineId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + if v, ok := input.Parsed["baselineName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "baselineName", input) + } + + baselineName, err := parseVulnerabilityAssessmentPolicyBaselineName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.BaselineName = *baselineName + } + + return nil +} + +// ValidateBaselineID checks that 'input' can be parsed as a Baseline ID +func ValidateBaselineID(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 := ParseBaselineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Baseline ID +func (id BaselineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/vulnerabilityAssessments/default/rules/%s/baselines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.RuleId, string(id.BaselineName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Baseline ID +func (id BaselineId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleId"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.ConstantSegment("baselineName", PossibleValuesForVulnerabilityAssessmentPolicyBaselineName(), "default"), + } +} + +// String returns a human-readable description of this Baseline ID +func (id BaselineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Rule: %q", id.RuleId), + fmt.Sprintf("Baseline Name: %q", string(id.BaselineName)), + } + return fmt.Sprintf("Baseline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go new file mode 100644 index 00000000000..17af9e25430 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go @@ -0,0 +1,447 @@ +package databasevulnerabilityassessmentrulebaselines + +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 = &BaselineId{} + +func TestNewBaselineID(t *testing.T) { + id := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId", "default") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.RuleId != "ruleId" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleId") + } + + if id.BaselineName != "default" { + t.Fatalf("Expected %q but got %q for Segment 'BaselineName'", id.BaselineName, "default") + } +} + +func TestFormatBaselineID(t *testing.T) { + actual := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleId", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBaselineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RuleId: "ruleId", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestParseBaselineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RuleId: "ruleId", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD/bAsElInEs/dEfAuLt", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + RuleId: "rUlEiD", + BaselineName: "default", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD/bAsElInEs/dEfAuLt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestSegmentsForBaselineId(t *testing.T) { + segments := BaselineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BaselineId 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/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go new file mode 100644 index 00000000000..e0a57bf0eef --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go @@ -0,0 +1,57 @@ +package databasevulnerabilityassessmentrulebaselines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessmentRuleBaseline +} + +// CreateOrUpdate ... +func (c DatabaseVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdate(ctx context.Context, id BaselineId, input DatabaseVulnerabilityAssessmentRuleBaseline) (result CreateOrUpdateOperationResponse, 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 DatabaseVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_delete.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_delete.go new file mode 100644 index 00000000000..cc043e8d89b --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_delete.go @@ -0,0 +1,46 @@ +package databasevulnerabilityassessmentrulebaselines + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DatabaseVulnerabilityAssessmentRuleBaselinesClient) Delete(ctx context.Context, id BaselineId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_get.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_get.go new file mode 100644 index 00000000000..554e6664a47 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/method_get.go @@ -0,0 +1,53 @@ +package databasevulnerabilityassessmentrulebaselines + +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 *DatabaseVulnerabilityAssessmentRuleBaseline +} + +// Get ... +func (c DatabaseVulnerabilityAssessmentRuleBaselinesClient) Get(ctx context.Context, id BaselineId) (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 DatabaseVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..fe51a95a8d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go @@ -0,0 +1,11 @@ +package databasevulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentRuleBaseline struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseVulnerabilityAssessmentRuleBaselineProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go new file mode 100644 index 00000000000..b47ec6e5578 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go @@ -0,0 +1,8 @@ +package databasevulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentRuleBaselineItem struct { + Result []string `json:"result"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..f51405f99d9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go @@ -0,0 +1,8 @@ +package databasevulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentRuleBaselineProperties struct { + BaselineResults []DatabaseVulnerabilityAssessmentRuleBaselineItem `json:"baselineResults"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/version.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/version.go new file mode 100644 index 00000000000..e4d87ea7ef9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentrulebaselines/version.go @@ -0,0 +1,10 @@ +package databasevulnerabilityassessmentrulebaselines + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasevulnerabilityassessmentrulebaselines/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/README.md b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/README.md new file mode 100644 index 00000000000..7dc93d37532 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessments` Documentation + +The `databasevulnerabilityassessments` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := databasevulnerabilityassessments.NewDatabaseVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := databasevulnerabilityassessments.DatabaseVulnerabilityAssessment{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DatabaseVulnerabilityAssessmentsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/client.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/client.go new file mode 100644 index 00000000000..038b962a146 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/client.go @@ -0,0 +1,26 @@ +package databasevulnerabilityassessments + +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 DatabaseVulnerabilityAssessmentsClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseVulnerabilityAssessmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseVulnerabilityAssessmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasevulnerabilityassessments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseVulnerabilityAssessmentsClient: %+v", err) + } + + return &DatabaseVulnerabilityAssessmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..cd059d04950 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,60 @@ +package databasevulnerabilityassessments + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessment +} + +// CreateOrUpdate ... +func (c DatabaseVulnerabilityAssessmentsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input DatabaseVulnerabilityAssessment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 DatabaseVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..6172241c793 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_delete.go @@ -0,0 +1,48 @@ +package databasevulnerabilityassessments + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DatabaseVulnerabilityAssessmentsClient) Delete(ctx context.Context, id commonids.SqlDatabaseId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_get.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..45ee4c29235 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_get.go @@ -0,0 +1,55 @@ +package databasevulnerabilityassessments + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessment +} + +// Get ... +func (c DatabaseVulnerabilityAssessmentsClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 DatabaseVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_listbydatabase.go new file mode 100644 index 00000000000..c5f109bbde6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databasevulnerabilityassessments + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseVulnerabilityAssessment +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseVulnerabilityAssessment +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseVulnerabilityAssessmentsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/vulnerabilityAssessments", 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 *[]DatabaseVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseVulnerabilityAssessmentsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseVulnerabilityAssessmentOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseVulnerabilityAssessmentsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DatabaseVulnerabilityAssessmentOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseVulnerabilityAssessment, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go new file mode 100644 index 00000000000..9269405cf65 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go @@ -0,0 +1,11 @@ +package databasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..0bdca627486 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package databasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..fd19effd67d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package databasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/predicates.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..4f0c37586c8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/predicates.go @@ -0,0 +1,27 @@ +package databasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseVulnerabilityAssessmentOperationPredicate) Matches(input DatabaseVulnerabilityAssessment) 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/sql/2023-08-01/databasevulnerabilityassessments/version.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/version.go new file mode 100644 index 00000000000..3d62edacad1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessments/version.go @@ -0,0 +1,10 @@ +package databasevulnerabilityassessments + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasevulnerabilityassessments/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..e9a44e517dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans` Documentation + +The `databasevulnerabilityassessmentscans` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans" +``` + + +### Client Initialization + +```go +client := databasevulnerabilityassessmentscans.NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentScansClient.Export` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentscans.NewVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + +read, err := client.Export(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentScansClient.Get` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentscans.NewVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + +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: `DatabaseVulnerabilityAssessmentScansClient.InitiateScan` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentscans.NewVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + +if err := client.InitiateScanThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentScansClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..7060f30a177 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/client.go @@ -0,0 +1,26 @@ +package databasevulnerabilityassessmentscans + +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 DatabaseVulnerabilityAssessmentScansClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseVulnerabilityAssessmentScansClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databasevulnerabilityassessmentscans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseVulnerabilityAssessmentScansClient: %+v", err) + } + + return &DatabaseVulnerabilityAssessmentScansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..791d3bd0ff7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/constants.go @@ -0,0 +1,98 @@ +package databasevulnerabilityassessmentscans + +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 VulnerabilityAssessmentScanState string + +const ( + VulnerabilityAssessmentScanStateFailed VulnerabilityAssessmentScanState = "Failed" + VulnerabilityAssessmentScanStateFailedToRun VulnerabilityAssessmentScanState = "FailedToRun" + VulnerabilityAssessmentScanStateInProgress VulnerabilityAssessmentScanState = "InProgress" + VulnerabilityAssessmentScanStatePassed VulnerabilityAssessmentScanState = "Passed" +) + +func PossibleValuesForVulnerabilityAssessmentScanState() []string { + return []string{ + string(VulnerabilityAssessmentScanStateFailed), + string(VulnerabilityAssessmentScanStateFailedToRun), + string(VulnerabilityAssessmentScanStateInProgress), + string(VulnerabilityAssessmentScanStatePassed), + } +} + +func (s *VulnerabilityAssessmentScanState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanState(input string) (*VulnerabilityAssessmentScanState, error) { + vals := map[string]VulnerabilityAssessmentScanState{ + "failed": VulnerabilityAssessmentScanStateFailed, + "failedtorun": VulnerabilityAssessmentScanStateFailedToRun, + "inprogress": VulnerabilityAssessmentScanStateInProgress, + "passed": VulnerabilityAssessmentScanStatePassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanState(input) + return &out, nil +} + +type VulnerabilityAssessmentScanTriggerType string + +const ( + VulnerabilityAssessmentScanTriggerTypeOnDemand VulnerabilityAssessmentScanTriggerType = "OnDemand" + VulnerabilityAssessmentScanTriggerTypeRecurring VulnerabilityAssessmentScanTriggerType = "Recurring" +) + +func PossibleValuesForVulnerabilityAssessmentScanTriggerType() []string { + return []string{ + string(VulnerabilityAssessmentScanTriggerTypeOnDemand), + string(VulnerabilityAssessmentScanTriggerTypeRecurring), + } +} + +func (s *VulnerabilityAssessmentScanTriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanTriggerType(input string) (*VulnerabilityAssessmentScanTriggerType, error) { + vals := map[string]VulnerabilityAssessmentScanTriggerType{ + "ondemand": VulnerabilityAssessmentScanTriggerTypeOnDemand, + "recurring": VulnerabilityAssessmentScanTriggerTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanTriggerType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go new file mode 100644 index 00000000000..1231ad3d14f --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go @@ -0,0 +1,150 @@ +package databasevulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VulnerabilityAssessmentScanId{}) +} + +var _ resourceids.ResourceId = &VulnerabilityAssessmentScanId{} + +// VulnerabilityAssessmentScanId is a struct representing the Resource ID for a Vulnerability Assessment Scan +type VulnerabilityAssessmentScanId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + ScanId string +} + +// NewVulnerabilityAssessmentScanID returns a new VulnerabilityAssessmentScanId struct +func NewVulnerabilityAssessmentScanID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, scanId string) VulnerabilityAssessmentScanId { + return VulnerabilityAssessmentScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + ScanId: scanId, + } +} + +// ParseVulnerabilityAssessmentScanID parses 'input' into a VulnerabilityAssessmentScanId +func ParseVulnerabilityAssessmentScanID(input string) (*VulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&VulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVulnerabilityAssessmentScanIDInsensitively parses 'input' case-insensitively into a VulnerabilityAssessmentScanId +// note: this method should only be used for API response data and not user input +func ParseVulnerabilityAssessmentScanIDInsensitively(input string) (*VulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&VulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VulnerabilityAssessmentScanId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateVulnerabilityAssessmentScanID checks that 'input' can be parsed as a Vulnerability Assessment Scan ID +func ValidateVulnerabilityAssessmentScanID(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 := ParseVulnerabilityAssessmentScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vulnerability Assessment Scan ID +func (id VulnerabilityAssessmentScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/vulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vulnerability Assessment Scan ID +func (id VulnerabilityAssessmentScanId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + } +} + +// String returns a human-readable description of this Vulnerability Assessment Scan ID +func (id VulnerabilityAssessmentScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Vulnerability Assessment Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..6244a448abf --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go @@ -0,0 +1,402 @@ +package databasevulnerabilityassessmentscans + +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 = &VulnerabilityAssessmentScanId{} + +func TestNewVulnerabilityAssessmentScanID(t *testing.T) { + id := NewVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } +} + +func TestFormatVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "scanId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVulnerabilityAssessmentScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId", + Expected: &VulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVulnerabilityAssessmentScanID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseVulnerabilityAssessmentScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId", + Expected: &VulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiD", + Expected: &VulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + ScanId: "sCaNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVulnerabilityAssessmentScanIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForVulnerabilityAssessmentScanId(t *testing.T) { + segments := VulnerabilityAssessmentScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VulnerabilityAssessmentScanId 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/sql/2023-08-01/databasevulnerabilityassessmentscans/method_export.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_export.go new file mode 100644 index 00000000000..6990e393834 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_export.go @@ -0,0 +1,54 @@ +package databasevulnerabilityassessmentscans + +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 ExportOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessmentScansExport +} + +// Export ... +func (c DatabaseVulnerabilityAssessmentScansClient) Export(ctx context.Context, id VulnerabilityAssessmentScanId) (result ExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", 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 DatabaseVulnerabilityAssessmentScansExport + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..c692ed8bc59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_get.go @@ -0,0 +1,53 @@ +package databasevulnerabilityassessmentscans + +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 *VulnerabilityAssessmentScanRecord +} + +// Get ... +func (c DatabaseVulnerabilityAssessmentScansClient) Get(ctx context.Context, id VulnerabilityAssessmentScanId) (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 VulnerabilityAssessmentScanRecord + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_initiatescan.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_initiatescan.go new file mode 100644 index 00000000000..f100586b147 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_initiatescan.go @@ -0,0 +1,70 @@ +package databasevulnerabilityassessmentscans + +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 InitiateScanOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// InitiateScan ... +func (c DatabaseVulnerabilityAssessmentScansClient) InitiateScan(ctx context.Context, id VulnerabilityAssessmentScanId) (result InitiateScanOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/initiateScan", 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 +} + +// InitiateScanThenPoll performs InitiateScan then polls until it's completed +func (c DatabaseVulnerabilityAssessmentScansClient) InitiateScanThenPoll(ctx context.Context, id VulnerabilityAssessmentScanId) error { + result, err := c.InitiateScan(ctx, id) + if err != nil { + return fmt.Errorf("performing InitiateScan: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after InitiateScan: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_listbydatabase.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_listbydatabase.go new file mode 100644 index 00000000000..1dde13b5722 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/method_listbydatabase.go @@ -0,0 +1,106 @@ +package databasevulnerabilityassessmentscans + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VulnerabilityAssessmentScanRecord +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []VulnerabilityAssessmentScanRecord +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DatabaseVulnerabilityAssessmentScansClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default/scans", 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 *[]VulnerabilityAssessmentScanRecord `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, VulnerabilityAssessmentScanRecordOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate VulnerabilityAssessmentScanRecordOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]VulnerabilityAssessmentScanRecord, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go new file mode 100644 index 00000000000..cdafe495ca7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go @@ -0,0 +1,8 @@ +package databasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentScanExportProperties struct { + ExportedReportLocation *string `json:"exportedReportLocation,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go new file mode 100644 index 00000000000..f960c81d8a0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go @@ -0,0 +1,11 @@ +package databasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentScansExport struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseVulnerabilityAssessmentScanExportProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..0fa70199afb --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go @@ -0,0 +1,9 @@ +package databasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..3123a1b31f1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go @@ -0,0 +1,11 @@ +package databasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecord struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VulnerabilityAssessmentScanRecordProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..8ddd7d0d512 --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go @@ -0,0 +1,45 @@ +package databasevulnerabilityassessmentscans + +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 VulnerabilityAssessmentScanRecordProperties struct { + EndTime *string `json:"endTime,omitempty"` + Errors *[]VulnerabilityAssessmentScanError `json:"errors,omitempty"` + NumberOfFailedSecurityChecks *int64 `json:"numberOfFailedSecurityChecks,omitempty"` + ScanId *string `json:"scanId,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *VulnerabilityAssessmentScanState `json:"state,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + TriggerType *VulnerabilityAssessmentScanTriggerType `json:"triggerType,omitempty"` +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..5794f6e1b2c --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/predicates.go @@ -0,0 +1,27 @@ +package databasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecordOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VulnerabilityAssessmentScanRecordOperationPredicate) Matches(input VulnerabilityAssessmentScanRecord) 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/sql/2023-08-01/databasevulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..39c30a3f36d --- /dev/null +++ b/resource-manager/sql/2023-08-01/databasevulnerabilityassessmentscans/version.go @@ -0,0 +1,10 @@ +package databasevulnerabilityassessmentscans + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databasevulnerabilityassessmentscans/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/README.md b/resource-manager/sql/2023-08-01/datamaskingpolicies/README.md new file mode 100644 index 00000000000..7c424e33f50 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datamaskingpolicies` Documentation + +The `datamaskingpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datamaskingpolicies" +``` + + +### Client Initialization + +```go +client := datamaskingpolicies.NewDataMaskingPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataMaskingPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := datamaskingpolicies.DataMaskingPolicy{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataMaskingPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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 +} +``` diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/client.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/client.go new file mode 100644 index 00000000000..b9fc98390b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/client.go @@ -0,0 +1,26 @@ +package datamaskingpolicies + +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 DataMaskingPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewDataMaskingPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*DataMaskingPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "datamaskingpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataMaskingPoliciesClient: %+v", err) + } + + return &DataMaskingPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/constants.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/constants.go new file mode 100644 index 00000000000..ac7ba1d7679 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/constants.go @@ -0,0 +1,51 @@ +package datamaskingpolicies + +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 DataMaskingState string + +const ( + DataMaskingStateDisabled DataMaskingState = "Disabled" + DataMaskingStateEnabled DataMaskingState = "Enabled" +) + +func PossibleValuesForDataMaskingState() []string { + return []string{ + string(DataMaskingStateDisabled), + string(DataMaskingStateEnabled), + } +} + +func (s *DataMaskingState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingState(input string) (*DataMaskingState, error) { + vals := map[string]DataMaskingState{ + "disabled": DataMaskingStateDisabled, + "enabled": DataMaskingStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/method_createorupdate.go new file mode 100644 index 00000000000..40914de8f15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/method_createorupdate.go @@ -0,0 +1,60 @@ +package datamaskingpolicies + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingPolicy +} + +// CreateOrUpdate ... +func (c DataMaskingPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input DataMaskingPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/dataMaskingPolicies/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 DataMaskingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/method_get.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/method_get.go new file mode 100644 index 00000000000..a1fc156a99f --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/method_get.go @@ -0,0 +1,55 @@ +package datamaskingpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingPolicy +} + +// Get ... +func (c DataMaskingPoliciesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dataMaskingPolicies/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 DataMaskingPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicy.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicy.go new file mode 100644 index 00000000000..cfe52f97165 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicy.go @@ -0,0 +1,13 @@ +package datamaskingpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataMaskingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicyproperties.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicyproperties.go new file mode 100644 index 00000000000..088a6d92c48 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/model_datamaskingpolicyproperties.go @@ -0,0 +1,11 @@ +package datamaskingpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingPolicyProperties struct { + ApplicationPrincipals *string `json:"applicationPrincipals,omitempty"` + DataMaskingState DataMaskingState `json:"dataMaskingState"` + ExemptPrincipals *string `json:"exemptPrincipals,omitempty"` + MaskingLevel *string `json:"maskingLevel,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/datamaskingpolicies/version.go b/resource-manager/sql/2023-08-01/datamaskingpolicies/version.go new file mode 100644 index 00000000000..a23343f12f4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingpolicies/version.go @@ -0,0 +1,10 @@ +package datamaskingpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/datamaskingpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/README.md b/resource-manager/sql/2023-08-01/datamaskingrules/README.md new file mode 100644 index 00000000000..d7f5e8ca38a --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/README.md @@ -0,0 +1,59 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datamaskingrules` Documentation + +The `datamaskingrules` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datamaskingrules" +``` + + +### Client Initialization + +```go +client := datamaskingrules.NewDataMaskingRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataMaskingRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := datamaskingrules.NewDataMaskingPolicyRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleName") + +payload := datamaskingrules.DataMaskingRule{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataMaskingRulesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/client.go b/resource-manager/sql/2023-08-01/datamaskingrules/client.go new file mode 100644 index 00000000000..e9a838cb776 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/client.go @@ -0,0 +1,26 @@ +package datamaskingrules + +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 DataMaskingRulesClient struct { + Client *resourcemanager.Client +} + +func NewDataMaskingRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*DataMaskingRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "datamaskingrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataMaskingRulesClient: %+v", err) + } + + return &DataMaskingRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/constants.go b/resource-manager/sql/2023-08-01/datamaskingrules/constants.go new file mode 100644 index 00000000000..1fd30bab056 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/constants.go @@ -0,0 +1,104 @@ +package datamaskingrules + +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 DataMaskingFunction string + +const ( + DataMaskingFunctionCCN DataMaskingFunction = "CCN" + DataMaskingFunctionDefault DataMaskingFunction = "Default" + DataMaskingFunctionEmail DataMaskingFunction = "Email" + DataMaskingFunctionNumber DataMaskingFunction = "Number" + DataMaskingFunctionSSN DataMaskingFunction = "SSN" + DataMaskingFunctionText DataMaskingFunction = "Text" +) + +func PossibleValuesForDataMaskingFunction() []string { + return []string{ + string(DataMaskingFunctionCCN), + string(DataMaskingFunctionDefault), + string(DataMaskingFunctionEmail), + string(DataMaskingFunctionNumber), + string(DataMaskingFunctionSSN), + string(DataMaskingFunctionText), + } +} + +func (s *DataMaskingFunction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingFunction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingFunction(input string) (*DataMaskingFunction, error) { + vals := map[string]DataMaskingFunction{ + "ccn": DataMaskingFunctionCCN, + "default": DataMaskingFunctionDefault, + "email": DataMaskingFunctionEmail, + "number": DataMaskingFunctionNumber, + "ssn": DataMaskingFunctionSSN, + "text": DataMaskingFunctionText, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingFunction(input) + return &out, nil +} + +type DataMaskingRuleState string + +const ( + DataMaskingRuleStateDisabled DataMaskingRuleState = "Disabled" + DataMaskingRuleStateEnabled DataMaskingRuleState = "Enabled" +) + +func PossibleValuesForDataMaskingRuleState() []string { + return []string{ + string(DataMaskingRuleStateDisabled), + string(DataMaskingRuleStateEnabled), + } +} + +func (s *DataMaskingRuleState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingRuleState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingRuleState(input string) (*DataMaskingRuleState, error) { + vals := map[string]DataMaskingRuleState{ + "disabled": DataMaskingRuleStateDisabled, + "enabled": DataMaskingRuleStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingRuleState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule.go b/resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule.go new file mode 100644 index 00000000000..5cef2fdde04 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule.go @@ -0,0 +1,150 @@ +package datamaskingrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DataMaskingPolicyRuleId{}) +} + +var _ resourceids.ResourceId = &DataMaskingPolicyRuleId{} + +// DataMaskingPolicyRuleId is a struct representing the Resource ID for a Data Masking Policy Rule +type DataMaskingPolicyRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + RuleName string +} + +// NewDataMaskingPolicyRuleID returns a new DataMaskingPolicyRuleId struct +func NewDataMaskingPolicyRuleID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, ruleName string) DataMaskingPolicyRuleId { + return DataMaskingPolicyRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + RuleName: ruleName, + } +} + +// ParseDataMaskingPolicyRuleID parses 'input' into a DataMaskingPolicyRuleId +func ParseDataMaskingPolicyRuleID(input string) (*DataMaskingPolicyRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataMaskingPolicyRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataMaskingPolicyRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDataMaskingPolicyRuleIDInsensitively parses 'input' case-insensitively into a DataMaskingPolicyRuleId +// note: this method should only be used for API response data and not user input +func ParseDataMaskingPolicyRuleIDInsensitively(input string) (*DataMaskingPolicyRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataMaskingPolicyRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataMaskingPolicyRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DataMaskingPolicyRuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.RuleName, ok = input.Parsed["ruleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleName", input) + } + + return nil +} + +// ValidateDataMaskingPolicyRuleID checks that 'input' can be parsed as a Data Masking Policy Rule ID +func ValidateDataMaskingPolicyRuleID(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 := ParseDataMaskingPolicyRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Data Masking Policy Rule ID +func (id DataMaskingPolicyRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/dataMaskingPolicies/default/rules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.RuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Data Masking Policy Rule ID +func (id DataMaskingPolicyRuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticDataMaskingPolicies", "dataMaskingPolicies", "dataMaskingPolicies"), + resourceids.StaticSegment("dataMaskingPolicyName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleName", "ruleName"), + } +} + +// String returns a human-readable description of this Data Masking Policy Rule ID +func (id DataMaskingPolicyRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Rule Name: %q", id.RuleName), + } + return fmt.Sprintf("Data Masking Policy Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule_test.go b/resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule_test.go new file mode 100644 index 00000000000..113a74c654a --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/id_datamaskingpolicyrule_test.go @@ -0,0 +1,402 @@ +package datamaskingrules + +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 = &DataMaskingPolicyRuleId{} + +func TestNewDataMaskingPolicyRuleID(t *testing.T) { + id := NewDataMaskingPolicyRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.RuleName != "ruleName" { + t.Fatalf("Expected %q but got %q for Segment 'RuleName'", id.RuleName, "ruleName") + } +} + +func TestFormatDataMaskingPolicyRuleID(t *testing.T) { + actual := NewDataMaskingPolicyRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "ruleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules/ruleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDataMaskingPolicyRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataMaskingPolicyRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules/ruleName", + Expected: &DataMaskingPolicyRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RuleName: "ruleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules/ruleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataMaskingPolicyRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleName != v.Expected.RuleName { + t.Fatalf("Expected %q but got %q for RuleName", v.Expected.RuleName, actual.RuleName) + } + + } +} + +func TestParseDataMaskingPolicyRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataMaskingPolicyRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/dAtAmAsKiNgPoLiCiEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/dAtAmAsKiNgPoLiCiEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules/ruleName", + Expected: &DataMaskingPolicyRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RuleName: "ruleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/dataMaskingPolicies/default/rules/ruleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs/rUlEnAmE", + Expected: &DataMaskingPolicyRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + RuleName: "rUlEnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs/rUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataMaskingPolicyRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleName != v.Expected.RuleName { + t.Fatalf("Expected %q but got %q for RuleName", v.Expected.RuleName, actual.RuleName) + } + + } +} + +func TestSegmentsForDataMaskingPolicyRuleId(t *testing.T) { + segments := DataMaskingPolicyRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DataMaskingPolicyRuleId 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/sql/2023-08-01/datamaskingrules/method_createorupdate.go b/resource-manager/sql/2023-08-01/datamaskingrules/method_createorupdate.go new file mode 100644 index 00000000000..5665741a0d2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/method_createorupdate.go @@ -0,0 +1,58 @@ +package datamaskingrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingRule +} + +// CreateOrUpdate ... +func (c DataMaskingRulesClient) CreateOrUpdate(ctx context.Context, id DataMaskingPolicyRuleId, input DataMaskingRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DataMaskingRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/method_listbydatabase.go b/resource-manager/sql/2023-08-01/datamaskingrules/method_listbydatabase.go new file mode 100644 index 00000000000..43666bbd0a8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/method_listbydatabase.go @@ -0,0 +1,106 @@ +package datamaskingrules + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataMaskingRule +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataMaskingRule +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DataMaskingRulesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/dataMaskingPolicies/default/rules", 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 *[]DataMaskingRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DataMaskingRulesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DataMaskingRuleOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataMaskingRulesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DataMaskingRuleOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DataMaskingRule, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingrule.go b/resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingrule.go new file mode 100644 index 00000000000..f913eb87c5a --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingrule.go @@ -0,0 +1,13 @@ +package datamaskingrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRule struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataMaskingRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingruleproperties.go b/resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingruleproperties.go new file mode 100644 index 00000000000..91a008885e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/model_datamaskingruleproperties.go @@ -0,0 +1,19 @@ +package datamaskingrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRuleProperties struct { + AliasName *string `json:"aliasName,omitempty"` + ColumnName string `json:"columnName"` + Id *string `json:"id,omitempty"` + MaskingFunction DataMaskingFunction `json:"maskingFunction"` + NumberFrom *string `json:"numberFrom,omitempty"` + NumberTo *string `json:"numberTo,omitempty"` + PrefixSize *string `json:"prefixSize,omitempty"` + ReplacementString *string `json:"replacementString,omitempty"` + RuleState *DataMaskingRuleState `json:"ruleState,omitempty"` + SchemaName string `json:"schemaName"` + SuffixSize *string `json:"suffixSize,omitempty"` + TableName string `json:"tableName"` +} diff --git a/resource-manager/sql/2023-08-01/datamaskingrules/predicates.go b/resource-manager/sql/2023-08-01/datamaskingrules/predicates.go new file mode 100644 index 00000000000..a5864e3f5e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/predicates.go @@ -0,0 +1,37 @@ +package datamaskingrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRuleOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p DataMaskingRuleOperationPredicate) Matches(input DataMaskingRule) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/datamaskingrules/version.go b/resource-manager/sql/2023-08-01/datamaskingrules/version.go new file mode 100644 index 00000000000..cf76446b55e --- /dev/null +++ b/resource-manager/sql/2023-08-01/datamaskingrules/version.go @@ -0,0 +1,10 @@ +package datamaskingrules + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/datamaskingrules/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/README.md b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/README.md new file mode 100644 index 00000000000..4a69cae9da8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datawarehouseuseractivities` Documentation + +The `datawarehouseuseractivities` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/datawarehouseuseractivities" +``` + + +### Client Initialization + +```go +client := datawarehouseuseractivities.NewDataWarehouseUserActivitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataWarehouseUserActivitiesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `DataWarehouseUserActivitiesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/client.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/client.go new file mode 100644 index 00000000000..98e15f11f1c --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/client.go @@ -0,0 +1,26 @@ +package datawarehouseuseractivities + +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 DataWarehouseUserActivitiesClient struct { + Client *resourcemanager.Client +} + +func NewDataWarehouseUserActivitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*DataWarehouseUserActivitiesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "datawarehouseuseractivities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataWarehouseUserActivitiesClient: %+v", err) + } + + return &DataWarehouseUserActivitiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_get.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_get.go new file mode 100644 index 00000000000..2d7d9d01bb7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_get.go @@ -0,0 +1,55 @@ +package datawarehouseuseractivities + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataWarehouseUserActivities +} + +// Get ... +func (c DataWarehouseUserActivitiesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dataWarehouseUserActivities/current", 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 DataWarehouseUserActivities + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_listbydatabase.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_listbydatabase.go new file mode 100644 index 00000000000..0afca238098 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/method_listbydatabase.go @@ -0,0 +1,106 @@ +package datawarehouseuseractivities + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataWarehouseUserActivities +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataWarehouseUserActivities +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c DataWarehouseUserActivitiesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/dataWarehouseUserActivities", 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 *[]DataWarehouseUserActivities `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c DataWarehouseUserActivitiesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DataWarehouseUserActivitiesOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataWarehouseUserActivitiesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate DataWarehouseUserActivitiesOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DataWarehouseUserActivities, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivities.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivities.go new file mode 100644 index 00000000000..7e187e58a9d --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivities.go @@ -0,0 +1,11 @@ +package datawarehouseuseractivities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataWarehouseUserActivities struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataWarehouseUserActivitiesProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go new file mode 100644 index 00000000000..c36effa5b46 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go @@ -0,0 +1,8 @@ +package datawarehouseuseractivities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataWarehouseUserActivitiesProperties struct { + ActiveQueriesCount *int64 `json:"activeQueriesCount,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/datawarehouseuseractivities/predicates.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/predicates.go new file mode 100644 index 00000000000..25dc9b0b353 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/predicates.go @@ -0,0 +1,27 @@ +package datawarehouseuseractivities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataWarehouseUserActivitiesOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DataWarehouseUserActivitiesOperationPredicate) Matches(input DataWarehouseUserActivities) 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/sql/2023-08-01/datawarehouseuseractivities/version.go b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/version.go new file mode 100644 index 00000000000..195f054f651 --- /dev/null +++ b/resource-manager/sql/2023-08-01/datawarehouseuseractivities/version.go @@ -0,0 +1,10 @@ +package datawarehouseuseractivities + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/datawarehouseuseractivities/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/README.md b/resource-manager/sql/2023-08-01/deletedservers/README.md new file mode 100644 index 00000000000..1f1be0574c6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/deletedservers` Documentation + +The `deletedservers` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/deletedservers" +``` + + +### Client Initialization + +```go +client := deletedservers.NewDeletedServersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeletedServersClient.Get` + +```go +ctx := context.TODO() +id := deletedservers.NewDeletedServerID("12345678-1234-9876-4563-123456789012", "locationName", "deletedServerName") + +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: `DeletedServersClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `DeletedServersClient.ListByLocation` + +```go +ctx := context.TODO() +id := deletedservers.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeletedServersClient.Recover` + +```go +ctx := context.TODO() +id := deletedservers.NewDeletedServerID("12345678-1234-9876-4563-123456789012", "locationName", "deletedServerName") + +if err := client.RecoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/deletedservers/client.go b/resource-manager/sql/2023-08-01/deletedservers/client.go new file mode 100644 index 00000000000..6679ead4a59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/client.go @@ -0,0 +1,26 @@ +package deletedservers + +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 DeletedServersClient struct { + Client *resourcemanager.Client +} + +func NewDeletedServersClientWithBaseURI(sdkApi sdkEnv.Api) (*DeletedServersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "deletedservers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeletedServersClient: %+v", err) + } + + return &DeletedServersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/id_deletedserver.go b/resource-manager/sql/2023-08-01/deletedservers/id_deletedserver.go new file mode 100644 index 00000000000..952f38cc887 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/id_deletedserver.go @@ -0,0 +1,130 @@ +package deletedservers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeletedServerId{}) +} + +var _ resourceids.ResourceId = &DeletedServerId{} + +// DeletedServerId is a struct representing the Resource ID for a Deleted Server +type DeletedServerId struct { + SubscriptionId string + LocationName string + DeletedServerName string +} + +// NewDeletedServerID returns a new DeletedServerId struct +func NewDeletedServerID(subscriptionId string, locationName string, deletedServerName string) DeletedServerId { + return DeletedServerId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + DeletedServerName: deletedServerName, + } +} + +// ParseDeletedServerID parses 'input' into a DeletedServerId +func ParseDeletedServerID(input string) (*DeletedServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedServerIDInsensitively parses 'input' case-insensitively into a DeletedServerId +// note: this method should only be used for API response data and not user input +func ParseDeletedServerIDInsensitively(input string) (*DeletedServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedServerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.DeletedServerName, ok = input.Parsed["deletedServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedServerName", input) + } + + return nil +} + +// ValidateDeletedServerID checks that 'input' can be parsed as a Deleted Server ID +func ValidateDeletedServerID(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 := ParseDeletedServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Server ID +func (id DeletedServerId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/deletedServers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.DeletedServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Server ID +func (id DeletedServerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticDeletedServers", "deletedServers", "deletedServers"), + resourceids.UserSpecifiedSegment("deletedServerName", "deletedServerName"), + } +} + +// String returns a human-readable description of this Deleted Server ID +func (id DeletedServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Deleted Server Name: %q", id.DeletedServerName), + } + return fmt.Sprintf("Deleted Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/id_deletedserver_test.go b/resource-manager/sql/2023-08-01/deletedservers/id_deletedserver_test.go new file mode 100644 index 00000000000..30e037bc66f --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/id_deletedserver_test.go @@ -0,0 +1,282 @@ +package deletedservers + +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 = &DeletedServerId{} + +func TestNewDeletedServerID(t *testing.T) { + id := NewDeletedServerID("12345678-1234-9876-4563-123456789012", "locationName", "deletedServerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.DeletedServerName != "deletedServerName" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedServerName'", id.DeletedServerName, "deletedServerName") + } +} + +func TestFormatDeletedServerID(t *testing.T) { + actual := NewDeletedServerID("12345678-1234-9876-4563-123456789012", "locationName", "deletedServerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers/deletedServerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers/deletedServerName", + Expected: &DeletedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + DeletedServerName: "deletedServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers/deletedServerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedServerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.DeletedServerName != v.Expected.DeletedServerName { + t.Fatalf("Expected %q but got %q for DeletedServerName", v.Expected.DeletedServerName, actual.DeletedServerName) + } + + } +} + +func TestParseDeletedServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers/deletedServerName", + Expected: &DeletedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + DeletedServerName: "deletedServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/deletedServers/deletedServerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdSeRvErS/dElEtEdSeRvErNaMe", + Expected: &DeletedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + DeletedServerName: "dElEtEdSeRvErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/dElEtEdSeRvErS/dElEtEdSeRvErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedServerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.DeletedServerName != v.Expected.DeletedServerName { + t.Fatalf("Expected %q but got %q for DeletedServerName", v.Expected.DeletedServerName, actual.DeletedServerName) + } + + } +} + +func TestSegmentsForDeletedServerId(t *testing.T) { + segments := DeletedServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedServerId 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/sql/2023-08-01/deletedservers/id_location.go b/resource-manager/sql/2023-08-01/deletedservers/id_location.go new file mode 100644 index 00000000000..d61e1b38206 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/id_location.go @@ -0,0 +1,121 @@ +package deletedservers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/id_location_test.go b/resource-manager/sql/2023-08-01/deletedservers/id_location_test.go new file mode 100644 index 00000000000..eb6da5596ac --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/id_location_test.go @@ -0,0 +1,237 @@ +package deletedservers + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/deletedservers/method_get.go b/resource-manager/sql/2023-08-01/deletedservers/method_get.go new file mode 100644 index 00000000000..7f7f83241ae --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/method_get.go @@ -0,0 +1,53 @@ +package deletedservers + +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 *DeletedServer +} + +// Get ... +func (c DeletedServersClient) Get(ctx context.Context, id DeletedServerId) (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 DeletedServer + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/method_list.go b/resource-manager/sql/2023-08-01/deletedservers/method_list.go new file mode 100644 index 00000000000..b05a2be5d8a --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/method_list.go @@ -0,0 +1,106 @@ +package deletedservers + +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 *[]DeletedServer +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeletedServer +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c DeletedServersClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/deletedServers", 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 *[]DeletedServer `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 DeletedServersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DeletedServerOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeletedServersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DeletedServerOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DeletedServer, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/method_listbylocation.go b/resource-manager/sql/2023-08-01/deletedservers/method_listbylocation.go new file mode 100644 index 00000000000..db104941bc6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/method_listbylocation.go @@ -0,0 +1,105 @@ +package deletedservers + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DeletedServer +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeletedServer +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c DeletedServersClient) ListByLocation(ctx context.Context, id LocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/deletedServers", 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 *[]DeletedServer `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c DeletedServersClient) ListByLocationComplete(ctx context.Context, id LocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, DeletedServerOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeletedServersClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate DeletedServerOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]DeletedServer, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/method_recover.go b/resource-manager/sql/2023-08-01/deletedservers/method_recover.go new file mode 100644 index 00000000000..385c348c761 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/method_recover.go @@ -0,0 +1,71 @@ +package deletedservers + +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 RecoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DeletedServer +} + +// Recover ... +func (c DeletedServersClient) Recover(ctx context.Context, id DeletedServerId) (result RecoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/recover", 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 +} + +// RecoverThenPoll performs Recover then polls until it's completed +func (c DeletedServersClient) RecoverThenPoll(ctx context.Context, id DeletedServerId) error { + result, err := c.Recover(ctx, id) + if err != nil { + return fmt.Errorf("performing Recover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Recover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/model_deletedserver.go b/resource-manager/sql/2023-08-01/deletedservers/model_deletedserver.go new file mode 100644 index 00000000000..483e36dc97c --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/model_deletedserver.go @@ -0,0 +1,11 @@ +package deletedservers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedServer struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeletedServerProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/model_deletedserverproperties.go b/resource-manager/sql/2023-08-01/deletedservers/model_deletedserverproperties.go new file mode 100644 index 00000000000..cc25fe5c0d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/model_deletedserverproperties.go @@ -0,0 +1,29 @@ +package deletedservers + +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 DeletedServerProperties struct { + DeletionTime *string `json:"deletionTime,omitempty"` + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty"` + OriginalId *string `json:"originalId,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *DeletedServerProperties) GetDeletionTimeAsTime() (*time.Time, error) { + if o.DeletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeletedServerProperties) SetDeletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/deletedservers/predicates.go b/resource-manager/sql/2023-08-01/deletedservers/predicates.go new file mode 100644 index 00000000000..9f570a85ad9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/predicates.go @@ -0,0 +1,27 @@ +package deletedservers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeletedServerOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DeletedServerOperationPredicate) Matches(input DeletedServer) 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/sql/2023-08-01/deletedservers/version.go b/resource-manager/sql/2023-08-01/deletedservers/version.go new file mode 100644 index 00000000000..c348cc83202 --- /dev/null +++ b/resource-manager/sql/2023-08-01/deletedservers/version.go @@ -0,0 +1,10 @@ +package deletedservers + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/deletedservers/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/README.md b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/README.md new file mode 100644 index 00000000000..e3754c01027 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/README.md @@ -0,0 +1,134 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/distributedavailabilitygroups` Documentation + +The `distributedavailabilitygroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/distributedavailabilitygroups" +``` + + +### Client Initialization + +```go +client := distributedavailabilitygroups.NewDistributedAvailabilityGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + +payload := distributedavailabilitygroups.DistributedAvailabilityGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.Delete` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.Failover` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + +payload := distributedavailabilitygroups.DistributedAvailabilityGroupsFailoverRequest{ + // ... +} + + +if err := client.FailoverThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.Get` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + +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: `DistributedAvailabilityGroupsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.SetRole` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + +payload := distributedavailabilitygroups.DistributedAvailabilityGroupSetRole{ + // ... +} + + +if err := client.SetRoleThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.Update` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + +payload := distributedavailabilitygroups.DistributedAvailabilityGroup{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/client.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/client.go new file mode 100644 index 00000000000..f9d46b7aa4b --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/client.go @@ -0,0 +1,26 @@ +package distributedavailabilitygroups + +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 DistributedAvailabilityGroupsClient struct { + Client *resourcemanager.Client +} + +func NewDistributedAvailabilityGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*DistributedAvailabilityGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "distributedavailabilitygroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DistributedAvailabilityGroupsClient: %+v", err) + } + + return &DistributedAvailabilityGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/constants.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/constants.go new file mode 100644 index 00000000000..ca73daa69ff --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/constants.go @@ -0,0 +1,382 @@ +package distributedavailabilitygroups + +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 FailoverModeType string + +const ( + FailoverModeTypeManual FailoverModeType = "Manual" + FailoverModeTypeNone FailoverModeType = "None" +) + +func PossibleValuesForFailoverModeType() []string { + return []string{ + string(FailoverModeTypeManual), + string(FailoverModeTypeNone), + } +} + +func (s *FailoverModeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFailoverModeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFailoverModeType(input string) (*FailoverModeType, error) { + vals := map[string]FailoverModeType{ + "manual": FailoverModeTypeManual, + "none": FailoverModeTypeNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FailoverModeType(input) + return &out, nil +} + +type FailoverType string + +const ( + FailoverTypeForcedAllowDataLoss FailoverType = "ForcedAllowDataLoss" + FailoverTypePlanned FailoverType = "Planned" +) + +func PossibleValuesForFailoverType() []string { + return []string{ + string(FailoverTypeForcedAllowDataLoss), + string(FailoverTypePlanned), + } +} + +func (s *FailoverType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFailoverType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFailoverType(input string) (*FailoverType, error) { + vals := map[string]FailoverType{ + "forcedallowdataloss": FailoverTypeForcedAllowDataLoss, + "planned": FailoverTypePlanned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FailoverType(input) + return &out, nil +} + +type InstanceRole string + +const ( + InstanceRolePrimary InstanceRole = "Primary" + InstanceRoleSecondary InstanceRole = "Secondary" +) + +func PossibleValuesForInstanceRole() []string { + return []string{ + string(InstanceRolePrimary), + string(InstanceRoleSecondary), + } +} + +func (s *InstanceRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInstanceRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInstanceRole(input string) (*InstanceRole, error) { + vals := map[string]InstanceRole{ + "primary": InstanceRolePrimary, + "secondary": InstanceRoleSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InstanceRole(input) + return &out, nil +} + +type LinkRole string + +const ( + LinkRolePrimary LinkRole = "Primary" + LinkRoleSecondary LinkRole = "Secondary" +) + +func PossibleValuesForLinkRole() []string { + return []string{ + string(LinkRolePrimary), + string(LinkRoleSecondary), + } +} + +func (s *LinkRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkRole(input string) (*LinkRole, error) { + vals := map[string]LinkRole{ + "primary": LinkRolePrimary, + "secondary": LinkRoleSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkRole(input) + return &out, nil +} + +type ReplicaConnectedState string + +const ( + ReplicaConnectedStateCONNECTED ReplicaConnectedState = "CONNECTED" + ReplicaConnectedStateDISCONNECTED ReplicaConnectedState = "DISCONNECTED" +) + +func PossibleValuesForReplicaConnectedState() []string { + return []string{ + string(ReplicaConnectedStateCONNECTED), + string(ReplicaConnectedStateDISCONNECTED), + } +} + +func (s *ReplicaConnectedState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicaConnectedState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicaConnectedState(input string) (*ReplicaConnectedState, error) { + vals := map[string]ReplicaConnectedState{ + "connected": ReplicaConnectedStateCONNECTED, + "disconnected": ReplicaConnectedStateDISCONNECTED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicaConnectedState(input) + return &out, nil +} + +type ReplicaSynchronizationHealth string + +const ( + ReplicaSynchronizationHealthHEALTHY ReplicaSynchronizationHealth = "HEALTHY" + ReplicaSynchronizationHealthNOTHEALTHY ReplicaSynchronizationHealth = "NOT_HEALTHY" + ReplicaSynchronizationHealthPARTIALLYHEALTHY ReplicaSynchronizationHealth = "PARTIALLY_HEALTHY" +) + +func PossibleValuesForReplicaSynchronizationHealth() []string { + return []string{ + string(ReplicaSynchronizationHealthHEALTHY), + string(ReplicaSynchronizationHealthNOTHEALTHY), + string(ReplicaSynchronizationHealthPARTIALLYHEALTHY), + } +} + +func (s *ReplicaSynchronizationHealth) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicaSynchronizationHealth(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicaSynchronizationHealth(input string) (*ReplicaSynchronizationHealth, error) { + vals := map[string]ReplicaSynchronizationHealth{ + "healthy": ReplicaSynchronizationHealthHEALTHY, + "not_healthy": ReplicaSynchronizationHealthNOTHEALTHY, + "partially_healthy": ReplicaSynchronizationHealthPARTIALLYHEALTHY, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicaSynchronizationHealth(input) + return &out, nil +} + +type ReplicationModeType string + +const ( + ReplicationModeTypeAsync ReplicationModeType = "Async" + ReplicationModeTypeSync ReplicationModeType = "Sync" +) + +func PossibleValuesForReplicationModeType() []string { + return []string{ + string(ReplicationModeTypeAsync), + string(ReplicationModeTypeSync), + } +} + +func (s *ReplicationModeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationModeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationModeType(input string) (*ReplicationModeType, error) { + vals := map[string]ReplicationModeType{ + "async": ReplicationModeTypeAsync, + "sync": ReplicationModeTypeSync, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationModeType(input) + return &out, nil +} + +type RoleChangeType string + +const ( + RoleChangeTypeForced RoleChangeType = "Forced" + RoleChangeTypePlanned RoleChangeType = "Planned" +) + +func PossibleValuesForRoleChangeType() []string { + return []string{ + string(RoleChangeTypeForced), + string(RoleChangeTypePlanned), + } +} + +func (s *RoleChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRoleChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRoleChangeType(input string) (*RoleChangeType, error) { + vals := map[string]RoleChangeType{ + "forced": RoleChangeTypeForced, + "planned": RoleChangeTypePlanned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RoleChangeType(input) + return &out, nil +} + +type SeedingModeType string + +const ( + SeedingModeTypeAutomatic SeedingModeType = "Automatic" + SeedingModeTypeManual SeedingModeType = "Manual" +) + +func PossibleValuesForSeedingModeType() []string { + return []string{ + string(SeedingModeTypeAutomatic), + string(SeedingModeTypeManual), + } +} + +func (s *SeedingModeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSeedingModeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSeedingModeType(input string) (*SeedingModeType, error) { + vals := map[string]SeedingModeType{ + "automatic": SeedingModeTypeAutomatic, + "manual": SeedingModeTypeManual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SeedingModeType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup.go new file mode 100644 index 00000000000..33d8fd774b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup.go @@ -0,0 +1,139 @@ +package distributedavailabilitygroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DistributedAvailabilityGroupId{}) +} + +var _ resourceids.ResourceId = &DistributedAvailabilityGroupId{} + +// DistributedAvailabilityGroupId is a struct representing the Resource ID for a Distributed Availability Group +type DistributedAvailabilityGroupId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DistributedAvailabilityGroupName string +} + +// NewDistributedAvailabilityGroupID returns a new DistributedAvailabilityGroupId struct +func NewDistributedAvailabilityGroupID(subscriptionId string, resourceGroupName string, managedInstanceName string, distributedAvailabilityGroupName string) DistributedAvailabilityGroupId { + return DistributedAvailabilityGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DistributedAvailabilityGroupName: distributedAvailabilityGroupName, + } +} + +// ParseDistributedAvailabilityGroupID parses 'input' into a DistributedAvailabilityGroupId +func ParseDistributedAvailabilityGroupID(input string) (*DistributedAvailabilityGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&DistributedAvailabilityGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DistributedAvailabilityGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDistributedAvailabilityGroupIDInsensitively parses 'input' case-insensitively into a DistributedAvailabilityGroupId +// note: this method should only be used for API response data and not user input +func ParseDistributedAvailabilityGroupIDInsensitively(input string) (*DistributedAvailabilityGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&DistributedAvailabilityGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DistributedAvailabilityGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DistributedAvailabilityGroupId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DistributedAvailabilityGroupName, ok = input.Parsed["distributedAvailabilityGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "distributedAvailabilityGroupName", input) + } + + return nil +} + +// ValidateDistributedAvailabilityGroupID checks that 'input' can be parsed as a Distributed Availability Group ID +func ValidateDistributedAvailabilityGroupID(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 := ParseDistributedAvailabilityGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Distributed Availability Group ID +func (id DistributedAvailabilityGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/distributedAvailabilityGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DistributedAvailabilityGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Distributed Availability Group ID +func (id DistributedAvailabilityGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDistributedAvailabilityGroups", "distributedAvailabilityGroups", "distributedAvailabilityGroups"), + resourceids.UserSpecifiedSegment("distributedAvailabilityGroupName", "distributedAvailabilityGroupName"), + } +} + +// String returns a human-readable description of this Distributed Availability Group ID +func (id DistributedAvailabilityGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Distributed Availability Group Name: %q", id.DistributedAvailabilityGroupName), + } + return fmt.Sprintf("Distributed Availability Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go new file mode 100644 index 00000000000..45fb901be20 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go @@ -0,0 +1,327 @@ +package distributedavailabilitygroups + +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 = &DistributedAvailabilityGroupId{} + +func TestNewDistributedAvailabilityGroupID(t *testing.T) { + id := NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DistributedAvailabilityGroupName != "distributedAvailabilityGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'DistributedAvailabilityGroupName'", id.DistributedAvailabilityGroupName, "distributedAvailabilityGroupName") + } +} + +func TestFormatDistributedAvailabilityGroupID(t *testing.T) { + actual := NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "distributedAvailabilityGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups/distributedAvailabilityGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDistributedAvailabilityGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DistributedAvailabilityGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups/distributedAvailabilityGroupName", + Expected: &DistributedAvailabilityGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DistributedAvailabilityGroupName: "distributedAvailabilityGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups/distributedAvailabilityGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDistributedAvailabilityGroupID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DistributedAvailabilityGroupName != v.Expected.DistributedAvailabilityGroupName { + t.Fatalf("Expected %q but got %q for DistributedAvailabilityGroupName", v.Expected.DistributedAvailabilityGroupName, actual.DistributedAvailabilityGroupName) + } + + } +} + +func TestParseDistributedAvailabilityGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DistributedAvailabilityGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dIsTrIbUtEdAvAiLaBiLiTyGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups/distributedAvailabilityGroupName", + Expected: &DistributedAvailabilityGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DistributedAvailabilityGroupName: "distributedAvailabilityGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/distributedAvailabilityGroups/distributedAvailabilityGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dIsTrIbUtEdAvAiLaBiLiTyGrOuPs/dIsTrIbUtEdAvAiLaBiLiTyGrOuPnAmE", + Expected: &DistributedAvailabilityGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DistributedAvailabilityGroupName: "dIsTrIbUtEdAvAiLaBiLiTyGrOuPnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dIsTrIbUtEdAvAiLaBiLiTyGrOuPs/dIsTrIbUtEdAvAiLaBiLiTyGrOuPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDistributedAvailabilityGroupIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DistributedAvailabilityGroupName != v.Expected.DistributedAvailabilityGroupName { + t.Fatalf("Expected %q but got %q for DistributedAvailabilityGroupName", v.Expected.DistributedAvailabilityGroupName, actual.DistributedAvailabilityGroupName) + } + + } +} + +func TestSegmentsForDistributedAvailabilityGroupId(t *testing.T) { + segments := DistributedAvailabilityGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DistributedAvailabilityGroupId 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/sql/2023-08-01/distributedavailabilitygroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_createorupdate.go new file mode 100644 index 00000000000..a1bc709775c --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_createorupdate.go @@ -0,0 +1,76 @@ +package distributedavailabilitygroups + +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 *DistributedAvailabilityGroup +} + +// CreateOrUpdate ... +func (c DistributedAvailabilityGroupsClient) CreateOrUpdate(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 DistributedAvailabilityGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroup) 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/sql/2023-08-01/distributedavailabilitygroups/method_delete.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_delete.go new file mode 100644 index 00000000000..19d3805ce35 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_delete.go @@ -0,0 +1,71 @@ +package distributedavailabilitygroups + +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 DistributedAvailabilityGroupsClient) Delete(ctx context.Context, id DistributedAvailabilityGroupId) (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 DistributedAvailabilityGroupsClient) DeleteThenPoll(ctx context.Context, id DistributedAvailabilityGroupId) 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/sql/2023-08-01/distributedavailabilitygroups/method_failover.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_failover.go new file mode 100644 index 00000000000..e2818489480 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_failover.go @@ -0,0 +1,75 @@ +package distributedavailabilitygroups + +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 FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DistributedAvailabilityGroup +} + +// Failover ... +func (c DistributedAvailabilityGroupsClient) Failover(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroupsFailoverRequest) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c DistributedAvailabilityGroupsClient) FailoverThenPoll(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroupsFailoverRequest) error { + result, err := c.Failover(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_get.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_get.go new file mode 100644 index 00000000000..d60cf4fdf20 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_get.go @@ -0,0 +1,53 @@ +package distributedavailabilitygroups + +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 *DistributedAvailabilityGroup +} + +// Get ... +func (c DistributedAvailabilityGroupsClient) Get(ctx context.Context, id DistributedAvailabilityGroupId) (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 DistributedAvailabilityGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_listbyinstance.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_listbyinstance.go new file mode 100644 index 00000000000..3d8d4ba9d9a --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_listbyinstance.go @@ -0,0 +1,106 @@ +package distributedavailabilitygroups + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DistributedAvailabilityGroup +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []DistributedAvailabilityGroup +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c DistributedAvailabilityGroupsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/distributedAvailabilityGroups", 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 *[]DistributedAvailabilityGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c DistributedAvailabilityGroupsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, DistributedAvailabilityGroupOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DistributedAvailabilityGroupsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate DistributedAvailabilityGroupOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]DistributedAvailabilityGroup, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_setrole.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_setrole.go new file mode 100644 index 00000000000..3946c4c5bb5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_setrole.go @@ -0,0 +1,75 @@ +package distributedavailabilitygroups + +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 SetRoleOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DistributedAvailabilityGroup +} + +// SetRole ... +func (c DistributedAvailabilityGroupsClient) SetRole(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroupSetRole) (result SetRoleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/setRole", 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 +} + +// SetRoleThenPoll performs SetRole then polls until it's completed +func (c DistributedAvailabilityGroupsClient) SetRoleThenPoll(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroupSetRole) error { + result, err := c.SetRole(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SetRole: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SetRole: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_update.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_update.go new file mode 100644 index 00000000000..e82559765a0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/method_update.go @@ -0,0 +1,75 @@ +package distributedavailabilitygroups + +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 *DistributedAvailabilityGroup +} + +// Update ... +func (c DistributedAvailabilityGroupsClient) Update(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroup) (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 DistributedAvailabilityGroupsClient) UpdateThenPoll(ctx context.Context, id DistributedAvailabilityGroupId, input DistributedAvailabilityGroup) 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/sql/2023-08-01/distributedavailabilitygroups/model_certificateinfo.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_certificateinfo.go new file mode 100644 index 00000000000..c283fede0f0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_certificateinfo.go @@ -0,0 +1,27 @@ +package distributedavailabilitygroups + +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 CertificateInfo struct { + CertificateName *string `json:"certificateName,omitempty"` + ExpiryDate *string `json:"expiryDate,omitempty"` +} + +func (o *CertificateInfo) GetExpiryDateAsTime() (*time.Time, error) { + if o.ExpiryDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CertificateInfo) SetExpiryDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroup.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroup.go new file mode 100644 index 00000000000..e56cb07f9e6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroup.go @@ -0,0 +1,11 @@ +package distributedavailabilitygroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedAvailabilityGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DistributedAvailabilityGroupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go new file mode 100644 index 00000000000..07e528cbe4d --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go @@ -0,0 +1,94 @@ +package distributedavailabilitygroups + +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 DistributedAvailabilityGroupDatabase struct { + ConnectedState *ReplicaConnectedState `json:"connectedState,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + InstanceRedoReplicationLagSeconds *int64 `json:"instanceRedoReplicationLagSeconds,omitempty"` + InstanceReplicaId *string `json:"instanceReplicaId,omitempty"` + InstanceSendReplicationLagSeconds *int64 `json:"instanceSendReplicationLagSeconds,omitempty"` + LastBackupLsn *string `json:"lastBackupLsn,omitempty"` + LastBackupTime *string `json:"lastBackupTime,omitempty"` + LastCommitLsn *string `json:"lastCommitLsn,omitempty"` + LastCommitTime *string `json:"lastCommitTime,omitempty"` + LastHardenedLsn *string `json:"lastHardenedLsn,omitempty"` + LastHardenedTime *string `json:"lastHardenedTime,omitempty"` + LastReceivedLsn *string `json:"lastReceivedLsn,omitempty"` + LastReceivedTime *string `json:"lastReceivedTime,omitempty"` + LastSentLsn *string `json:"lastSentLsn,omitempty"` + LastSentTime *string `json:"lastSentTime,omitempty"` + MostRecentLinkError *string `json:"mostRecentLinkError,omitempty"` + PartnerAuthCertValidity *CertificateInfo `json:"partnerAuthCertValidity,omitempty"` + PartnerReplicaId *string `json:"partnerReplicaId,omitempty"` + ReplicaState *string `json:"replicaState,omitempty"` + SeedingProgress *string `json:"seedingProgress,omitempty"` + SynchronizationHealth *ReplicaSynchronizationHealth `json:"synchronizationHealth,omitempty"` +} + +func (o *DistributedAvailabilityGroupDatabase) GetLastBackupTimeAsTime() (*time.Time, error) { + if o.LastBackupTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastBackupTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DistributedAvailabilityGroupDatabase) SetLastBackupTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastBackupTime = &formatted +} + +func (o *DistributedAvailabilityGroupDatabase) GetLastCommitTimeAsTime() (*time.Time, error) { + if o.LastCommitTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastCommitTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DistributedAvailabilityGroupDatabase) SetLastCommitTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastCommitTime = &formatted +} + +func (o *DistributedAvailabilityGroupDatabase) GetLastHardenedTimeAsTime() (*time.Time, error) { + if o.LastHardenedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastHardenedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DistributedAvailabilityGroupDatabase) SetLastHardenedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastHardenedTime = &formatted +} + +func (o *DistributedAvailabilityGroupDatabase) GetLastReceivedTimeAsTime() (*time.Time, error) { + if o.LastReceivedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastReceivedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DistributedAvailabilityGroupDatabase) SetLastReceivedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastReceivedTime = &formatted +} + +func (o *DistributedAvailabilityGroupDatabase) GetLastSentTimeAsTime() (*time.Time, error) { + if o.LastSentTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSentTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DistributedAvailabilityGroupDatabase) SetLastSentTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSentTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go new file mode 100644 index 00000000000..610182ba45e --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go @@ -0,0 +1,18 @@ +package distributedavailabilitygroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedAvailabilityGroupProperties struct { + Databases *[]DistributedAvailabilityGroupDatabase `json:"databases,omitempty"` + DistributedAvailabilityGroupId *string `json:"distributedAvailabilityGroupId,omitempty"` + DistributedAvailabilityGroupName *string `json:"distributedAvailabilityGroupName,omitempty"` + FailoverMode *FailoverModeType `json:"failoverMode,omitempty"` + InstanceAvailabilityGroupName *string `json:"instanceAvailabilityGroupName,omitempty"` + InstanceLinkRole *LinkRole `json:"instanceLinkRole,omitempty"` + PartnerAvailabilityGroupName *string `json:"partnerAvailabilityGroupName,omitempty"` + PartnerEndpoint *string `json:"partnerEndpoint,omitempty"` + PartnerLinkRole *LinkRole `json:"partnerLinkRole,omitempty"` + ReplicationMode *ReplicationModeType `json:"replicationMode,omitempty"` + SeedingMode *SeedingModeType `json:"seedingMode,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go new file mode 100644 index 00000000000..93dcf60bf98 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go @@ -0,0 +1,9 @@ +package distributedavailabilitygroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedAvailabilityGroupSetRole struct { + InstanceRole InstanceRole `json:"instanceRole"` + RoleChangeType RoleChangeType `json:"roleChangeType"` +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsfailoverrequest.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsfailoverrequest.go new file mode 100644 index 00000000000..72d0b9ea0e0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/model_distributedavailabilitygroupsfailoverrequest.go @@ -0,0 +1,8 @@ +package distributedavailabilitygroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedAvailabilityGroupsFailoverRequest struct { + FailoverType FailoverType `json:"failoverType"` +} diff --git a/resource-manager/sql/2023-08-01/distributedavailabilitygroups/predicates.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/predicates.go new file mode 100644 index 00000000000..7e0a257a8fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/predicates.go @@ -0,0 +1,27 @@ +package distributedavailabilitygroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DistributedAvailabilityGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DistributedAvailabilityGroupOperationPredicate) Matches(input DistributedAvailabilityGroup) 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/sql/2023-08-01/distributedavailabilitygroups/version.go b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/version.go new file mode 100644 index 00000000000..61e4aab0e48 --- /dev/null +++ b/resource-manager/sql/2023-08-01/distributedavailabilitygroups/version.go @@ -0,0 +1,10 @@ +package distributedavailabilitygroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/distributedavailabilitygroups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/README.md b/resource-manager/sql/2023-08-01/elasticpooloperations/README.md new file mode 100644 index 00000000000..cd82a026803 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/elasticpooloperations` Documentation + +The `elasticpooloperations` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/elasticpooloperations" +``` + + +### Client Initialization + +```go +client := elasticpooloperations.NewElasticPoolOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ElasticPoolOperationsClient.Cancel` + +```go +ctx := context.TODO() +id := elasticpooloperations.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName", "operationId") + +read, err := client.Cancel(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ElasticPoolOperationsClient.ListByElasticPool` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +// alternatively `client.ListByElasticPool(ctx, id)` can be used to do batched pagination +items, err := client.ListByElasticPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/client.go b/resource-manager/sql/2023-08-01/elasticpooloperations/client.go new file mode 100644 index 00000000000..fbaee40df4b --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/client.go @@ -0,0 +1,26 @@ +package elasticpooloperations + +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 ElasticPoolOperationsClient struct { + Client *resourcemanager.Client +} + +func NewElasticPoolOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ElasticPoolOperationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "elasticpooloperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ElasticPoolOperationsClient: %+v", err) + } + + return &ElasticPoolOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/id_operation.go b/resource-manager/sql/2023-08-01/elasticpooloperations/id_operation.go new file mode 100644 index 00000000000..4e37b35a8ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/id_operation.go @@ -0,0 +1,148 @@ +package elasticpooloperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + ElasticPoolName string + OperationId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(subscriptionId string, resourceGroupName string, serverName string, elasticPoolName string, operationId string) OperationId { + return OperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + ElasticPoolName: elasticPoolName, + OperationId: operationId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.ElasticPoolName, ok = input.Parsed["elasticPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "elasticPoolName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(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 := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/elasticPools/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.ElasticPoolName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticElasticPools", "elasticPools", "elasticPools"), + resourceids.UserSpecifiedSegment("elasticPoolName", "elasticPoolName"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationId"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Elastic Pool Name: %q", id.ElasticPoolName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/id_operation_test.go b/resource-manager/sql/2023-08-01/elasticpooloperations/id_operation_test.go new file mode 100644 index 00000000000..0168e8874fb --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/id_operation_test.go @@ -0,0 +1,372 @@ +package elasticpooloperations + +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 = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName", "operationId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.ElasticPoolName != "elasticPoolName" { + t.Fatalf("Expected %q but got %q for Segment 'ElasticPoolName'", id.ElasticPoolName, "elasticPoolName") + } + + if id.OperationId != "operationId" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationId") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName", "operationId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations/operationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations/operationId", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ElasticPoolName: "elasticPoolName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations/operationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ElasticPoolName != v.Expected.ElasticPoolName { + t.Fatalf("Expected %q but got %q for ElasticPoolName", v.Expected.ElasticPoolName, actual.ElasticPoolName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/eLaStIcPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/eLaStIcPoOlS/eLaStIcPoOlNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/eLaStIcPoOlS/eLaStIcPoOlNaMe/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations/operationId", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ElasticPoolName: "elasticPoolName", + OperationId: "operationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/elasticPools/elasticPoolName/operations/operationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/eLaStIcPoOlS/eLaStIcPoOlNaMe/oPeRaTiOnS/oPeRaTiOnId", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + ElasticPoolName: "eLaStIcPoOlNaMe", + OperationId: "oPeRaTiOnId", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/eLaStIcPoOlS/eLaStIcPoOlNaMe/oPeRaTiOnS/oPeRaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ElasticPoolName != v.Expected.ElasticPoolName { + t.Fatalf("Expected %q but got %q for ElasticPoolName", v.Expected.ElasticPoolName, actual.ElasticPoolName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId 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/sql/2023-08-01/elasticpooloperations/method_cancel.go b/resource-manager/sql/2023-08-01/elasticpooloperations/method_cancel.go new file mode 100644 index 00000000000..1fe7fb80fa2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/method_cancel.go @@ -0,0 +1,47 @@ +package elasticpooloperations + +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 CancelOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Cancel ... +func (c ElasticPoolOperationsClient) Cancel(ctx context.Context, id OperationId) (result CancelOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/method_listbyelasticpool.go b/resource-manager/sql/2023-08-01/elasticpooloperations/method_listbyelasticpool.go new file mode 100644 index 00000000000..102edc56a53 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/method_listbyelasticpool.go @@ -0,0 +1,106 @@ +package elasticpooloperations + +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 ListByElasticPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ElasticPoolOperation +} + +type ListByElasticPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []ElasticPoolOperation +} + +type ListByElasticPoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByElasticPoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByElasticPool ... +func (c ElasticPoolOperationsClient) ListByElasticPool(ctx context.Context, id commonids.SqlElasticPoolId) (result ListByElasticPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByElasticPoolCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]ElasticPoolOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByElasticPoolComplete retrieves all the results into a single object +func (c ElasticPoolOperationsClient) ListByElasticPoolComplete(ctx context.Context, id commonids.SqlElasticPoolId) (ListByElasticPoolCompleteResult, error) { + return c.ListByElasticPoolCompleteMatchingPredicate(ctx, id, ElasticPoolOperationOperationPredicate{}) +} + +// ListByElasticPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ElasticPoolOperationsClient) ListByElasticPoolCompleteMatchingPredicate(ctx context.Context, id commonids.SqlElasticPoolId, predicate ElasticPoolOperationOperationPredicate) (result ListByElasticPoolCompleteResult, err error) { + items := make([]ElasticPoolOperation, 0) + + resp, err := c.ListByElasticPool(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByElasticPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperation.go b/resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperation.go new file mode 100644 index 00000000000..c9613df58fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperation.go @@ -0,0 +1,11 @@ +package elasticpooloperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolOperation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ElasticPoolOperationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperationproperties.go b/resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperationproperties.go new file mode 100644 index 00000000000..70c4481877d --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/model_elasticpooloperationproperties.go @@ -0,0 +1,51 @@ +package elasticpooloperations + +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 ElasticPoolOperationProperties struct { + Description *string `json:"description,omitempty"` + ElasticPoolName *string `json:"elasticPoolName,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorDescription *string `json:"errorDescription,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + EstimatedCompletionTime *string `json:"estimatedCompletionTime,omitempty"` + IsCancellable *bool `json:"isCancellable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Operation *string `json:"operation,omitempty"` + OperationFriendlyName *string `json:"operationFriendlyName,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + ServerName *string `json:"serverName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *string `json:"state,omitempty"` +} + +func (o *ElasticPoolOperationProperties) GetEstimatedCompletionTimeAsTime() (*time.Time, error) { + if o.EstimatedCompletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EstimatedCompletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ElasticPoolOperationProperties) SetEstimatedCompletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EstimatedCompletionTime = &formatted +} + +func (o *ElasticPoolOperationProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ElasticPoolOperationProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/elasticpooloperations/predicates.go b/resource-manager/sql/2023-08-01/elasticpooloperations/predicates.go new file mode 100644 index 00000000000..2ac5a815355 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/predicates.go @@ -0,0 +1,27 @@ +package elasticpooloperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolOperationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ElasticPoolOperationOperationPredicate) Matches(input ElasticPoolOperation) 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/sql/2023-08-01/elasticpooloperations/version.go b/resource-manager/sql/2023-08-01/elasticpooloperations/version.go new file mode 100644 index 00000000000..3afee108295 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpooloperations/version.go @@ -0,0 +1,10 @@ +package elasticpooloperations + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/elasticpooloperations/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/README.md b/resource-manager/sql/2023-08-01/elasticpools/README.md new file mode 100644 index 00000000000..f68c1816b48 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/README.md @@ -0,0 +1,112 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/elasticpools` Documentation + +The `elasticpools` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/elasticpools" +``` + + +### Client Initialization + +```go +client := elasticpools.NewElasticPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ElasticPoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +payload := elasticpools.ElasticPool{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ElasticPoolsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ElasticPoolsClient.Failover` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +if err := client.FailoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ElasticPoolsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +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: `ElasticPoolsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id, elasticpools.DefaultListByServerOperationOptions())` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id, elasticpools.DefaultListByServerOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ElasticPoolsClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "elasticPoolName") + +payload := elasticpools.ElasticPoolUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/elasticpools/client.go b/resource-manager/sql/2023-08-01/elasticpools/client.go new file mode 100644 index 00000000000..d6335179470 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/client.go @@ -0,0 +1,26 @@ +package elasticpools + +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 ElasticPoolsClient struct { + Client *resourcemanager.Client +} + +func NewElasticPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*ElasticPoolsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "elasticpools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ElasticPoolsClient: %+v", err) + } + + return &ElasticPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/constants.go b/resource-manager/sql/2023-08-01/elasticpools/constants.go new file mode 100644 index 00000000000..25bee78c361 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/constants.go @@ -0,0 +1,183 @@ +package elasticpools + +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 AlwaysEncryptedEnclaveType string + +const ( + AlwaysEncryptedEnclaveTypeDefault AlwaysEncryptedEnclaveType = "Default" + AlwaysEncryptedEnclaveTypeVBS AlwaysEncryptedEnclaveType = "VBS" +) + +func PossibleValuesForAlwaysEncryptedEnclaveType() []string { + return []string{ + string(AlwaysEncryptedEnclaveTypeDefault), + string(AlwaysEncryptedEnclaveTypeVBS), + } +} + +func (s *AlwaysEncryptedEnclaveType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlwaysEncryptedEnclaveType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlwaysEncryptedEnclaveType(input string) (*AlwaysEncryptedEnclaveType, error) { + vals := map[string]AlwaysEncryptedEnclaveType{ + "default": AlwaysEncryptedEnclaveTypeDefault, + "vbs": AlwaysEncryptedEnclaveTypeVBS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlwaysEncryptedEnclaveType(input) + return &out, nil +} + +type AvailabilityZoneType string + +const ( + AvailabilityZoneTypeNoPreference AvailabilityZoneType = "NoPreference" + AvailabilityZoneTypeOne AvailabilityZoneType = "1" + AvailabilityZoneTypeThree AvailabilityZoneType = "3" + AvailabilityZoneTypeTwo AvailabilityZoneType = "2" +) + +func PossibleValuesForAvailabilityZoneType() []string { + return []string{ + string(AvailabilityZoneTypeNoPreference), + string(AvailabilityZoneTypeOne), + string(AvailabilityZoneTypeThree), + string(AvailabilityZoneTypeTwo), + } +} + +func (s *AvailabilityZoneType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAvailabilityZoneType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAvailabilityZoneType(input string) (*AvailabilityZoneType, error) { + vals := map[string]AvailabilityZoneType{ + "nopreference": AvailabilityZoneTypeNoPreference, + "1": AvailabilityZoneTypeOne, + "3": AvailabilityZoneTypeThree, + "2": AvailabilityZoneTypeTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AvailabilityZoneType(input) + return &out, nil +} + +type ElasticPoolLicenseType string + +const ( + ElasticPoolLicenseTypeBasePrice ElasticPoolLicenseType = "BasePrice" + ElasticPoolLicenseTypeLicenseIncluded ElasticPoolLicenseType = "LicenseIncluded" +) + +func PossibleValuesForElasticPoolLicenseType() []string { + return []string{ + string(ElasticPoolLicenseTypeBasePrice), + string(ElasticPoolLicenseTypeLicenseIncluded), + } +} + +func (s *ElasticPoolLicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElasticPoolLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseElasticPoolLicenseType(input string) (*ElasticPoolLicenseType, error) { + vals := map[string]ElasticPoolLicenseType{ + "baseprice": ElasticPoolLicenseTypeBasePrice, + "licenseincluded": ElasticPoolLicenseTypeLicenseIncluded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ElasticPoolLicenseType(input) + return &out, nil +} + +type ElasticPoolState string + +const ( + ElasticPoolStateCreating ElasticPoolState = "Creating" + ElasticPoolStateDisabled ElasticPoolState = "Disabled" + ElasticPoolStateReady ElasticPoolState = "Ready" +) + +func PossibleValuesForElasticPoolState() []string { + return []string{ + string(ElasticPoolStateCreating), + string(ElasticPoolStateDisabled), + string(ElasticPoolStateReady), + } +} + +func (s *ElasticPoolState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElasticPoolState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseElasticPoolState(input string) (*ElasticPoolState, error) { + vals := map[string]ElasticPoolState{ + "creating": ElasticPoolStateCreating, + "disabled": ElasticPoolStateDisabled, + "ready": ElasticPoolStateReady, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ElasticPoolState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/method_createorupdate.go b/resource-manager/sql/2023-08-01/elasticpools/method_createorupdate.go new file mode 100644 index 00000000000..6afe71a8903 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/method_createorupdate.go @@ -0,0 +1,77 @@ +package elasticpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ElasticPool +} + +// CreateOrUpdate ... +func (c ElasticPoolsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlElasticPoolId, input ElasticPool) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ElasticPoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlElasticPoolId, input ElasticPool) 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/sql/2023-08-01/elasticpools/method_delete.go b/resource-manager/sql/2023-08-01/elasticpools/method_delete.go new file mode 100644 index 00000000000..93d7f09a5c9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/method_delete.go @@ -0,0 +1,72 @@ +package elasticpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ElasticPoolsClient) Delete(ctx context.Context, id commonids.SqlElasticPoolId) (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 ElasticPoolsClient) DeleteThenPoll(ctx context.Context, id commonids.SqlElasticPoolId) 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/sql/2023-08-01/elasticpools/method_failover.go b/resource-manager/sql/2023-08-01/elasticpools/method_failover.go new file mode 100644 index 00000000000..9b6d2e8ed60 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/method_failover.go @@ -0,0 +1,71 @@ +package elasticpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Failover ... +func (c ElasticPoolsClient) Failover(ctx context.Context, id commonids.SqlElasticPoolId) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c ElasticPoolsClient) FailoverThenPoll(ctx context.Context, id commonids.SqlElasticPoolId) error { + result, err := c.Failover(ctx, id) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/method_get.go b/resource-manager/sql/2023-08-01/elasticpools/method_get.go new file mode 100644 index 00000000000..8cad14ea50b --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/method_get.go @@ -0,0 +1,54 @@ +package elasticpools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ElasticPool +} + +// Get ... +func (c ElasticPoolsClient) Get(ctx context.Context, id commonids.SqlElasticPoolId) (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 ElasticPool + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/method_listbyserver.go b/resource-manager/sql/2023-08-01/elasticpools/method_listbyserver.go new file mode 100644 index 00000000000..62ae75c61d6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/method_listbyserver.go @@ -0,0 +1,135 @@ +package elasticpools + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ElasticPool +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ElasticPool +} + +type ListByServerOperationOptions struct { + Skip *int64 +} + +func DefaultListByServerOperationOptions() ListByServerOperationOptions { + return ListByServerOperationOptions{} +} + +func (o ListByServerOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServerOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByServerOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + return &out +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ElasticPoolsClient) ListByServer(ctx context.Context, id commonids.SqlServerId, options ListByServerOperationOptions) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/elasticPools", 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 *[]ElasticPool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ElasticPoolsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId, options ListByServerOperationOptions) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, options, ElasticPoolOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ElasticPoolsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, options ListByServerOperationOptions, predicate ElasticPoolOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ElasticPool, 0) + + resp, err := c.ListByServer(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/method_update.go b/resource-manager/sql/2023-08-01/elasticpools/method_update.go new file mode 100644 index 00000000000..902071af581 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/method_update.go @@ -0,0 +1,76 @@ +package elasticpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ElasticPool +} + +// Update ... +func (c ElasticPoolsClient) Update(ctx context.Context, id commonids.SqlElasticPoolId, input ElasticPoolUpdate) (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 ElasticPoolsClient) UpdateThenPoll(ctx context.Context, id commonids.SqlElasticPoolId, input ElasticPoolUpdate) 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/sql/2023-08-01/elasticpools/model_elasticpool.go b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpool.go new file mode 100644 index 00000000000..6a7910b4d24 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpool.go @@ -0,0 +1,15 @@ +package elasticpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPool struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ElasticPoolProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolperdatabasesettings.go b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolperdatabasesettings.go new file mode 100644 index 00000000000..6e4e9821184 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolperdatabasesettings.go @@ -0,0 +1,10 @@ +package elasticpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolPerDatabaseSettings struct { + AutoPauseDelay *int64 `json:"autoPauseDelay,omitempty"` + MaxCapacity *float64 `json:"maxCapacity,omitempty"` + MinCapacity *float64 `json:"minCapacity,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolproperties.go b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolproperties.go new file mode 100644 index 00000000000..e9896b583d3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolproperties.go @@ -0,0 +1,37 @@ +package elasticpools + +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 ElasticPoolProperties struct { + AutoPauseDelay *int64 `json:"autoPauseDelay,omitempty"` + AvailabilityZone *AvailabilityZoneType `json:"availabilityZone,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + HighAvailabilityReplicaCount *int64 `json:"highAvailabilityReplicaCount,omitempty"` + LicenseType *ElasticPoolLicenseType `json:"licenseType,omitempty"` + MaintenanceConfigurationId *string `json:"maintenanceConfigurationId,omitempty"` + MaxSizeBytes *int64 `json:"maxSizeBytes,omitempty"` + MinCapacity *float64 `json:"minCapacity,omitempty"` + PerDatabaseSettings *ElasticPoolPerDatabaseSettings `json:"perDatabaseSettings,omitempty"` + PreferredEnclaveType *AlwaysEncryptedEnclaveType `json:"preferredEnclaveType,omitempty"` + State *ElasticPoolState `json:"state,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} + +func (o *ElasticPoolProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ElasticPoolProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdate.go b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdate.go new file mode 100644 index 00000000000..449dad1ba0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdate.go @@ -0,0 +1,10 @@ +package elasticpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolUpdate struct { + Properties *ElasticPoolUpdateProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdateproperties.go b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdateproperties.go new file mode 100644 index 00000000000..b2093a684dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/model_elasticpoolupdateproperties.go @@ -0,0 +1,17 @@ +package elasticpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolUpdateProperties struct { + AutoPauseDelay *int64 `json:"autoPauseDelay,omitempty"` + AvailabilityZone *AvailabilityZoneType `json:"availabilityZone,omitempty"` + HighAvailabilityReplicaCount *int64 `json:"highAvailabilityReplicaCount,omitempty"` + LicenseType *ElasticPoolLicenseType `json:"licenseType,omitempty"` + MaintenanceConfigurationId *string `json:"maintenanceConfigurationId,omitempty"` + MaxSizeBytes *int64 `json:"maxSizeBytes,omitempty"` + MinCapacity *float64 `json:"minCapacity,omitempty"` + PerDatabaseSettings *ElasticPoolPerDatabaseSettings `json:"perDatabaseSettings,omitempty"` + PreferredEnclaveType *AlwaysEncryptedEnclaveType `json:"preferredEnclaveType,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/model_sku.go b/resource-manager/sql/2023-08-01/elasticpools/model_sku.go new file mode 100644 index 00000000000..d3cf12d1c73 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/model_sku.go @@ -0,0 +1,12 @@ +package elasticpools + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/elasticpools/predicates.go b/resource-manager/sql/2023-08-01/elasticpools/predicates.go new file mode 100644 index 00000000000..baa6c2c92d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/predicates.go @@ -0,0 +1,37 @@ +package elasticpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ElasticPoolOperationPredicate) Matches(input ElasticPool) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/elasticpools/version.go b/resource-manager/sql/2023-08-01/elasticpools/version.go new file mode 100644 index 00000000000..b9b077aaec9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/elasticpools/version.go @@ -0,0 +1,10 @@ +package elasticpools + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/elasticpools/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/README.md b/resource-manager/sql/2023-08-01/encryptionprotectors/README.md new file mode 100644 index 00000000000..084598581b4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/encryptionprotectors` Documentation + +The `encryptionprotectors` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/encryptionprotectors" +``` + + +### Client Initialization + +```go +client := encryptionprotectors.NewEncryptionProtectorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EncryptionProtectorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := encryptionprotectors.EncryptionProtector{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EncryptionProtectorsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `EncryptionProtectorsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EncryptionProtectorsClient.Revalidate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +if err := client.RevalidateThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/client.go b/resource-manager/sql/2023-08-01/encryptionprotectors/client.go new file mode 100644 index 00000000000..f72697edceb --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/client.go @@ -0,0 +1,26 @@ +package encryptionprotectors + +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 EncryptionProtectorsClient struct { + Client *resourcemanager.Client +} + +func NewEncryptionProtectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*EncryptionProtectorsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "encryptionprotectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EncryptionProtectorsClient: %+v", err) + } + + return &EncryptionProtectorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/constants.go b/resource-manager/sql/2023-08-01/encryptionprotectors/constants.go new file mode 100644 index 00000000000..f798ffd8f32 --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/constants.go @@ -0,0 +1,51 @@ +package encryptionprotectors + +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 ServerKeyType string + +const ( + ServerKeyTypeAzureKeyVault ServerKeyType = "AzureKeyVault" + ServerKeyTypeServiceManaged ServerKeyType = "ServiceManaged" +) + +func PossibleValuesForServerKeyType() []string { + return []string{ + string(ServerKeyTypeAzureKeyVault), + string(ServerKeyTypeServiceManaged), + } +} + +func (s *ServerKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerKeyType(input string) (*ServerKeyType, error) { + vals := map[string]ServerKeyType{ + "azurekeyvault": ServerKeyTypeAzureKeyVault, + "servicemanaged": ServerKeyTypeServiceManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/method_createorupdate.go b/resource-manager/sql/2023-08-01/encryptionprotectors/method_createorupdate.go new file mode 100644 index 00000000000..91a71d0cd02 --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/method_createorupdate.go @@ -0,0 +1,76 @@ +package encryptionprotectors + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EncryptionProtector +} + +// CreateOrUpdate ... +func (c EncryptionProtectorsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input EncryptionProtector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/encryptionProtector/current", 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 EncryptionProtectorsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input EncryptionProtector) 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/sql/2023-08-01/encryptionprotectors/method_get.go b/resource-manager/sql/2023-08-01/encryptionprotectors/method_get.go new file mode 100644 index 00000000000..f1b561315dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/method_get.go @@ -0,0 +1,55 @@ +package encryptionprotectors + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EncryptionProtector +} + +// Get ... +func (c EncryptionProtectorsClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/encryptionProtector/current", 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 EncryptionProtector + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/method_listbyserver.go b/resource-manager/sql/2023-08-01/encryptionprotectors/method_listbyserver.go new file mode 100644 index 00000000000..f7ca51c7156 --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/method_listbyserver.go @@ -0,0 +1,106 @@ +package encryptionprotectors + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EncryptionProtector +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []EncryptionProtector +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c EncryptionProtectorsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/encryptionProtector", 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 *[]EncryptionProtector `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c EncryptionProtectorsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, EncryptionProtectorOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EncryptionProtectorsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate EncryptionProtectorOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]EncryptionProtector, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/method_revalidate.go b/resource-manager/sql/2023-08-01/encryptionprotectors/method_revalidate.go new file mode 100644 index 00000000000..2e1da00467e --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/method_revalidate.go @@ -0,0 +1,71 @@ +package encryptionprotectors + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RevalidateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Revalidate ... +func (c EncryptionProtectorsClient) Revalidate(ctx context.Context, id commonids.SqlServerId) (result RevalidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/encryptionProtector/current/revalidate", 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 +} + +// RevalidateThenPoll performs Revalidate then polls until it's completed +func (c EncryptionProtectorsClient) RevalidateThenPoll(ctx context.Context, id commonids.SqlServerId) error { + result, err := c.Revalidate(ctx, id) + if err != nil { + return fmt.Errorf("performing Revalidate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Revalidate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotector.go b/resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotector.go new file mode 100644 index 00000000000..48d530b87a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotector.go @@ -0,0 +1,13 @@ +package encryptionprotectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProtector struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EncryptionProtectorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotectorproperties.go b/resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotectorproperties.go new file mode 100644 index 00000000000..0511dedf4aa --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/model_encryptionprotectorproperties.go @@ -0,0 +1,13 @@ +package encryptionprotectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProtectorProperties struct { + AutoRotationEnabled *bool `json:"autoRotationEnabled,omitempty"` + ServerKeyName *string `json:"serverKeyName,omitempty"` + ServerKeyType ServerKeyType `json:"serverKeyType"` + Subregion *string `json:"subregion,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/encryptionprotectors/predicates.go b/resource-manager/sql/2023-08-01/encryptionprotectors/predicates.go new file mode 100644 index 00000000000..8ccad2732fb --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/predicates.go @@ -0,0 +1,37 @@ +package encryptionprotectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProtectorOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p EncryptionProtectorOperationPredicate) Matches(input EncryptionProtector) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/encryptionprotectors/version.go b/resource-manager/sql/2023-08-01/encryptionprotectors/version.go new file mode 100644 index 00000000000..cdef06d2343 --- /dev/null +++ b/resource-manager/sql/2023-08-01/encryptionprotectors/version.go @@ -0,0 +1,10 @@ +package encryptionprotectors + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/encryptionprotectors/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/README.md b/resource-manager/sql/2023-08-01/endpointcertificates/README.md new file mode 100644 index 00000000000..03a3b597343 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/endpointcertificates` Documentation + +The `endpointcertificates` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/endpointcertificates" +``` + + +### Client Initialization + +```go +client := endpointcertificates.NewEndpointCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EndpointCertificatesClient.Get` + +```go +ctx := context.TODO() +id := endpointcertificates.NewEndpointCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "endpointCertificateName") + +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: `EndpointCertificatesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/client.go b/resource-manager/sql/2023-08-01/endpointcertificates/client.go new file mode 100644 index 00000000000..d3524ab4566 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/client.go @@ -0,0 +1,26 @@ +package endpointcertificates + +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 EndpointCertificatesClient struct { + Client *resourcemanager.Client +} + +func NewEndpointCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*EndpointCertificatesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "endpointcertificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EndpointCertificatesClient: %+v", err) + } + + return &EndpointCertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate.go b/resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate.go new file mode 100644 index 00000000000..c08cbe18a55 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate.go @@ -0,0 +1,139 @@ +package endpointcertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&EndpointCertificateId{}) +} + +var _ resourceids.ResourceId = &EndpointCertificateId{} + +// EndpointCertificateId is a struct representing the Resource ID for a Endpoint Certificate +type EndpointCertificateId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + EndpointCertificateName string +} + +// NewEndpointCertificateID returns a new EndpointCertificateId struct +func NewEndpointCertificateID(subscriptionId string, resourceGroupName string, managedInstanceName string, endpointCertificateName string) EndpointCertificateId { + return EndpointCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + EndpointCertificateName: endpointCertificateName, + } +} + +// ParseEndpointCertificateID parses 'input' into a EndpointCertificateId +func ParseEndpointCertificateID(input string) (*EndpointCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEndpointCertificateIDInsensitively parses 'input' case-insensitively into a EndpointCertificateId +// note: this method should only be used for API response data and not user input +func ParseEndpointCertificateIDInsensitively(input string) (*EndpointCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&EndpointCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EndpointCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EndpointCertificateId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.EndpointCertificateName, ok = input.Parsed["endpointCertificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "endpointCertificateName", input) + } + + return nil +} + +// ValidateEndpointCertificateID checks that 'input' can be parsed as a Endpoint Certificate ID +func ValidateEndpointCertificateID(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 := ParseEndpointCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Endpoint Certificate ID +func (id EndpointCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/endpointCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.EndpointCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Endpoint Certificate ID +func (id EndpointCertificateId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticEndpointCertificates", "endpointCertificates", "endpointCertificates"), + resourceids.UserSpecifiedSegment("endpointCertificateName", "endpointCertificateName"), + } +} + +// String returns a human-readable description of this Endpoint Certificate ID +func (id EndpointCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Endpoint Certificate Name: %q", id.EndpointCertificateName), + } + return fmt.Sprintf("Endpoint Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate_test.go b/resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate_test.go new file mode 100644 index 00000000000..3b730994ea2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/id_endpointcertificate_test.go @@ -0,0 +1,327 @@ +package endpointcertificates + +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 = &EndpointCertificateId{} + +func TestNewEndpointCertificateID(t *testing.T) { + id := NewEndpointCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "endpointCertificateName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.EndpointCertificateName != "endpointCertificateName" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointCertificateName'", id.EndpointCertificateName, "endpointCertificateName") + } +} + +func TestFormatEndpointCertificateID(t *testing.T) { + actual := NewEndpointCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "endpointCertificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates/endpointCertificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEndpointCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointCertificateId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates/endpointCertificateName", + Expected: &EndpointCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + EndpointCertificateName: "endpointCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates/endpointCertificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointCertificateID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.EndpointCertificateName != v.Expected.EndpointCertificateName { + t.Fatalf("Expected %q but got %q for EndpointCertificateName", v.Expected.EndpointCertificateName, actual.EndpointCertificateName) + } + + } +} + +func TestParseEndpointCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EndpointCertificateId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/eNdPoInTcErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates/endpointCertificateName", + Expected: &EndpointCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + EndpointCertificateName: "endpointCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/endpointCertificates/endpointCertificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/eNdPoInTcErTiFiCaTeS/eNdPoInTcErTiFiCaTeNaMe", + Expected: &EndpointCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + EndpointCertificateName: "eNdPoInTcErTiFiCaTeNaMe", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/eNdPoInTcErTiFiCaTeS/eNdPoInTcErTiFiCaTeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEndpointCertificateIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.EndpointCertificateName != v.Expected.EndpointCertificateName { + t.Fatalf("Expected %q but got %q for EndpointCertificateName", v.Expected.EndpointCertificateName, actual.EndpointCertificateName) + } + + } +} + +func TestSegmentsForEndpointCertificateId(t *testing.T) { + segments := EndpointCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EndpointCertificateId 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/sql/2023-08-01/endpointcertificates/method_get.go b/resource-manager/sql/2023-08-01/endpointcertificates/method_get.go new file mode 100644 index 00000000000..dfe976af079 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/method_get.go @@ -0,0 +1,53 @@ +package endpointcertificates + +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 *EndpointCertificate +} + +// Get ... +func (c EndpointCertificatesClient) Get(ctx context.Context, id EndpointCertificateId) (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 EndpointCertificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/method_listbyinstance.go b/resource-manager/sql/2023-08-01/endpointcertificates/method_listbyinstance.go new file mode 100644 index 00000000000..d7097ee92a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/method_listbyinstance.go @@ -0,0 +1,106 @@ +package endpointcertificates + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EndpointCertificate +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []EndpointCertificate +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c EndpointCertificatesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/endpointCertificates", 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 *[]EndpointCertificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c EndpointCertificatesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, EndpointCertificateOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EndpointCertificatesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate EndpointCertificateOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]EndpointCertificate, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificate.go b/resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificate.go new file mode 100644 index 00000000000..7404c259540 --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificate.go @@ -0,0 +1,11 @@ +package endpointcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EndpointCertificateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificateproperties.go b/resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificateproperties.go new file mode 100644 index 00000000000..b78448a5a9e --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/model_endpointcertificateproperties.go @@ -0,0 +1,8 @@ +package endpointcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointCertificateProperties struct { + PublicBlob *string `json:"publicBlob,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/endpointcertificates/predicates.go b/resource-manager/sql/2023-08-01/endpointcertificates/predicates.go new file mode 100644 index 00000000000..d8ebdc5270e --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/predicates.go @@ -0,0 +1,27 @@ +package endpointcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointCertificateOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EndpointCertificateOperationPredicate) Matches(input EndpointCertificate) 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/sql/2023-08-01/endpointcertificates/version.go b/resource-manager/sql/2023-08-01/endpointcertificates/version.go new file mode 100644 index 00000000000..ecf0f325eee --- /dev/null +++ b/resource-manager/sql/2023-08-01/endpointcertificates/version.go @@ -0,0 +1,10 @@ +package endpointcertificates + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/endpointcertificates/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/README.md b/resource-manager/sql/2023-08-01/failovergroups/README.md new file mode 100644 index 00000000000..0a96e57ea7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/README.md @@ -0,0 +1,136 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/failovergroups` Documentation + +The `failovergroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/failovergroups" +``` + + +### Client Initialization + +```go +client := failovergroups.NewFailoverGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FailoverGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +payload := failovergroups.FailoverGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `FailoverGroupsClient.Delete` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FailoverGroupsClient.Failover` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +if err := client.FailoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FailoverGroupsClient.ForceFailoverAllowDataLoss` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +if err := client.ForceFailoverAllowDataLossThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FailoverGroupsClient.Get` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +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: `FailoverGroupsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `FailoverGroupsClient.TryPlannedBeforeForcedFailover` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +if err := client.TryPlannedBeforeForcedFailoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FailoverGroupsClient.Update` + +```go +ctx := context.TODO() +id := failovergroups.NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + +payload := failovergroups.FailoverGroupUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/failovergroups/client.go b/resource-manager/sql/2023-08-01/failovergroups/client.go new file mode 100644 index 00000000000..2ea4965a0c0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/client.go @@ -0,0 +1,26 @@ +package failovergroups + +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 FailoverGroupsClient struct { + Client *resourcemanager.Client +} + +func NewFailoverGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*FailoverGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "failovergroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FailoverGroupsClient: %+v", err) + } + + return &FailoverGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/constants.go b/resource-manager/sql/2023-08-01/failovergroups/constants.go new file mode 100644 index 00000000000..e40ab43bb0b --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/constants.go @@ -0,0 +1,174 @@ +package failovergroups + +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 FailoverGroupDatabasesSecondaryType string + +const ( + FailoverGroupDatabasesSecondaryTypeGeo FailoverGroupDatabasesSecondaryType = "Geo" + FailoverGroupDatabasesSecondaryTypeStandby FailoverGroupDatabasesSecondaryType = "Standby" +) + +func PossibleValuesForFailoverGroupDatabasesSecondaryType() []string { + return []string{ + string(FailoverGroupDatabasesSecondaryTypeGeo), + string(FailoverGroupDatabasesSecondaryTypeStandby), + } +} + +func (s *FailoverGroupDatabasesSecondaryType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFailoverGroupDatabasesSecondaryType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFailoverGroupDatabasesSecondaryType(input string) (*FailoverGroupDatabasesSecondaryType, error) { + vals := map[string]FailoverGroupDatabasesSecondaryType{ + "geo": FailoverGroupDatabasesSecondaryTypeGeo, + "standby": FailoverGroupDatabasesSecondaryTypeStandby, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FailoverGroupDatabasesSecondaryType(input) + return &out, nil +} + +type FailoverGroupReplicationRole string + +const ( + FailoverGroupReplicationRolePrimary FailoverGroupReplicationRole = "Primary" + FailoverGroupReplicationRoleSecondary FailoverGroupReplicationRole = "Secondary" +) + +func PossibleValuesForFailoverGroupReplicationRole() []string { + return []string{ + string(FailoverGroupReplicationRolePrimary), + string(FailoverGroupReplicationRoleSecondary), + } +} + +func (s *FailoverGroupReplicationRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFailoverGroupReplicationRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFailoverGroupReplicationRole(input string) (*FailoverGroupReplicationRole, error) { + vals := map[string]FailoverGroupReplicationRole{ + "primary": FailoverGroupReplicationRolePrimary, + "secondary": FailoverGroupReplicationRoleSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FailoverGroupReplicationRole(input) + return &out, nil +} + +type ReadOnlyEndpointFailoverPolicy string + +const ( + ReadOnlyEndpointFailoverPolicyDisabled ReadOnlyEndpointFailoverPolicy = "Disabled" + ReadOnlyEndpointFailoverPolicyEnabled ReadOnlyEndpointFailoverPolicy = "Enabled" +) + +func PossibleValuesForReadOnlyEndpointFailoverPolicy() []string { + return []string{ + string(ReadOnlyEndpointFailoverPolicyDisabled), + string(ReadOnlyEndpointFailoverPolicyEnabled), + } +} + +func (s *ReadOnlyEndpointFailoverPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReadOnlyEndpointFailoverPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReadOnlyEndpointFailoverPolicy(input string) (*ReadOnlyEndpointFailoverPolicy, error) { + vals := map[string]ReadOnlyEndpointFailoverPolicy{ + "disabled": ReadOnlyEndpointFailoverPolicyDisabled, + "enabled": ReadOnlyEndpointFailoverPolicyEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReadOnlyEndpointFailoverPolicy(input) + return &out, nil +} + +type ReadWriteEndpointFailoverPolicy string + +const ( + ReadWriteEndpointFailoverPolicyAutomatic ReadWriteEndpointFailoverPolicy = "Automatic" + ReadWriteEndpointFailoverPolicyManual ReadWriteEndpointFailoverPolicy = "Manual" +) + +func PossibleValuesForReadWriteEndpointFailoverPolicy() []string { + return []string{ + string(ReadWriteEndpointFailoverPolicyAutomatic), + string(ReadWriteEndpointFailoverPolicyManual), + } +} + +func (s *ReadWriteEndpointFailoverPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReadWriteEndpointFailoverPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReadWriteEndpointFailoverPolicy(input string) (*ReadWriteEndpointFailoverPolicy, error) { + vals := map[string]ReadWriteEndpointFailoverPolicy{ + "automatic": ReadWriteEndpointFailoverPolicyAutomatic, + "manual": ReadWriteEndpointFailoverPolicyManual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReadWriteEndpointFailoverPolicy(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/id_failovergroup.go b/resource-manager/sql/2023-08-01/failovergroups/id_failovergroup.go new file mode 100644 index 00000000000..05603ab0287 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/id_failovergroup.go @@ -0,0 +1,139 @@ +package failovergroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FailoverGroupId{}) +} + +var _ resourceids.ResourceId = &FailoverGroupId{} + +// FailoverGroupId is a struct representing the Resource ID for a Failover Group +type FailoverGroupId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + FailoverGroupName string +} + +// NewFailoverGroupID returns a new FailoverGroupId struct +func NewFailoverGroupID(subscriptionId string, resourceGroupName string, serverName string, failoverGroupName string) FailoverGroupId { + return FailoverGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + FailoverGroupName: failoverGroupName, + } +} + +// ParseFailoverGroupID parses 'input' into a FailoverGroupId +func ParseFailoverGroupID(input string) (*FailoverGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&FailoverGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FailoverGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFailoverGroupIDInsensitively parses 'input' case-insensitively into a FailoverGroupId +// note: this method should only be used for API response data and not user input +func ParseFailoverGroupIDInsensitively(input string) (*FailoverGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&FailoverGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FailoverGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FailoverGroupId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.FailoverGroupName, ok = input.Parsed["failoverGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "failoverGroupName", input) + } + + return nil +} + +// ValidateFailoverGroupID checks that 'input' can be parsed as a Failover Group ID +func ValidateFailoverGroupID(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 := ParseFailoverGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Failover Group ID +func (id FailoverGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/failoverGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.FailoverGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Failover Group ID +func (id FailoverGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticFailoverGroups", "failoverGroups", "failoverGroups"), + resourceids.UserSpecifiedSegment("failoverGroupName", "failoverGroupName"), + } +} + +// String returns a human-readable description of this Failover Group ID +func (id FailoverGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Failover Group Name: %q", id.FailoverGroupName), + } + return fmt.Sprintf("Failover Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/id_failovergroup_test.go b/resource-manager/sql/2023-08-01/failovergroups/id_failovergroup_test.go new file mode 100644 index 00000000000..0edb09580af --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/id_failovergroup_test.go @@ -0,0 +1,327 @@ +package failovergroups + +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 = &FailoverGroupId{} + +func TestNewFailoverGroupID(t *testing.T) { + id := NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.FailoverGroupName != "failoverGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'FailoverGroupName'", id.FailoverGroupName, "failoverGroupName") + } +} + +func TestFormatFailoverGroupID(t *testing.T) { + actual := NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "failoverGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups/failoverGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFailoverGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FailoverGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups/failoverGroupName", + Expected: &FailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + FailoverGroupName: "failoverGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups/failoverGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFailoverGroupID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.FailoverGroupName != v.Expected.FailoverGroupName { + t.Fatalf("Expected %q but got %q for FailoverGroupName", v.Expected.FailoverGroupName, actual.FailoverGroupName) + } + + } +} + +func TestParseFailoverGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FailoverGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/fAiLoVeRgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups/failoverGroupName", + Expected: &FailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + FailoverGroupName: "failoverGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/failoverGroups/failoverGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/fAiLoVeRgRoUpS/fAiLoVeRgRoUpNaMe", + Expected: &FailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + FailoverGroupName: "fAiLoVeRgRoUpNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/fAiLoVeRgRoUpS/fAiLoVeRgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFailoverGroupIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.FailoverGroupName != v.Expected.FailoverGroupName { + t.Fatalf("Expected %q but got %q for FailoverGroupName", v.Expected.FailoverGroupName, actual.FailoverGroupName) + } + + } +} + +func TestSegmentsForFailoverGroupId(t *testing.T) { + segments := FailoverGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FailoverGroupId 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/sql/2023-08-01/failovergroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/failovergroups/method_createorupdate.go new file mode 100644 index 00000000000..945fef80170 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_createorupdate.go @@ -0,0 +1,76 @@ +package failovergroups + +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 *FailoverGroup +} + +// CreateOrUpdate ... +func (c FailoverGroupsClient) CreateOrUpdate(ctx context.Context, id FailoverGroupId, input FailoverGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 FailoverGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id FailoverGroupId, input FailoverGroup) 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/sql/2023-08-01/failovergroups/method_delete.go b/resource-manager/sql/2023-08-01/failovergroups/method_delete.go new file mode 100644 index 00000000000..6815bb47a0a --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_delete.go @@ -0,0 +1,71 @@ +package failovergroups + +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 FailoverGroupsClient) Delete(ctx context.Context, id FailoverGroupId) (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 FailoverGroupsClient) DeleteThenPoll(ctx context.Context, id FailoverGroupId) 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/sql/2023-08-01/failovergroups/method_failover.go b/resource-manager/sql/2023-08-01/failovergroups/method_failover.go new file mode 100644 index 00000000000..96a60e32163 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_failover.go @@ -0,0 +1,71 @@ +package failovergroups + +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 FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *FailoverGroup +} + +// Failover ... +func (c FailoverGroupsClient) Failover(ctx context.Context, id FailoverGroupId) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c FailoverGroupsClient) FailoverThenPoll(ctx context.Context, id FailoverGroupId) error { + result, err := c.Failover(ctx, id) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/method_forcefailoverallowdataloss.go b/resource-manager/sql/2023-08-01/failovergroups/method_forcefailoverallowdataloss.go new file mode 100644 index 00000000000..faac1fb72a3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_forcefailoverallowdataloss.go @@ -0,0 +1,71 @@ +package failovergroups + +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 ForceFailoverAllowDataLossOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *FailoverGroup +} + +// ForceFailoverAllowDataLoss ... +func (c FailoverGroupsClient) ForceFailoverAllowDataLoss(ctx context.Context, id FailoverGroupId) (result ForceFailoverAllowDataLossOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceFailoverAllowDataLoss", 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 +} + +// ForceFailoverAllowDataLossThenPoll performs ForceFailoverAllowDataLoss then polls until it's completed +func (c FailoverGroupsClient) ForceFailoverAllowDataLossThenPoll(ctx context.Context, id FailoverGroupId) error { + result, err := c.ForceFailoverAllowDataLoss(ctx, id) + if err != nil { + return fmt.Errorf("performing ForceFailoverAllowDataLoss: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ForceFailoverAllowDataLoss: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/method_get.go b/resource-manager/sql/2023-08-01/failovergroups/method_get.go new file mode 100644 index 00000000000..61d249dd805 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_get.go @@ -0,0 +1,53 @@ +package failovergroups + +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 *FailoverGroup +} + +// Get ... +func (c FailoverGroupsClient) Get(ctx context.Context, id FailoverGroupId) (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 FailoverGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/method_listbyserver.go b/resource-manager/sql/2023-08-01/failovergroups/method_listbyserver.go new file mode 100644 index 00000000000..100e1a498b9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_listbyserver.go @@ -0,0 +1,106 @@ +package failovergroups + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]FailoverGroup +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []FailoverGroup +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c FailoverGroupsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/failoverGroups", 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 *[]FailoverGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c FailoverGroupsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, FailoverGroupOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FailoverGroupsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate FailoverGroupOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]FailoverGroup, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/method_tryplannedbeforeforcedfailover.go b/resource-manager/sql/2023-08-01/failovergroups/method_tryplannedbeforeforcedfailover.go new file mode 100644 index 00000000000..7416b501757 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_tryplannedbeforeforcedfailover.go @@ -0,0 +1,71 @@ +package failovergroups + +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 TryPlannedBeforeForcedFailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *FailoverGroup +} + +// TryPlannedBeforeForcedFailover ... +func (c FailoverGroupsClient) TryPlannedBeforeForcedFailover(ctx context.Context, id FailoverGroupId) (result TryPlannedBeforeForcedFailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/tryPlannedBeforeForcedFailover", 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 +} + +// TryPlannedBeforeForcedFailoverThenPoll performs TryPlannedBeforeForcedFailover then polls until it's completed +func (c FailoverGroupsClient) TryPlannedBeforeForcedFailoverThenPoll(ctx context.Context, id FailoverGroupId) error { + result, err := c.TryPlannedBeforeForcedFailover(ctx, id) + if err != nil { + return fmt.Errorf("performing TryPlannedBeforeForcedFailover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TryPlannedBeforeForcedFailover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/method_update.go b/resource-manager/sql/2023-08-01/failovergroups/method_update.go new file mode 100644 index 00000000000..a50d8173831 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/method_update.go @@ -0,0 +1,75 @@ +package failovergroups + +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 *FailoverGroup +} + +// Update ... +func (c FailoverGroupsClient) Update(ctx context.Context, id FailoverGroupId, input FailoverGroupUpdate) (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 FailoverGroupsClient) UpdateThenPoll(ctx context.Context, id FailoverGroupId, input FailoverGroupUpdate) 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/sql/2023-08-01/failovergroups/model_failovergroup.go b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroup.go new file mode 100644 index 00000000000..bf4083437c2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroup.go @@ -0,0 +1,13 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroup struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *FailoverGroupProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupproperties.go b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupproperties.go new file mode 100644 index 00000000000..b22786bcf59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupproperties.go @@ -0,0 +1,14 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroupProperties struct { + Databases *[]string `json:"databases,omitempty"` + PartnerServers []PartnerInfo `json:"partnerServers"` + ReadOnlyEndpoint *FailoverGroupReadOnlyEndpoint `json:"readOnlyEndpoint,omitempty"` + ReadWriteEndpoint FailoverGroupReadWriteEndpoint `json:"readWriteEndpoint"` + ReplicationRole *FailoverGroupReplicationRole `json:"replicationRole,omitempty"` + ReplicationState *string `json:"replicationState,omitempty"` + SecondaryType *FailoverGroupDatabasesSecondaryType `json:"secondaryType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadonlyendpoint.go b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadonlyendpoint.go new file mode 100644 index 00000000000..d5fb08f6725 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadonlyendpoint.go @@ -0,0 +1,9 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroupReadOnlyEndpoint struct { + FailoverPolicy *ReadOnlyEndpointFailoverPolicy `json:"failoverPolicy,omitempty"` + TargetServer *string `json:"targetServer,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadwriteendpoint.go b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadwriteendpoint.go new file mode 100644 index 00000000000..a1e7d7b4510 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupreadwriteendpoint.go @@ -0,0 +1,9 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroupReadWriteEndpoint struct { + FailoverPolicy ReadWriteEndpointFailoverPolicy `json:"failoverPolicy"` + FailoverWithDataLossGracePeriodMinutes *int64 `json:"failoverWithDataLossGracePeriodMinutes,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdate.go b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdate.go new file mode 100644 index 00000000000..8181ff48639 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdate.go @@ -0,0 +1,9 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroupUpdate struct { + Properties *FailoverGroupUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdateproperties.go b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdateproperties.go new file mode 100644 index 00000000000..3202bb694bd --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_failovergroupupdateproperties.go @@ -0,0 +1,12 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroupUpdateProperties struct { + Databases *[]string `json:"databases,omitempty"` + PartnerServers *[]PartnerInfo `json:"partnerServers,omitempty"` + ReadOnlyEndpoint *FailoverGroupReadOnlyEndpoint `json:"readOnlyEndpoint,omitempty"` + ReadWriteEndpoint *FailoverGroupReadWriteEndpoint `json:"readWriteEndpoint,omitempty"` + SecondaryType *FailoverGroupDatabasesSecondaryType `json:"secondaryType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/model_partnerinfo.go b/resource-manager/sql/2023-08-01/failovergroups/model_partnerinfo.go new file mode 100644 index 00000000000..2fb7de037de --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/model_partnerinfo.go @@ -0,0 +1,10 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerInfo struct { + Id string `json:"id"` + Location *string `json:"location,omitempty"` + ReplicationRole *FailoverGroupReplicationRole `json:"replicationRole,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/failovergroups/predicates.go b/resource-manager/sql/2023-08-01/failovergroups/predicates.go new file mode 100644 index 00000000000..bba27fb4d10 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/predicates.go @@ -0,0 +1,32 @@ +package failovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverGroupOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p FailoverGroupOperationPredicate) Matches(input FailoverGroup) 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/sql/2023-08-01/failovergroups/version.go b/resource-manager/sql/2023-08-01/failovergroups/version.go new file mode 100644 index 00000000000..a91f87f30b1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/failovergroups/version.go @@ -0,0 +1,10 @@ +package failovergroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/failovergroups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/README.md b/resource-manager/sql/2023-08-01/firewallrules/README.md new file mode 100644 index 00000000000..681ed0be70d --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/README.md @@ -0,0 +1,112 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/firewallrules` Documentation + +The `firewallrules` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/firewallrules" +``` + + +### Client Initialization + +```go +client := firewallrules.NewFirewallRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FirewallRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "firewallRuleName") + +payload := firewallrules.FirewallRule{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `FirewallRulesClient.Delete` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "firewallRuleName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `FirewallRulesClient.Get` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "firewallRuleName") + +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: `FirewallRulesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `FirewallRulesClient.Replace` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := firewallrules.FirewallRuleList{ + // ... +} + + +read, err := client.Replace(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/sql/2023-08-01/firewallrules/client.go b/resource-manager/sql/2023-08-01/firewallrules/client.go new file mode 100644 index 00000000000..5ecd222a8c7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/client.go @@ -0,0 +1,26 @@ +package firewallrules + +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 FirewallRulesClient struct { + Client *resourcemanager.Client +} + +func NewFirewallRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*FirewallRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "firewallrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FirewallRulesClient: %+v", err) + } + + return &FirewallRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/id_firewallrule.go b/resource-manager/sql/2023-08-01/firewallrules/id_firewallrule.go new file mode 100644 index 00000000000..c35d061d813 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/id_firewallrule.go @@ -0,0 +1,139 @@ +package firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FirewallRuleId{}) +} + +var _ resourceids.ResourceId = &FirewallRuleId{} + +// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule +type FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + FirewallRuleName string +} + +// NewFirewallRuleID returns a new FirewallRuleId struct +func NewFirewallRuleID(subscriptionId string, resourceGroupName string, serverName string, firewallRuleName string) FirewallRuleId { + return FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + FirewallRuleName: firewallRuleName, + } +} + +// ParseFirewallRuleID parses 'input' into a FirewallRuleId +func ParseFirewallRuleID(input string) (*FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&FirewallRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FirewallRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFirewallRuleIDInsensitively parses 'input' case-insensitively into a FirewallRuleId +// note: this method should only be used for API response data and not user input +func ParseFirewallRuleIDInsensitively(input string) (*FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&FirewallRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FirewallRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FirewallRuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.FirewallRuleName, ok = input.Parsed["firewallRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "firewallRuleName", input) + } + + return nil +} + +// ValidateFirewallRuleID checks that 'input' can be parsed as a Firewall Rule ID +func ValidateFirewallRuleID(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 := ParseFirewallRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Firewall Rule ID +func (id FirewallRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/firewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.FirewallRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Firewall Rule ID +func (id FirewallRuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), + resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleName"), + } +} + +// String returns a human-readable description of this Firewall Rule ID +func (id FirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), + } + return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/id_firewallrule_test.go b/resource-manager/sql/2023-08-01/firewallrules/id_firewallrule_test.go new file mode 100644 index 00000000000..26d96f3841a --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/id_firewallrule_test.go @@ -0,0 +1,327 @@ +package firewallrules + +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 = &FirewallRuleId{} + +func TestNewFirewallRuleID(t *testing.T) { + id := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "firewallRuleName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.FirewallRuleName != "firewallRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleName") + } +} + +func TestFormatFirewallRuleID(t *testing.T) { + actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "firewallRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules/firewallRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules/firewallRuleName", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + FirewallRuleName: "firewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules/firewallRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.FirewallRuleName != v.Expected.FirewallRuleName { + t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) + } + + } +} + +func TestParseFirewallRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules/firewallRuleName", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + FirewallRuleName: "firewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/firewallRules/firewallRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/fIrEwAlLrUlEs/fIrEwAlLrUlEnAmE", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + FirewallRuleName: "fIrEwAlLrUlEnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/fIrEwAlLrUlEs/fIrEwAlLrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.FirewallRuleName != v.Expected.FirewallRuleName { + t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) + } + + } +} + +func TestSegmentsForFirewallRuleId(t *testing.T) { + segments := FirewallRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FirewallRuleId 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/sql/2023-08-01/firewallrules/method_createorupdate.go b/resource-manager/sql/2023-08-01/firewallrules/method_createorupdate.go new file mode 100644 index 00000000000..a122b14e4d9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/method_createorupdate.go @@ -0,0 +1,58 @@ +package firewallrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FirewallRule +} + +// CreateOrUpdate ... +func (c FirewallRulesClient) CreateOrUpdate(ctx context.Context, id FirewallRuleId, input FirewallRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model FirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/method_delete.go b/resource-manager/sql/2023-08-01/firewallrules/method_delete.go new file mode 100644 index 00000000000..9ba8c05de2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/method_delete.go @@ -0,0 +1,47 @@ +package firewallrules + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c FirewallRulesClient) Delete(ctx context.Context, id FirewallRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/method_get.go b/resource-manager/sql/2023-08-01/firewallrules/method_get.go new file mode 100644 index 00000000000..6b53b2919c9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/method_get.go @@ -0,0 +1,53 @@ +package firewallrules + +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 *FirewallRule +} + +// Get ... +func (c FirewallRulesClient) Get(ctx context.Context, id FirewallRuleId) (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 FirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/method_listbyserver.go b/resource-manager/sql/2023-08-01/firewallrules/method_listbyserver.go new file mode 100644 index 00000000000..aa03997e638 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/method_listbyserver.go @@ -0,0 +1,106 @@ +package firewallrules + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]FirewallRule +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []FirewallRule +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c FirewallRulesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/firewallRules", 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 *[]FirewallRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c FirewallRulesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, FirewallRuleOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FirewallRulesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate FirewallRuleOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]FirewallRule, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/method_replace.go b/resource-manager/sql/2023-08-01/firewallrules/method_replace.go new file mode 100644 index 00000000000..97cafcd2e7a --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/method_replace.go @@ -0,0 +1,60 @@ +package firewallrules + +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 ReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *FirewallRule +} + +// Replace ... +func (c FirewallRulesClient) Replace(ctx context.Context, id commonids.SqlServerId, input FirewallRuleList) (result ReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/firewallRules", 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 FirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/model_firewallrule.go b/resource-manager/sql/2023-08-01/firewallrules/model_firewallrule.go new file mode 100644 index 00000000000..d8f3c305e78 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/model_firewallrule.go @@ -0,0 +1,11 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerFirewallRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/model_firewallrulelist.go b/resource-manager/sql/2023-08-01/firewallrules/model_firewallrulelist.go new file mode 100644 index 00000000000..f7baf79f2af --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/model_firewallrulelist.go @@ -0,0 +1,8 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRuleList struct { + Values *[]FirewallRule `json:"values,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/model_serverfirewallruleproperties.go b/resource-manager/sql/2023-08-01/firewallrules/model_serverfirewallruleproperties.go new file mode 100644 index 00000000000..328206f5241 --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/model_serverfirewallruleproperties.go @@ -0,0 +1,9 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerFirewallRuleProperties struct { + EndIPAddress *string `json:"endIpAddress,omitempty"` + StartIPAddress *string `json:"startIpAddress,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/firewallrules/predicates.go b/resource-manager/sql/2023-08-01/firewallrules/predicates.go new file mode 100644 index 00000000000..fb7011b1d3b --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/predicates.go @@ -0,0 +1,27 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p FirewallRuleOperationPredicate) Matches(input FirewallRule) 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/sql/2023-08-01/firewallrules/version.go b/resource-manager/sql/2023-08-01/firewallrules/version.go new file mode 100644 index 00000000000..094095d713d --- /dev/null +++ b/resource-manager/sql/2023-08-01/firewallrules/version.go @@ -0,0 +1,10 @@ +package firewallrules + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/firewallrules/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/README.md b/resource-manager/sql/2023-08-01/geobackuppolicies/README.md new file mode 100644 index 00000000000..f63a61f5df0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/geobackuppolicies` Documentation + +The `geobackuppolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/geobackuppolicies" +``` + + +### Client Initialization + +```go +client := geobackuppolicies.NewGeoBackupPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GeoBackupPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := geobackuppolicies.GeoBackupPolicy{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GeoBackupPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `GeoBackupPoliciesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/client.go b/resource-manager/sql/2023-08-01/geobackuppolicies/client.go new file mode 100644 index 00000000000..bef6b615722 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/client.go @@ -0,0 +1,26 @@ +package geobackuppolicies + +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 GeoBackupPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewGeoBackupPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*GeoBackupPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "geobackuppolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GeoBackupPoliciesClient: %+v", err) + } + + return &GeoBackupPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/constants.go b/resource-manager/sql/2023-08-01/geobackuppolicies/constants.go new file mode 100644 index 00000000000..d66c0d850af --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/constants.go @@ -0,0 +1,51 @@ +package geobackuppolicies + +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 GeoBackupPolicyState string + +const ( + GeoBackupPolicyStateDisabled GeoBackupPolicyState = "Disabled" + GeoBackupPolicyStateEnabled GeoBackupPolicyState = "Enabled" +) + +func PossibleValuesForGeoBackupPolicyState() []string { + return []string{ + string(GeoBackupPolicyStateDisabled), + string(GeoBackupPolicyStateEnabled), + } +} + +func (s *GeoBackupPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGeoBackupPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGeoBackupPolicyState(input string) (*GeoBackupPolicyState, error) { + vals := map[string]GeoBackupPolicyState{ + "disabled": GeoBackupPolicyStateDisabled, + "enabled": GeoBackupPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GeoBackupPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/geobackuppolicies/method_createorupdate.go new file mode 100644 index 00000000000..d329ea74a15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/method_createorupdate.go @@ -0,0 +1,60 @@ +package geobackuppolicies + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GeoBackupPolicy +} + +// CreateOrUpdate ... +func (c GeoBackupPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input GeoBackupPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/geoBackupPolicies/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 GeoBackupPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/method_get.go b/resource-manager/sql/2023-08-01/geobackuppolicies/method_get.go new file mode 100644 index 00000000000..8a37d55fda5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/method_get.go @@ -0,0 +1,55 @@ +package geobackuppolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GeoBackupPolicy +} + +// Get ... +func (c GeoBackupPoliciesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/geoBackupPolicies/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 GeoBackupPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/method_list.go b/resource-manager/sql/2023-08-01/geobackuppolicies/method_list.go new file mode 100644 index 00000000000..d44abba7a39 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/method_list.go @@ -0,0 +1,106 @@ +package geobackuppolicies + +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 *[]GeoBackupPolicy +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GeoBackupPolicy +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c GeoBackupPoliciesClient) List(ctx context.Context, id commonids.SqlDatabaseId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/geoBackupPolicies", 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 *[]GeoBackupPolicy `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 GeoBackupPoliciesClient) ListComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, GeoBackupPolicyOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GeoBackupPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate GeoBackupPolicyOperationPredicate) (result ListCompleteResult, err error) { + items := make([]GeoBackupPolicy, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicy.go b/resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicy.go new file mode 100644 index 00000000000..b258a5e0ae5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicy.go @@ -0,0 +1,13 @@ +package geobackuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GeoBackupPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicyproperties.go b/resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicyproperties.go new file mode 100644 index 00000000000..55f98c04134 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/model_geobackuppolicyproperties.go @@ -0,0 +1,9 @@ +package geobackuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicyProperties struct { + State GeoBackupPolicyState `json:"state"` + StorageType *string `json:"storageType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/geobackuppolicies/predicates.go b/resource-manager/sql/2023-08-01/geobackuppolicies/predicates.go new file mode 100644 index 00000000000..fceb42b3214 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/predicates.go @@ -0,0 +1,37 @@ +package geobackuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicyOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p GeoBackupPolicyOperationPredicate) Matches(input GeoBackupPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/geobackuppolicies/version.go b/resource-manager/sql/2023-08-01/geobackuppolicies/version.go new file mode 100644 index 00000000000..e6334b86508 --- /dev/null +++ b/resource-manager/sql/2023-08-01/geobackuppolicies/version.go @@ -0,0 +1,10 @@ +package geobackuppolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/geobackuppolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/README.md b/resource-manager/sql/2023-08-01/instancefailovergroups/README.md new file mode 100644 index 00000000000..84ae5196def --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/instancefailovergroups` Documentation + +The `instancefailovergroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/instancefailovergroups" +``` + + +### Client Initialization + +```go +client := instancefailovergroups.NewInstanceFailoverGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `InstanceFailoverGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := instancefailovergroups.NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName") + +payload := instancefailovergroups.InstanceFailoverGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `InstanceFailoverGroupsClient.Delete` + +```go +ctx := context.TODO() +id := instancefailovergroups.NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `InstanceFailoverGroupsClient.Failover` + +```go +ctx := context.TODO() +id := instancefailovergroups.NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName") + +if err := client.FailoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `InstanceFailoverGroupsClient.ForceFailoverAllowDataLoss` + +```go +ctx := context.TODO() +id := instancefailovergroups.NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName") + +if err := client.ForceFailoverAllowDataLossThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `InstanceFailoverGroupsClient.Get` + +```go +ctx := context.TODO() +id := instancefailovergroups.NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName") + +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: `InstanceFailoverGroupsClient.ListByLocation` + +```go +ctx := context.TODO() +id := instancefailovergroups.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/client.go b/resource-manager/sql/2023-08-01/instancefailovergroups/client.go new file mode 100644 index 00000000000..32dba8d6339 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/client.go @@ -0,0 +1,26 @@ +package instancefailovergroups + +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 InstanceFailoverGroupsClient struct { + Client *resourcemanager.Client +} + +func NewInstanceFailoverGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*InstanceFailoverGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "instancefailovergroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating InstanceFailoverGroupsClient: %+v", err) + } + + return &InstanceFailoverGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/constants.go b/resource-manager/sql/2023-08-01/instancefailovergroups/constants.go new file mode 100644 index 00000000000..bada7a8e899 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/constants.go @@ -0,0 +1,174 @@ +package instancefailovergroups + +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 InstanceFailoverGroupReplicationRole string + +const ( + InstanceFailoverGroupReplicationRolePrimary InstanceFailoverGroupReplicationRole = "Primary" + InstanceFailoverGroupReplicationRoleSecondary InstanceFailoverGroupReplicationRole = "Secondary" +) + +func PossibleValuesForInstanceFailoverGroupReplicationRole() []string { + return []string{ + string(InstanceFailoverGroupReplicationRolePrimary), + string(InstanceFailoverGroupReplicationRoleSecondary), + } +} + +func (s *InstanceFailoverGroupReplicationRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInstanceFailoverGroupReplicationRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInstanceFailoverGroupReplicationRole(input string) (*InstanceFailoverGroupReplicationRole, error) { + vals := map[string]InstanceFailoverGroupReplicationRole{ + "primary": InstanceFailoverGroupReplicationRolePrimary, + "secondary": InstanceFailoverGroupReplicationRoleSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InstanceFailoverGroupReplicationRole(input) + return &out, nil +} + +type ReadOnlyEndpointFailoverPolicy string + +const ( + ReadOnlyEndpointFailoverPolicyDisabled ReadOnlyEndpointFailoverPolicy = "Disabled" + ReadOnlyEndpointFailoverPolicyEnabled ReadOnlyEndpointFailoverPolicy = "Enabled" +) + +func PossibleValuesForReadOnlyEndpointFailoverPolicy() []string { + return []string{ + string(ReadOnlyEndpointFailoverPolicyDisabled), + string(ReadOnlyEndpointFailoverPolicyEnabled), + } +} + +func (s *ReadOnlyEndpointFailoverPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReadOnlyEndpointFailoverPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReadOnlyEndpointFailoverPolicy(input string) (*ReadOnlyEndpointFailoverPolicy, error) { + vals := map[string]ReadOnlyEndpointFailoverPolicy{ + "disabled": ReadOnlyEndpointFailoverPolicyDisabled, + "enabled": ReadOnlyEndpointFailoverPolicyEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReadOnlyEndpointFailoverPolicy(input) + return &out, nil +} + +type ReadWriteEndpointFailoverPolicy string + +const ( + ReadWriteEndpointFailoverPolicyAutomatic ReadWriteEndpointFailoverPolicy = "Automatic" + ReadWriteEndpointFailoverPolicyManual ReadWriteEndpointFailoverPolicy = "Manual" +) + +func PossibleValuesForReadWriteEndpointFailoverPolicy() []string { + return []string{ + string(ReadWriteEndpointFailoverPolicyAutomatic), + string(ReadWriteEndpointFailoverPolicyManual), + } +} + +func (s *ReadWriteEndpointFailoverPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReadWriteEndpointFailoverPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReadWriteEndpointFailoverPolicy(input string) (*ReadWriteEndpointFailoverPolicy, error) { + vals := map[string]ReadWriteEndpointFailoverPolicy{ + "automatic": ReadWriteEndpointFailoverPolicyAutomatic, + "manual": ReadWriteEndpointFailoverPolicyManual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReadWriteEndpointFailoverPolicy(input) + return &out, nil +} + +type SecondaryInstanceType string + +const ( + SecondaryInstanceTypeGeo SecondaryInstanceType = "Geo" + SecondaryInstanceTypeStandby SecondaryInstanceType = "Standby" +) + +func PossibleValuesForSecondaryInstanceType() []string { + return []string{ + string(SecondaryInstanceTypeGeo), + string(SecondaryInstanceTypeStandby), + } +} + +func (s *SecondaryInstanceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecondaryInstanceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecondaryInstanceType(input string) (*SecondaryInstanceType, error) { + vals := map[string]SecondaryInstanceType{ + "geo": SecondaryInstanceTypeGeo, + "standby": SecondaryInstanceTypeStandby, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecondaryInstanceType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup.go b/resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup.go new file mode 100644 index 00000000000..5cbaddc2165 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup.go @@ -0,0 +1,139 @@ +package instancefailovergroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&InstanceFailoverGroupId{}) +} + +var _ resourceids.ResourceId = &InstanceFailoverGroupId{} + +// InstanceFailoverGroupId is a struct representing the Resource ID for a Instance Failover Group +type InstanceFailoverGroupId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + InstanceFailoverGroupName string +} + +// NewInstanceFailoverGroupID returns a new InstanceFailoverGroupId struct +func NewInstanceFailoverGroupID(subscriptionId string, resourceGroupName string, locationName string, instanceFailoverGroupName string) InstanceFailoverGroupId { + return InstanceFailoverGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + InstanceFailoverGroupName: instanceFailoverGroupName, + } +} + +// ParseInstanceFailoverGroupID parses 'input' into a InstanceFailoverGroupId +func ParseInstanceFailoverGroupID(input string) (*InstanceFailoverGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstanceFailoverGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstanceFailoverGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseInstanceFailoverGroupIDInsensitively parses 'input' case-insensitively into a InstanceFailoverGroupId +// note: this method should only be used for API response data and not user input +func ParseInstanceFailoverGroupIDInsensitively(input string) (*InstanceFailoverGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstanceFailoverGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstanceFailoverGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *InstanceFailoverGroupId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.InstanceFailoverGroupName, ok = input.Parsed["instanceFailoverGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "instanceFailoverGroupName", input) + } + + return nil +} + +// ValidateInstanceFailoverGroupID checks that 'input' can be parsed as a Instance Failover Group ID +func ValidateInstanceFailoverGroupID(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 := ParseInstanceFailoverGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Instance Failover Group ID +func (id InstanceFailoverGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/instanceFailoverGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.InstanceFailoverGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Instance Failover Group ID +func (id InstanceFailoverGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticInstanceFailoverGroups", "instanceFailoverGroups", "instanceFailoverGroups"), + resourceids.UserSpecifiedSegment("instanceFailoverGroupName", "instanceFailoverGroupName"), + } +} + +// String returns a human-readable description of this Instance Failover Group ID +func (id InstanceFailoverGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Instance Failover Group Name: %q", id.InstanceFailoverGroupName), + } + return fmt.Sprintf("Instance Failover Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup_test.go b/resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup_test.go new file mode 100644 index 00000000000..9199e8d65dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/id_instancefailovergroup_test.go @@ -0,0 +1,327 @@ +package instancefailovergroups + +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 = &InstanceFailoverGroupId{} + +func TestNewInstanceFailoverGroupID(t *testing.T) { + id := NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.InstanceFailoverGroupName != "instanceFailoverGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'InstanceFailoverGroupName'", id.InstanceFailoverGroupName, "instanceFailoverGroupName") + } +} + +func TestFormatInstanceFailoverGroupID(t *testing.T) { + actual := NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "instanceFailoverGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups/instanceFailoverGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseInstanceFailoverGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstanceFailoverGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups/instanceFailoverGroupName", + Expected: &InstanceFailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + InstanceFailoverGroupName: "instanceFailoverGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups/instanceFailoverGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstanceFailoverGroupID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.InstanceFailoverGroupName != v.Expected.InstanceFailoverGroupName { + t.Fatalf("Expected %q but got %q for InstanceFailoverGroupName", v.Expected.InstanceFailoverGroupName, actual.InstanceFailoverGroupName) + } + + } +} + +func TestParseInstanceFailoverGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstanceFailoverGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/iNsTaNcEfAiLoVeRgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups/instanceFailoverGroupName", + Expected: &InstanceFailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + InstanceFailoverGroupName: "instanceFailoverGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/instanceFailoverGroups/instanceFailoverGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/iNsTaNcEfAiLoVeRgRoUpS/iNsTaNcEfAiLoVeRgRoUpNaMe", + Expected: &InstanceFailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + InstanceFailoverGroupName: "iNsTaNcEfAiLoVeRgRoUpNaMe", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/iNsTaNcEfAiLoVeRgRoUpS/iNsTaNcEfAiLoVeRgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstanceFailoverGroupIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.InstanceFailoverGroupName != v.Expected.InstanceFailoverGroupName { + t.Fatalf("Expected %q but got %q for InstanceFailoverGroupName", v.Expected.InstanceFailoverGroupName, actual.InstanceFailoverGroupName) + } + + } +} + +func TestSegmentsForInstanceFailoverGroupId(t *testing.T) { + segments := InstanceFailoverGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("InstanceFailoverGroupId 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/sql/2023-08-01/instancefailovergroups/id_providerlocation.go b/resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation.go new file mode 100644 index 00000000000..11a7a4a824c --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation.go @@ -0,0 +1,130 @@ +package instancefailovergroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation_test.go b/resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation_test.go new file mode 100644 index 00000000000..5a3d7cf64a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package instancefailovergroups + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/sql/2023-08-01/instancefailovergroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/instancefailovergroups/method_createorupdate.go new file mode 100644 index 00000000000..2c3e879c19e --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/method_createorupdate.go @@ -0,0 +1,76 @@ +package instancefailovergroups + +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 *InstanceFailoverGroup +} + +// CreateOrUpdate ... +func (c InstanceFailoverGroupsClient) CreateOrUpdate(ctx context.Context, id InstanceFailoverGroupId, input InstanceFailoverGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 InstanceFailoverGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id InstanceFailoverGroupId, input InstanceFailoverGroup) 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/sql/2023-08-01/instancefailovergroups/method_delete.go b/resource-manager/sql/2023-08-01/instancefailovergroups/method_delete.go new file mode 100644 index 00000000000..16c9e12489a --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/method_delete.go @@ -0,0 +1,71 @@ +package instancefailovergroups + +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 InstanceFailoverGroupsClient) Delete(ctx context.Context, id InstanceFailoverGroupId) (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 InstanceFailoverGroupsClient) DeleteThenPoll(ctx context.Context, id InstanceFailoverGroupId) 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/sql/2023-08-01/instancefailovergroups/method_failover.go b/resource-manager/sql/2023-08-01/instancefailovergroups/method_failover.go new file mode 100644 index 00000000000..33f750aa0d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/method_failover.go @@ -0,0 +1,71 @@ +package instancefailovergroups + +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 FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *InstanceFailoverGroup +} + +// Failover ... +func (c InstanceFailoverGroupsClient) Failover(ctx context.Context, id InstanceFailoverGroupId) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c InstanceFailoverGroupsClient) FailoverThenPoll(ctx context.Context, id InstanceFailoverGroupId) error { + result, err := c.Failover(ctx, id) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/method_forcefailoverallowdataloss.go b/resource-manager/sql/2023-08-01/instancefailovergroups/method_forcefailoverallowdataloss.go new file mode 100644 index 00000000000..9634e7ef7e4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/method_forcefailoverallowdataloss.go @@ -0,0 +1,71 @@ +package instancefailovergroups + +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 ForceFailoverAllowDataLossOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *InstanceFailoverGroup +} + +// ForceFailoverAllowDataLoss ... +func (c InstanceFailoverGroupsClient) ForceFailoverAllowDataLoss(ctx context.Context, id InstanceFailoverGroupId) (result ForceFailoverAllowDataLossOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceFailoverAllowDataLoss", 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 +} + +// ForceFailoverAllowDataLossThenPoll performs ForceFailoverAllowDataLoss then polls until it's completed +func (c InstanceFailoverGroupsClient) ForceFailoverAllowDataLossThenPoll(ctx context.Context, id InstanceFailoverGroupId) error { + result, err := c.ForceFailoverAllowDataLoss(ctx, id) + if err != nil { + return fmt.Errorf("performing ForceFailoverAllowDataLoss: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ForceFailoverAllowDataLoss: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/method_get.go b/resource-manager/sql/2023-08-01/instancefailovergroups/method_get.go new file mode 100644 index 00000000000..97fdea7143e --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/method_get.go @@ -0,0 +1,53 @@ +package instancefailovergroups + +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 *InstanceFailoverGroup +} + +// Get ... +func (c InstanceFailoverGroupsClient) Get(ctx context.Context, id InstanceFailoverGroupId) (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 InstanceFailoverGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/method_listbylocation.go b/resource-manager/sql/2023-08-01/instancefailovergroups/method_listbylocation.go new file mode 100644 index 00000000000..b5ab352fd08 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/method_listbylocation.go @@ -0,0 +1,105 @@ +package instancefailovergroups + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]InstanceFailoverGroup +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []InstanceFailoverGroup +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c InstanceFailoverGroupsClient) ListByLocation(ctx context.Context, id ProviderLocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/instanceFailoverGroups", 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 *[]InstanceFailoverGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c InstanceFailoverGroupsClient) ListByLocationComplete(ctx context.Context, id ProviderLocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, InstanceFailoverGroupOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c InstanceFailoverGroupsClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, predicate InstanceFailoverGroupOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]InstanceFailoverGroup, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroup.go b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroup.go new file mode 100644 index 00000000000..d143e10f5b1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroup.go @@ -0,0 +1,11 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstanceFailoverGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *InstanceFailoverGroupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupproperties.go b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupproperties.go new file mode 100644 index 00000000000..85645014187 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupproperties.go @@ -0,0 +1,14 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstanceFailoverGroupProperties struct { + ManagedInstancePairs []ManagedInstancePairInfo `json:"managedInstancePairs"` + PartnerRegions []PartnerRegionInfo `json:"partnerRegions"` + ReadOnlyEndpoint *InstanceFailoverGroupReadOnlyEndpoint `json:"readOnlyEndpoint,omitempty"` + ReadWriteEndpoint InstanceFailoverGroupReadWriteEndpoint `json:"readWriteEndpoint"` + ReplicationRole *InstanceFailoverGroupReplicationRole `json:"replicationRole,omitempty"` + ReplicationState *string `json:"replicationState,omitempty"` + SecondaryType *SecondaryInstanceType `json:"secondaryType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go new file mode 100644 index 00000000000..af9aae49c73 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go @@ -0,0 +1,8 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstanceFailoverGroupReadOnlyEndpoint struct { + FailoverPolicy *ReadOnlyEndpointFailoverPolicy `json:"failoverPolicy,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go new file mode 100644 index 00000000000..6470ba23b9e --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go @@ -0,0 +1,9 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstanceFailoverGroupReadWriteEndpoint struct { + FailoverPolicy ReadWriteEndpointFailoverPolicy `json:"failoverPolicy"` + FailoverWithDataLossGracePeriodMinutes *int64 `json:"failoverWithDataLossGracePeriodMinutes,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/model_managedinstancepairinfo.go b/resource-manager/sql/2023-08-01/instancefailovergroups/model_managedinstancepairinfo.go new file mode 100644 index 00000000000..2e3aef9ff30 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/model_managedinstancepairinfo.go @@ -0,0 +1,9 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePairInfo struct { + PartnerManagedInstanceId *string `json:"partnerManagedInstanceId,omitempty"` + PrimaryManagedInstanceId *string `json:"primaryManagedInstanceId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/model_partnerregioninfo.go b/resource-manager/sql/2023-08-01/instancefailovergroups/model_partnerregioninfo.go new file mode 100644 index 00000000000..948ef292459 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/model_partnerregioninfo.go @@ -0,0 +1,9 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerRegionInfo struct { + Location *string `json:"location,omitempty"` + ReplicationRole *InstanceFailoverGroupReplicationRole `json:"replicationRole,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancefailovergroups/predicates.go b/resource-manager/sql/2023-08-01/instancefailovergroups/predicates.go new file mode 100644 index 00000000000..bc1705b3dc4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/predicates.go @@ -0,0 +1,27 @@ +package instancefailovergroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstanceFailoverGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p InstanceFailoverGroupOperationPredicate) Matches(input InstanceFailoverGroup) 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/sql/2023-08-01/instancefailovergroups/version.go b/resource-manager/sql/2023-08-01/instancefailovergroups/version.go new file mode 100644 index 00000000000..f240a545ebb --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancefailovergroups/version.go @@ -0,0 +1,10 @@ +package instancefailovergroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/instancefailovergroups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/instancepools/README.md b/resource-manager/sql/2023-08-01/instancepools/README.md new file mode 100644 index 00000000000..4c82491cb0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/instancepools` Documentation + +The `instancepools` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/instancepools" +``` + + +### Client Initialization + +```go +client := instancepools.NewInstancePoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `InstancePoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := instancepools.NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + +payload := instancepools.InstancePool{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `InstancePoolsClient.Delete` + +```go +ctx := context.TODO() +id := instancepools.NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `InstancePoolsClient.Get` + +```go +ctx := context.TODO() +id := instancepools.NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + +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: `InstancePoolsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `InstancePoolsClient.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: `InstancePoolsClient.Update` + +```go +ctx := context.TODO() +id := instancepools.NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + +payload := instancepools.InstancePoolUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/instancepools/client.go b/resource-manager/sql/2023-08-01/instancepools/client.go new file mode 100644 index 00000000000..a637ecc1205 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/client.go @@ -0,0 +1,26 @@ +package instancepools + +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 InstancePoolsClient struct { + Client *resourcemanager.Client +} + +func NewInstancePoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*InstancePoolsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "instancepools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating InstancePoolsClient: %+v", err) + } + + return &InstancePoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/instancepools/constants.go b/resource-manager/sql/2023-08-01/instancepools/constants.go new file mode 100644 index 00000000000..1d4e4d38b29 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/constants.go @@ -0,0 +1,51 @@ +package instancepools + +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 InstancePoolLicenseType string + +const ( + InstancePoolLicenseTypeBasePrice InstancePoolLicenseType = "BasePrice" + InstancePoolLicenseTypeLicenseIncluded InstancePoolLicenseType = "LicenseIncluded" +) + +func PossibleValuesForInstancePoolLicenseType() []string { + return []string{ + string(InstancePoolLicenseTypeBasePrice), + string(InstancePoolLicenseTypeLicenseIncluded), + } +} + +func (s *InstancePoolLicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInstancePoolLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInstancePoolLicenseType(input string) (*InstancePoolLicenseType, error) { + vals := map[string]InstancePoolLicenseType{ + "baseprice": InstancePoolLicenseTypeBasePrice, + "licenseincluded": InstancePoolLicenseTypeLicenseIncluded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InstancePoolLicenseType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/instancepools/id_instancepool.go b/resource-manager/sql/2023-08-01/instancepools/id_instancepool.go new file mode 100644 index 00000000000..7b4592b51c0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/id_instancepool.go @@ -0,0 +1,130 @@ +package instancepools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&InstancePoolId{}) +} + +var _ resourceids.ResourceId = &InstancePoolId{} + +// InstancePoolId is a struct representing the Resource ID for a Instance Pool +type InstancePoolId struct { + SubscriptionId string + ResourceGroupName string + InstancePoolName string +} + +// NewInstancePoolID returns a new InstancePoolId struct +func NewInstancePoolID(subscriptionId string, resourceGroupName string, instancePoolName string) InstancePoolId { + return InstancePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + InstancePoolName: instancePoolName, + } +} + +// ParseInstancePoolID parses 'input' into a InstancePoolId +func ParseInstancePoolID(input string) (*InstancePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstancePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstancePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseInstancePoolIDInsensitively parses 'input' case-insensitively into a InstancePoolId +// note: this method should only be used for API response data and not user input +func ParseInstancePoolIDInsensitively(input string) (*InstancePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstancePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstancePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *InstancePoolId) 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.InstancePoolName, ok = input.Parsed["instancePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "instancePoolName", input) + } + + return nil +} + +// ValidateInstancePoolID checks that 'input' can be parsed as a Instance Pool ID +func ValidateInstancePoolID(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 := ParseInstancePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Instance Pool ID +func (id InstancePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/instancePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.InstancePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Instance Pool ID +func (id InstancePoolId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticInstancePools", "instancePools", "instancePools"), + resourceids.UserSpecifiedSegment("instancePoolName", "instancePoolName"), + } +} + +// String returns a human-readable description of this Instance Pool ID +func (id InstancePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Instance Pool Name: %q", id.InstancePoolName), + } + return fmt.Sprintf("Instance Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/instancepools/id_instancepool_test.go b/resource-manager/sql/2023-08-01/instancepools/id_instancepool_test.go new file mode 100644 index 00000000000..f0ee1b728a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/id_instancepool_test.go @@ -0,0 +1,282 @@ +package instancepools + +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 = &InstancePoolId{} + +func TestNewInstancePoolID(t *testing.T) { + id := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + + 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.InstancePoolName != "instancePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'InstancePoolName'", id.InstancePoolName, "instancePoolName") + } +} + +func TestFormatInstancePoolID(t *testing.T) { + actual := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseInstancePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstancePoolId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstancePoolID(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.InstancePoolName != v.Expected.InstancePoolName { + t.Fatalf("Expected %q but got %q for InstancePoolName", v.Expected.InstancePoolName, actual.InstancePoolName) + } + + } +} + +func TestParseInstancePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstancePoolId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/iNsTaNcEpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/iNsTaNcEpOoLs/iNsTaNcEpOoLnAmE", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + InstancePoolName: "iNsTaNcEpOoLnAmE", + }, + }, + { + // 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.sQl/iNsTaNcEpOoLs/iNsTaNcEpOoLnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstancePoolIDInsensitively(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.InstancePoolName != v.Expected.InstancePoolName { + t.Fatalf("Expected %q but got %q for InstancePoolName", v.Expected.InstancePoolName, actual.InstancePoolName) + } + + } +} + +func TestSegmentsForInstancePoolId(t *testing.T) { + segments := InstancePoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("InstancePoolId 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/sql/2023-08-01/instancepools/method_createorupdate.go b/resource-manager/sql/2023-08-01/instancepools/method_createorupdate.go new file mode 100644 index 00000000000..fe0c2809672 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/method_createorupdate.go @@ -0,0 +1,76 @@ +package instancepools + +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 *InstancePool +} + +// CreateOrUpdate ... +func (c InstancePoolsClient) CreateOrUpdate(ctx context.Context, id InstancePoolId, input InstancePool) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 InstancePoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id InstancePoolId, input InstancePool) 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/sql/2023-08-01/instancepools/method_delete.go b/resource-manager/sql/2023-08-01/instancepools/method_delete.go new file mode 100644 index 00000000000..211f171a9e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/method_delete.go @@ -0,0 +1,71 @@ +package instancepools + +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 InstancePoolsClient) Delete(ctx context.Context, id InstancePoolId) (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 InstancePoolsClient) DeleteThenPoll(ctx context.Context, id InstancePoolId) 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/sql/2023-08-01/instancepools/method_get.go b/resource-manager/sql/2023-08-01/instancepools/method_get.go new file mode 100644 index 00000000000..b953e524138 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/method_get.go @@ -0,0 +1,53 @@ +package instancepools + +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 *InstancePool +} + +// Get ... +func (c InstancePoolsClient) Get(ctx context.Context, id InstancePoolId) (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 InstancePool + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/instancepools/method_list.go b/resource-manager/sql/2023-08-01/instancepools/method_list.go new file mode 100644 index 00000000000..a5553a16bf6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/method_list.go @@ -0,0 +1,106 @@ +package instancepools + +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 *[]InstancePool +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []InstancePool +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c InstancePoolsClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/instancePools", 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 *[]InstancePool `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 InstancePoolsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, InstancePoolOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c InstancePoolsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate InstancePoolOperationPredicate) (result ListCompleteResult, err error) { + items := make([]InstancePool, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/instancepools/method_listbyresourcegroup.go b/resource-manager/sql/2023-08-01/instancepools/method_listbyresourcegroup.go new file mode 100644 index 00000000000..6731b2a93f3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package instancepools + +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 *[]InstancePool +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []InstancePool +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c InstancePoolsClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/instancePools", 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 *[]InstancePool `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 InstancePoolsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, InstancePoolOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c InstancePoolsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate InstancePoolOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]InstancePool, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/instancepools/method_update.go b/resource-manager/sql/2023-08-01/instancepools/method_update.go new file mode 100644 index 00000000000..6261039b083 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/method_update.go @@ -0,0 +1,75 @@ +package instancepools + +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 *InstancePool +} + +// Update ... +func (c InstancePoolsClient) Update(ctx context.Context, id InstancePoolId, input InstancePoolUpdate) (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 InstancePoolsClient) UpdateThenPoll(ctx context.Context, id InstancePoolId, input InstancePoolUpdate) 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/sql/2023-08-01/instancepools/model_instancepool.go b/resource-manager/sql/2023-08-01/instancepools/model_instancepool.go new file mode 100644 index 00000000000..13794e6a2ce --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/model_instancepool.go @@ -0,0 +1,14 @@ +package instancepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePool struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *InstancePoolProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancepools/model_instancepoolproperties.go b/resource-manager/sql/2023-08-01/instancepools/model_instancepoolproperties.go new file mode 100644 index 00000000000..6f987f1c794 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/model_instancepoolproperties.go @@ -0,0 +1,12 @@ +package instancepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePoolProperties struct { + DnsZone *string `json:"dnsZone,omitempty"` + LicenseType InstancePoolLicenseType `json:"licenseType"` + MaintenanceConfigurationId *string `json:"maintenanceConfigurationId,omitempty"` + SubnetId string `json:"subnetId"` + VCores int64 `json:"vCores"` +} diff --git a/resource-manager/sql/2023-08-01/instancepools/model_instancepoolupdate.go b/resource-manager/sql/2023-08-01/instancepools/model_instancepoolupdate.go new file mode 100644 index 00000000000..1f263758f58 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/model_instancepoolupdate.go @@ -0,0 +1,10 @@ +package instancepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePoolUpdate struct { + Properties *InstancePoolProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancepools/model_sku.go b/resource-manager/sql/2023-08-01/instancepools/model_sku.go new file mode 100644 index 00000000000..d9ee72a468f --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/model_sku.go @@ -0,0 +1,12 @@ +package instancepools + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/instancepools/predicates.go b/resource-manager/sql/2023-08-01/instancepools/predicates.go new file mode 100644 index 00000000000..65903be2cc9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/predicates.go @@ -0,0 +1,32 @@ +package instancepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePoolOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p InstancePoolOperationPredicate) Matches(input InstancePool) 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/sql/2023-08-01/instancepools/version.go b/resource-manager/sql/2023-08-01/instancepools/version.go new file mode 100644 index 00000000000..bc221c68b08 --- /dev/null +++ b/resource-manager/sql/2023-08-01/instancepools/version.go @@ -0,0 +1,10 @@ +package instancepools + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/instancepools/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/README.md b/resource-manager/sql/2023-08-01/ipv6firewallrules/README.md new file mode 100644 index 00000000000..b65a3dcd762 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/ipv6firewallrules` Documentation + +The `ipv6firewallrules` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/ipv6firewallrules" +``` + + +### Client Initialization + +```go +client := ipv6firewallrules.NewIPv6FirewallRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IPv6FirewallRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := ipv6firewallrules.NewIPv6FirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ipv6FirewallRuleName") + +payload := ipv6firewallrules.IPv6FirewallRule{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IPv6FirewallRulesClient.Delete` + +```go +ctx := context.TODO() +id := ipv6firewallrules.NewIPv6FirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ipv6FirewallRuleName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IPv6FirewallRulesClient.Get` + +```go +ctx := context.TODO() +id := ipv6firewallrules.NewIPv6FirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ipv6FirewallRuleName") + +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: `IPv6FirewallRulesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/client.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/client.go new file mode 100644 index 00000000000..59b1646ba2d --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/client.go @@ -0,0 +1,26 @@ +package ipv6firewallrules + +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 IPv6FirewallRulesClient struct { + Client *resourcemanager.Client +} + +func NewIPv6FirewallRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*IPv6FirewallRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "ipv6firewallrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IPv6FirewallRulesClient: %+v", err) + } + + return &IPv6FirewallRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule.go new file mode 100644 index 00000000000..7a8bc04abee --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule.go @@ -0,0 +1,139 @@ +package ipv6firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&IPv6FirewallRuleId{}) +} + +var _ resourceids.ResourceId = &IPv6FirewallRuleId{} + +// IPv6FirewallRuleId is a struct representing the Resource ID for a I Pv 6 Firewall Rule +type IPv6FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + Ipv6FirewallRuleName string +} + +// NewIPv6FirewallRuleID returns a new IPv6FirewallRuleId struct +func NewIPv6FirewallRuleID(subscriptionId string, resourceGroupName string, serverName string, ipv6FirewallRuleName string) IPv6FirewallRuleId { + return IPv6FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + Ipv6FirewallRuleName: ipv6FirewallRuleName, + } +} + +// ParseIPv6FirewallRuleID parses 'input' into a IPv6FirewallRuleId +func ParseIPv6FirewallRuleID(input string) (*IPv6FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&IPv6FirewallRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IPv6FirewallRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIPv6FirewallRuleIDInsensitively parses 'input' case-insensitively into a IPv6FirewallRuleId +// note: this method should only be used for API response data and not user input +func ParseIPv6FirewallRuleIDInsensitively(input string) (*IPv6FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&IPv6FirewallRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IPv6FirewallRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IPv6FirewallRuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.Ipv6FirewallRuleName, ok = input.Parsed["ipv6FirewallRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ipv6FirewallRuleName", input) + } + + return nil +} + +// ValidateIPv6FirewallRuleID checks that 'input' can be parsed as a I Pv 6 Firewall Rule ID +func ValidateIPv6FirewallRuleID(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 := ParseIPv6FirewallRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted I Pv 6 Firewall Rule ID +func (id IPv6FirewallRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/ipv6FirewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.Ipv6FirewallRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this I Pv 6 Firewall Rule ID +func (id IPv6FirewallRuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticIpv6FirewallRules", "ipv6FirewallRules", "ipv6FirewallRules"), + resourceids.UserSpecifiedSegment("ipv6FirewallRuleName", "ipv6FirewallRuleName"), + } +} + +// String returns a human-readable description of this I Pv 6 Firewall Rule ID +func (id IPv6FirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Ipv 6 Firewall Rule Name: %q", id.Ipv6FirewallRuleName), + } + return fmt.Sprintf("I Pv 6 Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule_test.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule_test.go new file mode 100644 index 00000000000..d56bbf6cbf5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/id_ipv6firewallrule_test.go @@ -0,0 +1,327 @@ +package ipv6firewallrules + +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 = &IPv6FirewallRuleId{} + +func TestNewIPv6FirewallRuleID(t *testing.T) { + id := NewIPv6FirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ipv6FirewallRuleName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.Ipv6FirewallRuleName != "ipv6FirewallRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'Ipv6FirewallRuleName'", id.Ipv6FirewallRuleName, "ipv6FirewallRuleName") + } +} + +func TestFormatIPv6FirewallRuleID(t *testing.T) { + actual := NewIPv6FirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ipv6FirewallRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules/ipv6FirewallRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIPv6FirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IPv6FirewallRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules/ipv6FirewallRuleName", + Expected: &IPv6FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + Ipv6FirewallRuleName: "ipv6FirewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules/ipv6FirewallRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIPv6FirewallRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.Ipv6FirewallRuleName != v.Expected.Ipv6FirewallRuleName { + t.Fatalf("Expected %q but got %q for Ipv6FirewallRuleName", v.Expected.Ipv6FirewallRuleName, actual.Ipv6FirewallRuleName) + } + + } +} + +func TestParseIPv6FirewallRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IPv6FirewallRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/iPv6fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules/ipv6FirewallRuleName", + Expected: &IPv6FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + Ipv6FirewallRuleName: "ipv6FirewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/ipv6FirewallRules/ipv6FirewallRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/iPv6fIrEwAlLrUlEs/iPv6fIrEwAlLrUlEnAmE", + Expected: &IPv6FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + Ipv6FirewallRuleName: "iPv6fIrEwAlLrUlEnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/iPv6fIrEwAlLrUlEs/iPv6fIrEwAlLrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIPv6FirewallRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.Ipv6FirewallRuleName != v.Expected.Ipv6FirewallRuleName { + t.Fatalf("Expected %q but got %q for Ipv6FirewallRuleName", v.Expected.Ipv6FirewallRuleName, actual.Ipv6FirewallRuleName) + } + + } +} + +func TestSegmentsForIPv6FirewallRuleId(t *testing.T) { + segments := IPv6FirewallRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IPv6FirewallRuleId 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/sql/2023-08-01/ipv6firewallrules/method_createorupdate.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_createorupdate.go new file mode 100644 index 00000000000..51a11453d62 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_createorupdate.go @@ -0,0 +1,58 @@ +package ipv6firewallrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IPv6FirewallRule +} + +// CreateOrUpdate ... +func (c IPv6FirewallRulesClient) CreateOrUpdate(ctx context.Context, id IPv6FirewallRuleId, input IPv6FirewallRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model IPv6FirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/method_delete.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_delete.go new file mode 100644 index 00000000000..a99679c4296 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_delete.go @@ -0,0 +1,47 @@ +package ipv6firewallrules + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IPv6FirewallRulesClient) Delete(ctx context.Context, id IPv6FirewallRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/method_get.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_get.go new file mode 100644 index 00000000000..7eec857c439 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_get.go @@ -0,0 +1,53 @@ +package ipv6firewallrules + +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 *IPv6FirewallRule +} + +// Get ... +func (c IPv6FirewallRulesClient) Get(ctx context.Context, id IPv6FirewallRuleId) (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 IPv6FirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/method_listbyserver.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_listbyserver.go new file mode 100644 index 00000000000..8c95219db62 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/method_listbyserver.go @@ -0,0 +1,106 @@ +package ipv6firewallrules + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IPv6FirewallRule +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []IPv6FirewallRule +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c IPv6FirewallRulesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/ipv6FirewallRules", 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 *[]IPv6FirewallRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c IPv6FirewallRulesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, IPv6FirewallRuleOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IPv6FirewallRulesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate IPv6FirewallRuleOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]IPv6FirewallRule, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6firewallrule.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6firewallrule.go new file mode 100644 index 00000000000..730a73e9b39 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6firewallrule.go @@ -0,0 +1,11 @@ +package ipv6firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPv6FirewallRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IPv6ServerFirewallRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go new file mode 100644 index 00000000000..449f0a5cbad --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go @@ -0,0 +1,9 @@ +package ipv6firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPv6ServerFirewallRuleProperties struct { + EndIPv6Address *string `json:"endIPv6Address,omitempty"` + StartIPv6Address *string `json:"startIPv6Address,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/ipv6firewallrules/predicates.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/predicates.go new file mode 100644 index 00000000000..2bc9ba46621 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/predicates.go @@ -0,0 +1,27 @@ +package ipv6firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPv6FirewallRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IPv6FirewallRuleOperationPredicate) Matches(input IPv6FirewallRule) 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/sql/2023-08-01/ipv6firewallrules/version.go b/resource-manager/sql/2023-08-01/ipv6firewallrules/version.go new file mode 100644 index 00000000000..68032cfc56b --- /dev/null +++ b/resource-manager/sql/2023-08-01/ipv6firewallrules/version.go @@ -0,0 +1,10 @@ +package ipv6firewallrules + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/ipv6firewallrules/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobagents/README.md b/resource-manager/sql/2023-08-01/jobagents/README.md new file mode 100644 index 00000000000..abf0a0960e4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/README.md @@ -0,0 +1,100 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobagents` Documentation + +The `jobagents` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobagents" +``` + + +### Client Initialization + +```go +client := jobagents.NewJobAgentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobAgentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobagents.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +payload := jobagents.JobAgent{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobAgentsClient.Delete` + +```go +ctx := context.TODO() +id := jobagents.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobAgentsClient.Get` + +```go +ctx := context.TODO() +id := jobagents.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +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: `JobAgentsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobAgentsClient.Update` + +```go +ctx := context.TODO() +id := jobagents.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +payload := jobagents.JobAgentUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/jobagents/client.go b/resource-manager/sql/2023-08-01/jobagents/client.go new file mode 100644 index 00000000000..12ff1946c03 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/client.go @@ -0,0 +1,26 @@ +package jobagents + +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 JobAgentsClient struct { + Client *resourcemanager.Client +} + +func NewJobAgentsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobAgentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobagents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobAgentsClient: %+v", err) + } + + return &JobAgentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobagents/constants.go b/resource-manager/sql/2023-08-01/jobagents/constants.go new file mode 100644 index 00000000000..015cde7bdcc --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/constants.go @@ -0,0 +1,107 @@ +package jobagents + +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 JobAgentIdentityType string + +const ( + JobAgentIdentityTypeNone JobAgentIdentityType = "None" + JobAgentIdentityTypeSystemAssigned JobAgentIdentityType = "SystemAssigned" + JobAgentIdentityTypeSystemAssignedUserAssigned JobAgentIdentityType = "SystemAssignedUserAssigned" + JobAgentIdentityTypeUserAssigned JobAgentIdentityType = "UserAssigned" +) + +func PossibleValuesForJobAgentIdentityType() []string { + return []string{ + string(JobAgentIdentityTypeNone), + string(JobAgentIdentityTypeSystemAssigned), + string(JobAgentIdentityTypeSystemAssignedUserAssigned), + string(JobAgentIdentityTypeUserAssigned), + } +} + +func (s *JobAgentIdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobAgentIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobAgentIdentityType(input string) (*JobAgentIdentityType, error) { + vals := map[string]JobAgentIdentityType{ + "none": JobAgentIdentityTypeNone, + "systemassigned": JobAgentIdentityTypeSystemAssigned, + "systemassigneduserassigned": JobAgentIdentityTypeSystemAssignedUserAssigned, + "userassigned": JobAgentIdentityTypeUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobAgentIdentityType(input) + return &out, nil +} + +type JobAgentState string + +const ( + JobAgentStateCreating JobAgentState = "Creating" + JobAgentStateDeleting JobAgentState = "Deleting" + JobAgentStateDisabled JobAgentState = "Disabled" + JobAgentStateReady JobAgentState = "Ready" + JobAgentStateUpdating JobAgentState = "Updating" +) + +func PossibleValuesForJobAgentState() []string { + return []string{ + string(JobAgentStateCreating), + string(JobAgentStateDeleting), + string(JobAgentStateDisabled), + string(JobAgentStateReady), + string(JobAgentStateUpdating), + } +} + +func (s *JobAgentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobAgentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobAgentState(input string) (*JobAgentState, error) { + vals := map[string]JobAgentState{ + "creating": JobAgentStateCreating, + "deleting": JobAgentStateDeleting, + "disabled": JobAgentStateDisabled, + "ready": JobAgentStateReady, + "updating": JobAgentStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobAgentState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/jobagents/id_jobagent.go b/resource-manager/sql/2023-08-01/jobagents/id_jobagent.go new file mode 100644 index 00000000000..373bc0c8dfc --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/id_jobagent.go @@ -0,0 +1,139 @@ +package jobagents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobAgentId{}) +} + +var _ resourceids.ResourceId = &JobAgentId{} + +// JobAgentId is a struct representing the Resource ID for a Job Agent +type JobAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string +} + +// NewJobAgentID returns a new JobAgentId struct +func NewJobAgentID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string) JobAgentId { + return JobAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + } +} + +// ParseJobAgentID parses 'input' into a JobAgentId +func ParseJobAgentID(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobAgentIDInsensitively parses 'input' case-insensitively into a JobAgentId +// note: this method should only be used for API response data and not user input +func ParseJobAgentIDInsensitively(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + return nil +} + +// ValidateJobAgentID checks that 'input' can be parsed as a Job Agent ID +func ValidateJobAgentID(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 := ParseJobAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job Agent ID +func (id JobAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job Agent ID +func (id JobAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + } +} + +// String returns a human-readable description of this Job Agent ID +func (id JobAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + } + return fmt.Sprintf("Job Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobagents/id_jobagent_test.go b/resource-manager/sql/2023-08-01/jobagents/id_jobagent_test.go new file mode 100644 index 00000000000..320d0ca2c20 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/id_jobagent_test.go @@ -0,0 +1,327 @@ +package jobagents + +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 = &JobAgentId{} + +func TestNewJobAgentID(t *testing.T) { + id := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestParseJobAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestSegmentsForJobAgentId(t *testing.T) { + segments := JobAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobAgentId 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/sql/2023-08-01/jobagents/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobagents/method_createorupdate.go new file mode 100644 index 00000000000..f120e0f623d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/method_createorupdate.go @@ -0,0 +1,76 @@ +package jobagents + +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 *JobAgent +} + +// CreateOrUpdate ... +func (c JobAgentsClient) CreateOrUpdate(ctx context.Context, id JobAgentId, input JobAgent) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 JobAgentsClient) CreateOrUpdateThenPoll(ctx context.Context, id JobAgentId, input JobAgent) 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/sql/2023-08-01/jobagents/method_delete.go b/resource-manager/sql/2023-08-01/jobagents/method_delete.go new file mode 100644 index 00000000000..8f6a62a0044 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/method_delete.go @@ -0,0 +1,71 @@ +package jobagents + +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 JobAgentsClient) Delete(ctx context.Context, id JobAgentId) (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 JobAgentsClient) DeleteThenPoll(ctx context.Context, id JobAgentId) 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/sql/2023-08-01/jobagents/method_get.go b/resource-manager/sql/2023-08-01/jobagents/method_get.go new file mode 100644 index 00000000000..ee85f1b86c7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/method_get.go @@ -0,0 +1,53 @@ +package jobagents + +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 *JobAgent +} + +// Get ... +func (c JobAgentsClient) Get(ctx context.Context, id JobAgentId) (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 JobAgent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobagents/method_listbyserver.go b/resource-manager/sql/2023-08-01/jobagents/method_listbyserver.go new file mode 100644 index 00000000000..5b82df1dd3d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/method_listbyserver.go @@ -0,0 +1,106 @@ +package jobagents + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobAgent +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobAgent +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c JobAgentsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/jobAgents", 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 *[]JobAgent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c JobAgentsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, JobAgentOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobAgentsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate JobAgentOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]JobAgent, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobagents/method_update.go b/resource-manager/sql/2023-08-01/jobagents/method_update.go new file mode 100644 index 00000000000..c2a872a26b5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/method_update.go @@ -0,0 +1,75 @@ +package jobagents + +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 *JobAgent +} + +// Update ... +func (c JobAgentsClient) Update(ctx context.Context, id JobAgentId, input JobAgentUpdate) (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 JobAgentsClient) UpdateThenPoll(ctx context.Context, id JobAgentId, input JobAgentUpdate) 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/sql/2023-08-01/jobagents/model_jobagent.go b/resource-manager/sql/2023-08-01/jobagents/model_jobagent.go new file mode 100644 index 00000000000..f4d2138665d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/model_jobagent.go @@ -0,0 +1,15 @@ +package jobagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgent struct { + Id *string `json:"id,omitempty"` + Identity *JobAgentIdentity `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *JobAgentProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobagents/model_jobagentidentity.go b/resource-manager/sql/2023-08-01/jobagents/model_jobagentidentity.go new file mode 100644 index 00000000000..031109c9b52 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/model_jobagentidentity.go @@ -0,0 +1,10 @@ +package jobagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentIdentity struct { + TenantId *string `json:"tenantId,omitempty"` + Type JobAgentIdentityType `json:"type"` + UserAssignedIdentities *map[string]JobAgentUserAssignedIdentity `json:"userAssignedIdentities,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobagents/model_jobagentproperties.go b/resource-manager/sql/2023-08-01/jobagents/model_jobagentproperties.go new file mode 100644 index 00000000000..e40a2a55db6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/model_jobagentproperties.go @@ -0,0 +1,9 @@ +package jobagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentProperties struct { + DatabaseId string `json:"databaseId"` + State *JobAgentState `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobagents/model_jobagentupdate.go b/resource-manager/sql/2023-08-01/jobagents/model_jobagentupdate.go new file mode 100644 index 00000000000..5c013e0cbbd --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/model_jobagentupdate.go @@ -0,0 +1,10 @@ +package jobagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentUpdate struct { + Identity *JobAgentIdentity `json:"identity,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobagents/model_jobagentuserassignedidentity.go b/resource-manager/sql/2023-08-01/jobagents/model_jobagentuserassignedidentity.go new file mode 100644 index 00000000000..3dc6c7368d6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/model_jobagentuserassignedidentity.go @@ -0,0 +1,9 @@ +package jobagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentUserAssignedIdentity struct { + ClientId *string `json:"clientId,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobagents/model_sku.go b/resource-manager/sql/2023-08-01/jobagents/model_sku.go new file mode 100644 index 00000000000..42a3cd79363 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/model_sku.go @@ -0,0 +1,12 @@ +package jobagents + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobagents/predicates.go b/resource-manager/sql/2023-08-01/jobagents/predicates.go new file mode 100644 index 00000000000..0813f84a604 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/predicates.go @@ -0,0 +1,32 @@ +package jobagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p JobAgentOperationPredicate) Matches(input JobAgent) 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/sql/2023-08-01/jobagents/version.go b/resource-manager/sql/2023-08-01/jobagents/version.go new file mode 100644 index 00000000000..afdb04a6f84 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobagents/version.go @@ -0,0 +1,10 @@ +package jobagents + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobagents/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/README.md b/resource-manager/sql/2023-08-01/jobcredentials/README.md new file mode 100644 index 00000000000..fca06efee79 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobcredentials` Documentation + +The `jobcredentials` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobcredentials" +``` + + +### Client Initialization + +```go +client := jobcredentials.NewJobCredentialsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobCredentialsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobcredentials.NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "credentialName") + +payload := jobcredentials.JobCredential{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobCredentialsClient.Delete` + +```go +ctx := context.TODO() +id := jobcredentials.NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "credentialName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobCredentialsClient.Get` + +```go +ctx := context.TODO() +id := jobcredentials.NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "credentialName") + +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: `JobCredentialsClient.ListByAgent` + +```go +ctx := context.TODO() +id := jobcredentials.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +// alternatively `client.ListByAgent(ctx, id)` can be used to do batched pagination +items, err := client.ListByAgentComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobcredentials/client.go b/resource-manager/sql/2023-08-01/jobcredentials/client.go new file mode 100644 index 00000000000..9bc1ca997fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/client.go @@ -0,0 +1,26 @@ +package jobcredentials + +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 JobCredentialsClient struct { + Client *resourcemanager.Client +} + +func NewJobCredentialsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobCredentialsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobcredentials", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobCredentialsClient: %+v", err) + } + + return &JobCredentialsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/id_credential.go b/resource-manager/sql/2023-08-01/jobcredentials/id_credential.go new file mode 100644 index 00000000000..9d3793337de --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/id_credential.go @@ -0,0 +1,148 @@ +package jobcredentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CredentialId{}) +} + +var _ resourceids.ResourceId = &CredentialId{} + +// CredentialId is a struct representing the Resource ID for a Credential +type CredentialId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + CredentialName string +} + +// NewCredentialID returns a new CredentialId struct +func NewCredentialID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, credentialName string) CredentialId { + return CredentialId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + CredentialName: credentialName, + } +} + +// ParseCredentialID parses 'input' into a CredentialId +func ParseCredentialID(input string) (*CredentialId, error) { + parser := resourceids.NewParserFromResourceIdType(&CredentialId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CredentialId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCredentialIDInsensitively parses 'input' case-insensitively into a CredentialId +// note: this method should only be used for API response data and not user input +func ParseCredentialIDInsensitively(input string) (*CredentialId, error) { + parser := resourceids.NewParserFromResourceIdType(&CredentialId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CredentialId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CredentialId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.CredentialName, ok = input.Parsed["credentialName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "credentialName", input) + } + + return nil +} + +// ValidateCredentialID checks that 'input' can be parsed as a Credential ID +func ValidateCredentialID(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 := ParseCredentialID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Credential ID +func (id CredentialId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/credentials/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.CredentialName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Credential ID +func (id CredentialId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticCredentials", "credentials", "credentials"), + resourceids.UserSpecifiedSegment("credentialName", "credentialName"), + } +} + +// String returns a human-readable description of this Credential ID +func (id CredentialId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Credential Name: %q", id.CredentialName), + } + return fmt.Sprintf("Credential (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/id_credential_test.go b/resource-manager/sql/2023-08-01/jobcredentials/id_credential_test.go new file mode 100644 index 00000000000..a925a830fa3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/id_credential_test.go @@ -0,0 +1,372 @@ +package jobcredentials + +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 = &CredentialId{} + +func TestNewCredentialID(t *testing.T) { + id := NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "credentialName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.CredentialName != "credentialName" { + t.Fatalf("Expected %q but got %q for Segment 'CredentialName'", id.CredentialName, "credentialName") + } +} + +func TestFormatCredentialID(t *testing.T) { + actual := NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "credentialName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials/credentialName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCredentialID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CredentialId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials/credentialName", + Expected: &CredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + CredentialName: "credentialName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials/credentialName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCredentialID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.CredentialName != v.Expected.CredentialName { + t.Fatalf("Expected %q but got %q for CredentialName", v.Expected.CredentialName, actual.CredentialName) + } + + } +} + +func TestParseCredentialIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CredentialId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/cReDeNtIaLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials/credentialName", + Expected: &CredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + CredentialName: "credentialName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/credentials/credentialName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/cReDeNtIaLs/cReDeNtIaLnAmE", + Expected: &CredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + CredentialName: "cReDeNtIaLnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/cReDeNtIaLs/cReDeNtIaLnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCredentialIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.CredentialName != v.Expected.CredentialName { + t.Fatalf("Expected %q but got %q for CredentialName", v.Expected.CredentialName, actual.CredentialName) + } + + } +} + +func TestSegmentsForCredentialId(t *testing.T) { + segments := CredentialId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CredentialId 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/sql/2023-08-01/jobcredentials/id_jobagent.go b/resource-manager/sql/2023-08-01/jobcredentials/id_jobagent.go new file mode 100644 index 00000000000..58756841c98 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/id_jobagent.go @@ -0,0 +1,139 @@ +package jobcredentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobAgentId{}) +} + +var _ resourceids.ResourceId = &JobAgentId{} + +// JobAgentId is a struct representing the Resource ID for a Job Agent +type JobAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string +} + +// NewJobAgentID returns a new JobAgentId struct +func NewJobAgentID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string) JobAgentId { + return JobAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + } +} + +// ParseJobAgentID parses 'input' into a JobAgentId +func ParseJobAgentID(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobAgentIDInsensitively parses 'input' case-insensitively into a JobAgentId +// note: this method should only be used for API response data and not user input +func ParseJobAgentIDInsensitively(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + return nil +} + +// ValidateJobAgentID checks that 'input' can be parsed as a Job Agent ID +func ValidateJobAgentID(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 := ParseJobAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job Agent ID +func (id JobAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job Agent ID +func (id JobAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + } +} + +// String returns a human-readable description of this Job Agent ID +func (id JobAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + } + return fmt.Sprintf("Job Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/id_jobagent_test.go b/resource-manager/sql/2023-08-01/jobcredentials/id_jobagent_test.go new file mode 100644 index 00000000000..58a0714408e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/id_jobagent_test.go @@ -0,0 +1,327 @@ +package jobcredentials + +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 = &JobAgentId{} + +func TestNewJobAgentID(t *testing.T) { + id := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestParseJobAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestSegmentsForJobAgentId(t *testing.T) { + segments := JobAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobAgentId 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/sql/2023-08-01/jobcredentials/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobcredentials/method_createorupdate.go new file mode 100644 index 00000000000..9cd18192efa --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/method_createorupdate.go @@ -0,0 +1,58 @@ +package jobcredentials + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *JobCredential +} + +// CreateOrUpdate ... +func (c JobCredentialsClient) CreateOrUpdate(ctx context.Context, id CredentialId, input JobCredential) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model JobCredential + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/method_delete.go b/resource-manager/sql/2023-08-01/jobcredentials/method_delete.go new file mode 100644 index 00000000000..d09d1b97d23 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/method_delete.go @@ -0,0 +1,47 @@ +package jobcredentials + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c JobCredentialsClient) Delete(ctx context.Context, id CredentialId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/method_get.go b/resource-manager/sql/2023-08-01/jobcredentials/method_get.go new file mode 100644 index 00000000000..c9c5e2020d9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/method_get.go @@ -0,0 +1,53 @@ +package jobcredentials + +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 *JobCredential +} + +// Get ... +func (c JobCredentialsClient) Get(ctx context.Context, id CredentialId) (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 JobCredential + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/method_listbyagent.go b/resource-manager/sql/2023-08-01/jobcredentials/method_listbyagent.go new file mode 100644 index 00000000000..ec10fbb7262 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/method_listbyagent.go @@ -0,0 +1,105 @@ +package jobcredentials + +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 ListByAgentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobCredential +} + +type ListByAgentCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobCredential +} + +type ListByAgentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByAgentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByAgent ... +func (c JobCredentialsClient) ListByAgent(ctx context.Context, id JobAgentId) (result ListByAgentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByAgentCustomPager{}, + Path: fmt.Sprintf("%s/credentials", 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 *[]JobCredential `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAgentComplete retrieves all the results into a single object +func (c JobCredentialsClient) ListByAgentComplete(ctx context.Context, id JobAgentId) (ListByAgentCompleteResult, error) { + return c.ListByAgentCompleteMatchingPredicate(ctx, id, JobCredentialOperationPredicate{}) +} + +// ListByAgentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobCredentialsClient) ListByAgentCompleteMatchingPredicate(ctx context.Context, id JobAgentId, predicate JobCredentialOperationPredicate) (result ListByAgentCompleteResult, err error) { + items := make([]JobCredential, 0) + + resp, err := c.ListByAgent(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAgentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/model_jobcredential.go b/resource-manager/sql/2023-08-01/jobcredentials/model_jobcredential.go new file mode 100644 index 00000000000..8756d3b7470 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/model_jobcredential.go @@ -0,0 +1,11 @@ +package jobcredentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobCredential struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobCredentialProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/model_jobcredentialproperties.go b/resource-manager/sql/2023-08-01/jobcredentials/model_jobcredentialproperties.go new file mode 100644 index 00000000000..6df1c01f450 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/model_jobcredentialproperties.go @@ -0,0 +1,9 @@ +package jobcredentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobCredentialProperties struct { + Password string `json:"password"` + Username string `json:"username"` +} diff --git a/resource-manager/sql/2023-08-01/jobcredentials/predicates.go b/resource-manager/sql/2023-08-01/jobcredentials/predicates.go new file mode 100644 index 00000000000..2aa2ac84e10 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/predicates.go @@ -0,0 +1,27 @@ +package jobcredentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobCredentialOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobCredentialOperationPredicate) Matches(input JobCredential) 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/sql/2023-08-01/jobcredentials/version.go b/resource-manager/sql/2023-08-01/jobcredentials/version.go new file mode 100644 index 00000000000..06b415794a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobcredentials/version.go @@ -0,0 +1,10 @@ +package jobcredentials + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobcredentials/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/README.md b/resource-manager/sql/2023-08-01/jobexecutions/README.md new file mode 100644 index 00000000000..9131bb72061 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/README.md @@ -0,0 +1,110 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobexecutions` Documentation + +The `jobexecutions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobexecutions" +``` + + +### Client Initialization + +```go +client := jobexecutions.NewJobExecutionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobExecutionsClient.Cancel` + +```go +ctx := context.TODO() +id := jobexecutions.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + +read, err := client.Cancel(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobExecutionsClient.Create` + +```go +ctx := context.TODO() +id := jobexecutions.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +if err := client.CreateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobExecutionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobexecutions.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + +if err := client.CreateOrUpdateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobExecutionsClient.Get` + +```go +ctx := context.TODO() +id := jobexecutions.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + +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: `JobExecutionsClient.ListByAgent` + +```go +ctx := context.TODO() +id := jobexecutions.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +// alternatively `client.ListByAgent(ctx, id, jobexecutions.DefaultListByAgentOperationOptions())` can be used to do batched pagination +items, err := client.ListByAgentComplete(ctx, id, jobexecutions.DefaultListByAgentOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobExecutionsClient.ListByJob` + +```go +ctx := context.TODO() +id := jobexecutions.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +// alternatively `client.ListByJob(ctx, id, jobexecutions.DefaultListByJobOperationOptions())` can be used to do batched pagination +items, err := client.ListByJobComplete(ctx, id, jobexecutions.DefaultListByJobOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobexecutions/client.go b/resource-manager/sql/2023-08-01/jobexecutions/client.go new file mode 100644 index 00000000000..cad4ae0b98f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/client.go @@ -0,0 +1,26 @@ +package jobexecutions + +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 JobExecutionsClient struct { + Client *resourcemanager.Client +} + +func NewJobExecutionsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobExecutionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobexecutions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobExecutionsClient: %+v", err) + } + + return &JobExecutionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/constants.go b/resource-manager/sql/2023-08-01/jobexecutions/constants.go new file mode 100644 index 00000000000..f3edd670f90 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/constants.go @@ -0,0 +1,175 @@ +package jobexecutions + +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 JobExecutionLifecycle string + +const ( + JobExecutionLifecycleCanceled JobExecutionLifecycle = "Canceled" + JobExecutionLifecycleCreated JobExecutionLifecycle = "Created" + JobExecutionLifecycleFailed JobExecutionLifecycle = "Failed" + JobExecutionLifecycleInProgress JobExecutionLifecycle = "InProgress" + JobExecutionLifecycleSkipped JobExecutionLifecycle = "Skipped" + JobExecutionLifecycleSucceeded JobExecutionLifecycle = "Succeeded" + JobExecutionLifecycleSucceededWithSkipped JobExecutionLifecycle = "SucceededWithSkipped" + JobExecutionLifecycleTimedOut JobExecutionLifecycle = "TimedOut" + JobExecutionLifecycleWaitingForChildJobExecutions JobExecutionLifecycle = "WaitingForChildJobExecutions" + JobExecutionLifecycleWaitingForRetry JobExecutionLifecycle = "WaitingForRetry" +) + +func PossibleValuesForJobExecutionLifecycle() []string { + return []string{ + string(JobExecutionLifecycleCanceled), + string(JobExecutionLifecycleCreated), + string(JobExecutionLifecycleFailed), + string(JobExecutionLifecycleInProgress), + string(JobExecutionLifecycleSkipped), + string(JobExecutionLifecycleSucceeded), + string(JobExecutionLifecycleSucceededWithSkipped), + string(JobExecutionLifecycleTimedOut), + string(JobExecutionLifecycleWaitingForChildJobExecutions), + string(JobExecutionLifecycleWaitingForRetry), + } +} + +func (s *JobExecutionLifecycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobExecutionLifecycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobExecutionLifecycle(input string) (*JobExecutionLifecycle, error) { + vals := map[string]JobExecutionLifecycle{ + "canceled": JobExecutionLifecycleCanceled, + "created": JobExecutionLifecycleCreated, + "failed": JobExecutionLifecycleFailed, + "inprogress": JobExecutionLifecycleInProgress, + "skipped": JobExecutionLifecycleSkipped, + "succeeded": JobExecutionLifecycleSucceeded, + "succeededwithskipped": JobExecutionLifecycleSucceededWithSkipped, + "timedout": JobExecutionLifecycleTimedOut, + "waitingforchildjobexecutions": JobExecutionLifecycleWaitingForChildJobExecutions, + "waitingforretry": JobExecutionLifecycleWaitingForRetry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobExecutionLifecycle(input) + return &out, nil +} + +type JobTargetType string + +const ( + JobTargetTypeSqlDatabase JobTargetType = "SqlDatabase" + JobTargetTypeSqlElasticPool JobTargetType = "SqlElasticPool" + JobTargetTypeSqlServer JobTargetType = "SqlServer" + JobTargetTypeSqlShardMap JobTargetType = "SqlShardMap" + JobTargetTypeTargetGroup JobTargetType = "TargetGroup" +) + +func PossibleValuesForJobTargetType() []string { + return []string{ + string(JobTargetTypeSqlDatabase), + string(JobTargetTypeSqlElasticPool), + string(JobTargetTypeSqlServer), + string(JobTargetTypeSqlShardMap), + string(JobTargetTypeTargetGroup), + } +} + +func (s *JobTargetType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobTargetType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobTargetType(input string) (*JobTargetType, error) { + vals := map[string]JobTargetType{ + "sqldatabase": JobTargetTypeSqlDatabase, + "sqlelasticpool": JobTargetTypeSqlElasticPool, + "sqlserver": JobTargetTypeSqlServer, + "sqlshardmap": JobTargetTypeSqlShardMap, + "targetgroup": JobTargetTypeTargetGroup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobTargetType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + 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{ + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/id_execution.go b/resource-manager/sql/2023-08-01/jobexecutions/id_execution.go new file mode 100644 index 00000000000..d3fafcddfc5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/id_execution.go @@ -0,0 +1,157 @@ +package jobexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExecutionId{}) +} + +var _ resourceids.ResourceId = &ExecutionId{} + +// ExecutionId is a struct representing the Resource ID for a Execution +type ExecutionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + JobExecutionId string +} + +// NewExecutionID returns a new ExecutionId struct +func NewExecutionID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobExecutionId string) ExecutionId { + return ExecutionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + JobExecutionId: jobExecutionId, + } +} + +// ParseExecutionID parses 'input' into a ExecutionId +func ParseExecutionID(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExecutionIDInsensitively parses 'input' case-insensitively into a ExecutionId +// note: this method should only be used for API response data and not user input +func ParseExecutionIDInsensitively(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExecutionId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.JobExecutionId, ok = input.Parsed["jobExecutionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobExecutionId", input) + } + + return nil +} + +// ValidateExecutionID checks that 'input' can be parsed as a Execution ID +func ValidateExecutionID(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 := ParseExecutionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Execution ID +func (id ExecutionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/executions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.JobExecutionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Execution ID +func (id ExecutionId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionId"), + } +} + +// String returns a human-readable description of this Execution ID +func (id ExecutionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Job Execution: %q", id.JobExecutionId), + } + return fmt.Sprintf("Execution (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/id_execution_test.go b/resource-manager/sql/2023-08-01/jobexecutions/id_execution_test.go new file mode 100644 index 00000000000..da16d0e19ab --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/id_execution_test.go @@ -0,0 +1,417 @@ +package jobexecutions + +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 = &ExecutionId{} + +func TestNewExecutionID(t *testing.T) { + id := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.JobExecutionId != "jobExecutionId" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionId") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExecutionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + } +} + +func TestParseExecutionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + JobExecutionId: "jObExEcUtIoNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + } +} + +func TestSegmentsForExecutionId(t *testing.T) { + segments := ExecutionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExecutionId 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/sql/2023-08-01/jobexecutions/id_job.go b/resource-manager/sql/2023-08-01/jobexecutions/id_job.go new file mode 100644 index 00000000000..6f485e0cc5a --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/id_job.go @@ -0,0 +1,148 @@ +package jobexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobId{}) +} + +var _ resourceids.ResourceId = &JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + return nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/id_job_test.go b/resource-manager/sql/2023-08-01/jobexecutions/id_job_test.go new file mode 100644 index 00000000000..4fef4f8f05e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/id_job_test.go @@ -0,0 +1,372 @@ +package jobexecutions + +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 = &JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/sql/2023-08-01/jobexecutions/id_jobagent.go b/resource-manager/sql/2023-08-01/jobexecutions/id_jobagent.go new file mode 100644 index 00000000000..ec7ce87850c --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/id_jobagent.go @@ -0,0 +1,139 @@ +package jobexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobAgentId{}) +} + +var _ resourceids.ResourceId = &JobAgentId{} + +// JobAgentId is a struct representing the Resource ID for a Job Agent +type JobAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string +} + +// NewJobAgentID returns a new JobAgentId struct +func NewJobAgentID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string) JobAgentId { + return JobAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + } +} + +// ParseJobAgentID parses 'input' into a JobAgentId +func ParseJobAgentID(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobAgentIDInsensitively parses 'input' case-insensitively into a JobAgentId +// note: this method should only be used for API response data and not user input +func ParseJobAgentIDInsensitively(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + return nil +} + +// ValidateJobAgentID checks that 'input' can be parsed as a Job Agent ID +func ValidateJobAgentID(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 := ParseJobAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job Agent ID +func (id JobAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job Agent ID +func (id JobAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + } +} + +// String returns a human-readable description of this Job Agent ID +func (id JobAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + } + return fmt.Sprintf("Job Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/id_jobagent_test.go b/resource-manager/sql/2023-08-01/jobexecutions/id_jobagent_test.go new file mode 100644 index 00000000000..2843c1aa444 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/id_jobagent_test.go @@ -0,0 +1,327 @@ +package jobexecutions + +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 = &JobAgentId{} + +func TestNewJobAgentID(t *testing.T) { + id := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestParseJobAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestSegmentsForJobAgentId(t *testing.T) { + segments := JobAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobAgentId 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/sql/2023-08-01/jobexecutions/method_cancel.go b/resource-manager/sql/2023-08-01/jobexecutions/method_cancel.go new file mode 100644 index 00000000000..79fe0585b31 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/method_cancel.go @@ -0,0 +1,47 @@ +package jobexecutions + +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 CancelOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Cancel ... +func (c JobExecutionsClient) Cancel(ctx context.Context, id ExecutionId) (result CancelOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/method_create.go b/resource-manager/sql/2023-08-01/jobexecutions/method_create.go new file mode 100644 index 00000000000..6146a9583b0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/method_create.go @@ -0,0 +1,71 @@ +package jobexecutions + +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 *JobExecution +} + +// Create ... +func (c JobExecutionsClient) Create(ctx context.Context, id JobId) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 +} + +// CreateThenPoll performs Create then polls until it's completed +func (c JobExecutionsClient) CreateThenPoll(ctx context.Context, id JobId) error { + result, err := c.Create(ctx, id) + 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/sql/2023-08-01/jobexecutions/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobexecutions/method_createorupdate.go new file mode 100644 index 00000000000..30b21bf002b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/method_createorupdate.go @@ -0,0 +1,72 @@ +package jobexecutions + +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 *JobExecution +} + +// CreateOrUpdate ... +func (c JobExecutionsClient) CreateOrUpdate(ctx context.Context, id ExecutionId) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c JobExecutionsClient) CreateOrUpdateThenPoll(ctx context.Context, id ExecutionId) error { + result, err := c.CreateOrUpdate(ctx, id) + 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/sql/2023-08-01/jobexecutions/method_get.go b/resource-manager/sql/2023-08-01/jobexecutions/method_get.go new file mode 100644 index 00000000000..9c693797e4c --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/method_get.go @@ -0,0 +1,53 @@ +package jobexecutions + +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 *JobExecution +} + +// Get ... +func (c JobExecutionsClient) Get(ctx context.Context, id ExecutionId) (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 JobExecution + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/method_listbyagent.go b/resource-manager/sql/2023-08-01/jobexecutions/method_listbyagent.go new file mode 100644 index 00000000000..3a05ff3fcb6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/method_listbyagent.go @@ -0,0 +1,158 @@ +package jobexecutions + +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 ListByAgentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type ListByAgentCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type ListByAgentOperationOptions struct { + CreateTimeMax *string + CreateTimeMin *string + EndTimeMax *string + EndTimeMin *string + IsActive *bool + Skip *int64 + Top *int64 +} + +func DefaultListByAgentOperationOptions() ListByAgentOperationOptions { + return ListByAgentOperationOptions{} +} + +func (o ListByAgentOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByAgentOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByAgentOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CreateTimeMax != nil { + out.Append("createTimeMax", fmt.Sprintf("%v", *o.CreateTimeMax)) + } + if o.CreateTimeMin != nil { + out.Append("createTimeMin", fmt.Sprintf("%v", *o.CreateTimeMin)) + } + if o.EndTimeMax != nil { + out.Append("endTimeMax", fmt.Sprintf("%v", *o.EndTimeMax)) + } + if o.EndTimeMin != nil { + out.Append("endTimeMin", fmt.Sprintf("%v", *o.EndTimeMin)) + } + if o.IsActive != nil { + out.Append("isActive", fmt.Sprintf("%v", *o.IsActive)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByAgentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByAgentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByAgent ... +func (c JobExecutionsClient) ListByAgent(ctx context.Context, id JobAgentId, options ListByAgentOperationOptions) (result ListByAgentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByAgentCustomPager{}, + Path: fmt.Sprintf("%s/executions", 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 *[]JobExecution `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAgentComplete retrieves all the results into a single object +func (c JobExecutionsClient) ListByAgentComplete(ctx context.Context, id JobAgentId, options ListByAgentOperationOptions) (ListByAgentCompleteResult, error) { + return c.ListByAgentCompleteMatchingPredicate(ctx, id, options, JobExecutionOperationPredicate{}) +} + +// ListByAgentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobExecutionsClient) ListByAgentCompleteMatchingPredicate(ctx context.Context, id JobAgentId, options ListByAgentOperationOptions, predicate JobExecutionOperationPredicate) (result ListByAgentCompleteResult, err error) { + items := make([]JobExecution, 0) + + resp, err := c.ListByAgent(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAgentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/method_listbyjob.go b/resource-manager/sql/2023-08-01/jobexecutions/method_listbyjob.go new file mode 100644 index 00000000000..e757e5359ff --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/method_listbyjob.go @@ -0,0 +1,158 @@ +package jobexecutions + +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 ListByJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type ListByJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type ListByJobOperationOptions struct { + CreateTimeMax *string + CreateTimeMin *string + EndTimeMax *string + EndTimeMin *string + IsActive *bool + Skip *int64 + Top *int64 +} + +func DefaultListByJobOperationOptions() ListByJobOperationOptions { + return ListByJobOperationOptions{} +} + +func (o ListByJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CreateTimeMax != nil { + out.Append("createTimeMax", fmt.Sprintf("%v", *o.CreateTimeMax)) + } + if o.CreateTimeMin != nil { + out.Append("createTimeMin", fmt.Sprintf("%v", *o.CreateTimeMin)) + } + if o.EndTimeMax != nil { + out.Append("endTimeMax", fmt.Sprintf("%v", *o.EndTimeMax)) + } + if o.EndTimeMin != nil { + out.Append("endTimeMin", fmt.Sprintf("%v", *o.EndTimeMin)) + } + if o.IsActive != nil { + out.Append("isActive", fmt.Sprintf("%v", *o.IsActive)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByJobCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByJobCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByJob ... +func (c JobExecutionsClient) ListByJob(ctx context.Context, id JobId, options ListByJobOperationOptions) (result ListByJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByJobCustomPager{}, + Path: fmt.Sprintf("%s/executions", 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 *[]JobExecution `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByJobComplete retrieves all the results into a single object +func (c JobExecutionsClient) ListByJobComplete(ctx context.Context, id JobId, options ListByJobOperationOptions) (ListByJobCompleteResult, error) { + return c.ListByJobCompleteMatchingPredicate(ctx, id, options, JobExecutionOperationPredicate{}) +} + +// ListByJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobExecutionsClient) ListByJobCompleteMatchingPredicate(ctx context.Context, id JobId, options ListByJobOperationOptions, predicate JobExecutionOperationPredicate) (result ListByJobCompleteResult, err error) { + items := make([]JobExecution, 0) + + resp, err := c.ListByJob(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecution.go b/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecution.go new file mode 100644 index 00000000000..f47665c9a2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecution.go @@ -0,0 +1,11 @@ +package jobexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecution struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobExecutionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutionproperties.go b/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutionproperties.go new file mode 100644 index 00000000000..81a73ba7318 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutionproperties.go @@ -0,0 +1,74 @@ +package jobexecutions + +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 JobExecutionProperties struct { + CreateTime *string `json:"createTime,omitempty"` + CurrentAttemptStartTime *string `json:"currentAttemptStartTime,omitempty"` + CurrentAttempts *int64 `json:"currentAttempts,omitempty"` + EndTime *string `json:"endTime,omitempty"` + JobExecutionId *string `json:"jobExecutionId,omitempty"` + JobVersion *int64 `json:"jobVersion,omitempty"` + LastMessage *string `json:"lastMessage,omitempty"` + Lifecycle *JobExecutionLifecycle `json:"lifecycle,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + StartTime *string `json:"startTime,omitempty"` + StepId *int64 `json:"stepId,omitempty"` + StepName *string `json:"stepName,omitempty"` + Target *JobExecutionTarget `json:"target,omitempty"` +} + +func (o *JobExecutionProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} + +func (o *JobExecutionProperties) GetCurrentAttemptStartTimeAsTime() (*time.Time, error) { + if o.CurrentAttemptStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CurrentAttemptStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetCurrentAttemptStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CurrentAttemptStartTime = &formatted +} + +func (o *JobExecutionProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobExecutionProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutiontarget.go b/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutiontarget.go new file mode 100644 index 00000000000..88547aaba3e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/model_jobexecutiontarget.go @@ -0,0 +1,10 @@ +package jobexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionTarget struct { + DatabaseName *string `json:"databaseName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Type *JobTargetType `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobexecutions/predicates.go b/resource-manager/sql/2023-08-01/jobexecutions/predicates.go new file mode 100644 index 00000000000..0f0cadef69d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/predicates.go @@ -0,0 +1,27 @@ +package jobexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobExecutionOperationPredicate) Matches(input JobExecution) 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/sql/2023-08-01/jobexecutions/version.go b/resource-manager/sql/2023-08-01/jobexecutions/version.go new file mode 100644 index 00000000000..e4180f00d4b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobexecutions/version.go @@ -0,0 +1,10 @@ +package jobexecutions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobexecutions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/README.md b/resource-manager/sql/2023-08-01/jobprivateendpoints/README.md new file mode 100644 index 00000000000..d0e40e0b6e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobprivateendpoints` Documentation + +The `jobprivateendpoints` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobprivateendpoints" +``` + + +### Client Initialization + +```go +client := jobprivateendpoints.NewJobPrivateEndpointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobPrivateEndpointsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobprivateendpoints.NewPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "privateEndpointName") + +payload := jobprivateendpoints.JobPrivateEndpoint{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobPrivateEndpointsClient.Delete` + +```go +ctx := context.TODO() +id := jobprivateendpoints.NewPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "privateEndpointName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `JobPrivateEndpointsClient.Get` + +```go +ctx := context.TODO() +id := jobprivateendpoints.NewPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "privateEndpointName") + +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: `JobPrivateEndpointsClient.ListByAgent` + +```go +ctx := context.TODO() +id := jobprivateendpoints.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +// alternatively `client.ListByAgent(ctx, id)` can be used to do batched pagination +items, err := client.ListByAgentComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/client.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/client.go new file mode 100644 index 00000000000..dafe168f98e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/client.go @@ -0,0 +1,26 @@ +package jobprivateendpoints + +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 JobPrivateEndpointsClient struct { + Client *resourcemanager.Client +} + +func NewJobPrivateEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobPrivateEndpointsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobprivateendpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobPrivateEndpointsClient: %+v", err) + } + + return &JobPrivateEndpointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent.go new file mode 100644 index 00000000000..9e996d56c70 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent.go @@ -0,0 +1,139 @@ +package jobprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobAgentId{}) +} + +var _ resourceids.ResourceId = &JobAgentId{} + +// JobAgentId is a struct representing the Resource ID for a Job Agent +type JobAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string +} + +// NewJobAgentID returns a new JobAgentId struct +func NewJobAgentID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string) JobAgentId { + return JobAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + } +} + +// ParseJobAgentID parses 'input' into a JobAgentId +func ParseJobAgentID(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobAgentIDInsensitively parses 'input' case-insensitively into a JobAgentId +// note: this method should only be used for API response data and not user input +func ParseJobAgentIDInsensitively(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + return nil +} + +// ValidateJobAgentID checks that 'input' can be parsed as a Job Agent ID +func ValidateJobAgentID(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 := ParseJobAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job Agent ID +func (id JobAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job Agent ID +func (id JobAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + } +} + +// String returns a human-readable description of this Job Agent ID +func (id JobAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + } + return fmt.Sprintf("Job Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent_test.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent_test.go new file mode 100644 index 00000000000..33da6551017 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_jobagent_test.go @@ -0,0 +1,327 @@ +package jobprivateendpoints + +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 = &JobAgentId{} + +func TestNewJobAgentID(t *testing.T) { + id := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestParseJobAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestSegmentsForJobAgentId(t *testing.T) { + segments := JobAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobAgentId 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/sql/2023-08-01/jobprivateendpoints/id_privateendpoint.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint.go new file mode 100644 index 00000000000..6b729b7b292 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint.go @@ -0,0 +1,148 @@ +package jobprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointId{} + +// PrivateEndpointId is a struct representing the Resource ID for a Private Endpoint +type PrivateEndpointId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + PrivateEndpointName string +} + +// NewPrivateEndpointID returns a new PrivateEndpointId struct +func NewPrivateEndpointID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, privateEndpointName string) PrivateEndpointId { + return PrivateEndpointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + PrivateEndpointName: privateEndpointName, + } +} + +// ParsePrivateEndpointID parses 'input' into a PrivateEndpointId +func ParsePrivateEndpointID(input string) (*PrivateEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointIDInsensitively parses 'input' case-insensitively into a PrivateEndpointId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointIDInsensitively(input string) (*PrivateEndpointId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.PrivateEndpointName, ok = input.Parsed["privateEndpointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointName", input) + } + + return nil +} + +// ValidatePrivateEndpointID checks that 'input' can be parsed as a Private Endpoint ID +func ValidatePrivateEndpointID(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 := ParsePrivateEndpointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint ID +func (id PrivateEndpointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/privateEndpoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.PrivateEndpointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint ID +func (id PrivateEndpointId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticPrivateEndpoints", "privateEndpoints", "privateEndpoints"), + resourceids.UserSpecifiedSegment("privateEndpointName", "privateEndpointName"), + } +} + +// String returns a human-readable description of this Private Endpoint ID +func (id PrivateEndpointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Private Endpoint Name: %q", id.PrivateEndpointName), + } + return fmt.Sprintf("Private Endpoint (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint_test.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint_test.go new file mode 100644 index 00000000000..0430cb22000 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/id_privateendpoint_test.go @@ -0,0 +1,372 @@ +package jobprivateendpoints + +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 = &PrivateEndpointId{} + +func TestNewPrivateEndpointID(t *testing.T) { + id := NewPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "privateEndpointName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.PrivateEndpointName != "privateEndpointName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointName'", id.PrivateEndpointName, "privateEndpointName") + } +} + +func TestFormatPrivateEndpointID(t *testing.T) { + actual := NewPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "privateEndpointName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints/privateEndpointName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints/privateEndpointName", + Expected: &PrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + PrivateEndpointName: "privateEndpointName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints/privateEndpointName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.PrivateEndpointName != v.Expected.PrivateEndpointName { + t.Fatalf("Expected %q but got %q for PrivateEndpointName", v.Expected.PrivateEndpointName, actual.PrivateEndpointName) + } + + } +} + +func TestParsePrivateEndpointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/pRiVaTeEnDpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints/privateEndpointName", + Expected: &PrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + PrivateEndpointName: "privateEndpointName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/privateEndpoints/privateEndpointName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/pRiVaTeEnDpOiNtS/pRiVaTeEnDpOiNtNaMe", + Expected: &PrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + PrivateEndpointName: "pRiVaTeEnDpOiNtNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/pRiVaTeEnDpOiNtS/pRiVaTeEnDpOiNtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.PrivateEndpointName != v.Expected.PrivateEndpointName { + t.Fatalf("Expected %q but got %q for PrivateEndpointName", v.Expected.PrivateEndpointName, actual.PrivateEndpointName) + } + + } +} + +func TestSegmentsForPrivateEndpointId(t *testing.T) { + segments := PrivateEndpointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointId 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/sql/2023-08-01/jobprivateendpoints/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_createorupdate.go new file mode 100644 index 00000000000..36cd8f7a491 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_createorupdate.go @@ -0,0 +1,76 @@ +package jobprivateendpoints + +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 *JobPrivateEndpoint +} + +// CreateOrUpdate ... +func (c JobPrivateEndpointsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointId, input JobPrivateEndpoint) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 JobPrivateEndpointsClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointId, input JobPrivateEndpoint) 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/sql/2023-08-01/jobprivateendpoints/method_delete.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_delete.go new file mode 100644 index 00000000000..df3d5dcf270 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_delete.go @@ -0,0 +1,71 @@ +package jobprivateendpoints + +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 JobPrivateEndpointsClient) Delete(ctx context.Context, id PrivateEndpointId) (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 JobPrivateEndpointsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointId) 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/sql/2023-08-01/jobprivateendpoints/method_get.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_get.go new file mode 100644 index 00000000000..02f75d07cc3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_get.go @@ -0,0 +1,53 @@ +package jobprivateendpoints + +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 *JobPrivateEndpoint +} + +// Get ... +func (c JobPrivateEndpointsClient) Get(ctx context.Context, id PrivateEndpointId) (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 JobPrivateEndpoint + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/method_listbyagent.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_listbyagent.go new file mode 100644 index 00000000000..45358ace395 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/method_listbyagent.go @@ -0,0 +1,105 @@ +package jobprivateendpoints + +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 ListByAgentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobPrivateEndpoint +} + +type ListByAgentCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobPrivateEndpoint +} + +type ListByAgentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByAgentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByAgent ... +func (c JobPrivateEndpointsClient) ListByAgent(ctx context.Context, id JobAgentId) (result ListByAgentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByAgentCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpoints", 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 *[]JobPrivateEndpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAgentComplete retrieves all the results into a single object +func (c JobPrivateEndpointsClient) ListByAgentComplete(ctx context.Context, id JobAgentId) (ListByAgentCompleteResult, error) { + return c.ListByAgentCompleteMatchingPredicate(ctx, id, JobPrivateEndpointOperationPredicate{}) +} + +// ListByAgentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobPrivateEndpointsClient) ListByAgentCompleteMatchingPredicate(ctx context.Context, id JobAgentId, predicate JobPrivateEndpointOperationPredicate) (result ListByAgentCompleteResult, err error) { + items := make([]JobPrivateEndpoint, 0) + + resp, err := c.ListByAgent(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAgentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpoint.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpoint.go new file mode 100644 index 00000000000..af327b4af92 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpoint.go @@ -0,0 +1,11 @@ +package jobprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobPrivateEndpoint struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobPrivateEndpointProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpointproperties.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpointproperties.go new file mode 100644 index 00000000000..7d1cc9cd131 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/model_jobprivateendpointproperties.go @@ -0,0 +1,9 @@ +package jobprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobPrivateEndpointProperties struct { + PrivateEndpointId *string `json:"privateEndpointId,omitempty"` + TargetServerAzureResourceId string `json:"targetServerAzureResourceId"` +} diff --git a/resource-manager/sql/2023-08-01/jobprivateendpoints/predicates.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/predicates.go new file mode 100644 index 00000000000..087227b91fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/predicates.go @@ -0,0 +1,27 @@ +package jobprivateendpoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobPrivateEndpointOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobPrivateEndpointOperationPredicate) Matches(input JobPrivateEndpoint) 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/sql/2023-08-01/jobprivateendpoints/version.go b/resource-manager/sql/2023-08-01/jobprivateendpoints/version.go new file mode 100644 index 00000000000..f9d11e12228 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobprivateendpoints/version.go @@ -0,0 +1,10 @@ +package jobprivateendpoints + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobprivateendpoints/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobs/README.md b/resource-manager/sql/2023-08-01/jobs/README.md new file mode 100644 index 00000000000..6623dc19984 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobs` Documentation + +The `jobs` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobs" +``` + + +### Client Initialization + +```go +client := jobs.NewJobsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +payload := jobs.Job{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobsClient.Delete` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobsClient.Get` + +```go +ctx := context.TODO() +id := jobs.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +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: `JobsClient.ListByAgent` + +```go +ctx := context.TODO() +id := jobs.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +// alternatively `client.ListByAgent(ctx, id)` can be used to do batched pagination +items, err := client.ListByAgentComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobs/client.go b/resource-manager/sql/2023-08-01/jobs/client.go new file mode 100644 index 00000000000..762c577e9e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/client.go @@ -0,0 +1,26 @@ +package jobs + +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 JobsClient struct { + Client *resourcemanager.Client +} + +func NewJobsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobsClient: %+v", err) + } + + return &JobsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobs/constants.go b/resource-manager/sql/2023-08-01/jobs/constants.go new file mode 100644 index 00000000000..2021912af6b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/constants.go @@ -0,0 +1,51 @@ +package jobs + +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 JobScheduleType string + +const ( + JobScheduleTypeOnce JobScheduleType = "Once" + JobScheduleTypeRecurring JobScheduleType = "Recurring" +) + +func PossibleValuesForJobScheduleType() []string { + return []string{ + string(JobScheduleTypeOnce), + string(JobScheduleTypeRecurring), + } +} + +func (s *JobScheduleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobScheduleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobScheduleType(input string) (*JobScheduleType, error) { + vals := map[string]JobScheduleType{ + "once": JobScheduleTypeOnce, + "recurring": JobScheduleTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobScheduleType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/jobs/id_job.go b/resource-manager/sql/2023-08-01/jobs/id_job.go new file mode 100644 index 00000000000..2ec039e7952 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/id_job.go @@ -0,0 +1,148 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobId{}) +} + +var _ resourceids.ResourceId = &JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + return nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobs/id_job_test.go b/resource-manager/sql/2023-08-01/jobs/id_job_test.go new file mode 100644 index 00000000000..c7319003e1e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/id_job_test.go @@ -0,0 +1,372 @@ +package jobs + +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 = &JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/sql/2023-08-01/jobs/id_jobagent.go b/resource-manager/sql/2023-08-01/jobs/id_jobagent.go new file mode 100644 index 00000000000..bdefa8a6d22 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/id_jobagent.go @@ -0,0 +1,139 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobAgentId{}) +} + +var _ resourceids.ResourceId = &JobAgentId{} + +// JobAgentId is a struct representing the Resource ID for a Job Agent +type JobAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string +} + +// NewJobAgentID returns a new JobAgentId struct +func NewJobAgentID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string) JobAgentId { + return JobAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + } +} + +// ParseJobAgentID parses 'input' into a JobAgentId +func ParseJobAgentID(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobAgentIDInsensitively parses 'input' case-insensitively into a JobAgentId +// note: this method should only be used for API response data and not user input +func ParseJobAgentIDInsensitively(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + return nil +} + +// ValidateJobAgentID checks that 'input' can be parsed as a Job Agent ID +func ValidateJobAgentID(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 := ParseJobAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job Agent ID +func (id JobAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job Agent ID +func (id JobAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + } +} + +// String returns a human-readable description of this Job Agent ID +func (id JobAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + } + return fmt.Sprintf("Job Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobs/id_jobagent_test.go b/resource-manager/sql/2023-08-01/jobs/id_jobagent_test.go new file mode 100644 index 00000000000..eafa1ea423e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/id_jobagent_test.go @@ -0,0 +1,327 @@ +package jobs + +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 = &JobAgentId{} + +func TestNewJobAgentID(t *testing.T) { + id := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestParseJobAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestSegmentsForJobAgentId(t *testing.T) { + segments := JobAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobAgentId 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/sql/2023-08-01/jobs/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobs/method_createorupdate.go new file mode 100644 index 00000000000..f3c623fcd53 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/method_createorupdate.go @@ -0,0 +1,58 @@ +package jobs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Job +} + +// CreateOrUpdate ... +func (c JobsClient) CreateOrUpdate(ctx context.Context, id JobId, input Job) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Job + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobs/method_delete.go b/resource-manager/sql/2023-08-01/jobs/method_delete.go new file mode 100644 index 00000000000..4e65e20fc82 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/method_delete.go @@ -0,0 +1,47 @@ +package jobs + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c JobsClient) Delete(ctx context.Context, id JobId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobs/method_get.go b/resource-manager/sql/2023-08-01/jobs/method_get.go new file mode 100644 index 00000000000..92dd9e2cf39 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/method_get.go @@ -0,0 +1,53 @@ +package jobs + +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 *Job +} + +// Get ... +func (c JobsClient) Get(ctx context.Context, id JobId) (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 Job + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobs/method_listbyagent.go b/resource-manager/sql/2023-08-01/jobs/method_listbyagent.go new file mode 100644 index 00000000000..ae393a334fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/method_listbyagent.go @@ -0,0 +1,105 @@ +package jobs + +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 ListByAgentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Job +} + +type ListByAgentCompleteResult struct { + LatestHttpResponse *http.Response + Items []Job +} + +type ListByAgentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByAgentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByAgent ... +func (c JobsClient) ListByAgent(ctx context.Context, id JobAgentId) (result ListByAgentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByAgentCustomPager{}, + Path: fmt.Sprintf("%s/jobs", 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 *[]Job `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAgentComplete retrieves all the results into a single object +func (c JobsClient) ListByAgentComplete(ctx context.Context, id JobAgentId) (ListByAgentCompleteResult, error) { + return c.ListByAgentCompleteMatchingPredicate(ctx, id, JobOperationPredicate{}) +} + +// ListByAgentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobsClient) ListByAgentCompleteMatchingPredicate(ctx context.Context, id JobAgentId, predicate JobOperationPredicate) (result ListByAgentCompleteResult, err error) { + items := make([]Job, 0) + + resp, err := c.ListByAgent(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAgentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobs/model_job.go b/resource-manager/sql/2023-08-01/jobs/model_job.go new file mode 100644 index 00000000000..ec2235381d8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/model_job.go @@ -0,0 +1,11 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Job struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobs/model_jobproperties.go b/resource-manager/sql/2023-08-01/jobs/model_jobproperties.go new file mode 100644 index 00000000000..bf61507564b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/model_jobproperties.go @@ -0,0 +1,10 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobProperties struct { + Description *string `json:"description,omitempty"` + Schedule *JobSchedule `json:"schedule,omitempty"` + Version *int64 `json:"version,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobs/model_jobschedule.go b/resource-manager/sql/2023-08-01/jobs/model_jobschedule.go new file mode 100644 index 00000000000..dda50f7119d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/model_jobschedule.go @@ -0,0 +1,42 @@ +package jobs + +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 JobSchedule struct { + Enabled *bool `json:"enabled,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Interval *string `json:"interval,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Type *JobScheduleType `json:"type,omitempty"` +} + +func (o *JobSchedule) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobSchedule) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobSchedule) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobSchedule) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/jobs/predicates.go b/resource-manager/sql/2023-08-01/jobs/predicates.go new file mode 100644 index 00000000000..8326102dc52 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/predicates.go @@ -0,0 +1,27 @@ +package jobs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobOperationPredicate) Matches(input Job) 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/sql/2023-08-01/jobs/version.go b/resource-manager/sql/2023-08-01/jobs/version.go new file mode 100644 index 00000000000..07a2c2357ce --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobs/version.go @@ -0,0 +1,10 @@ +package jobs + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobs/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/README.md b/resource-manager/sql/2023-08-01/jobstepexecutions/README.md new file mode 100644 index 00000000000..464c22cb515 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobstepexecutions` Documentation + +The `jobstepexecutions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobstepexecutions" +``` + + +### Client Initialization + +```go +client := jobstepexecutions.NewJobStepExecutionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobStepExecutionsClient.Get` + +```go +ctx := context.TODO() +id := jobstepexecutions.NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName") + +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: `JobStepExecutionsClient.ListByJobExecution` + +```go +ctx := context.TODO() +id := jobstepexecutions.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + +// alternatively `client.ListByJobExecution(ctx, id, jobstepexecutions.DefaultListByJobExecutionOperationOptions())` can be used to do batched pagination +items, err := client.ListByJobExecutionComplete(ctx, id, jobstepexecutions.DefaultListByJobExecutionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/client.go b/resource-manager/sql/2023-08-01/jobstepexecutions/client.go new file mode 100644 index 00000000000..097a54ba533 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/client.go @@ -0,0 +1,26 @@ +package jobstepexecutions + +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 JobStepExecutionsClient struct { + Client *resourcemanager.Client +} + +func NewJobStepExecutionsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobStepExecutionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobstepexecutions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobStepExecutionsClient: %+v", err) + } + + return &JobStepExecutionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/constants.go b/resource-manager/sql/2023-08-01/jobstepexecutions/constants.go new file mode 100644 index 00000000000..7cca81c5e81 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/constants.go @@ -0,0 +1,175 @@ +package jobstepexecutions + +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 JobExecutionLifecycle string + +const ( + JobExecutionLifecycleCanceled JobExecutionLifecycle = "Canceled" + JobExecutionLifecycleCreated JobExecutionLifecycle = "Created" + JobExecutionLifecycleFailed JobExecutionLifecycle = "Failed" + JobExecutionLifecycleInProgress JobExecutionLifecycle = "InProgress" + JobExecutionLifecycleSkipped JobExecutionLifecycle = "Skipped" + JobExecutionLifecycleSucceeded JobExecutionLifecycle = "Succeeded" + JobExecutionLifecycleSucceededWithSkipped JobExecutionLifecycle = "SucceededWithSkipped" + JobExecutionLifecycleTimedOut JobExecutionLifecycle = "TimedOut" + JobExecutionLifecycleWaitingForChildJobExecutions JobExecutionLifecycle = "WaitingForChildJobExecutions" + JobExecutionLifecycleWaitingForRetry JobExecutionLifecycle = "WaitingForRetry" +) + +func PossibleValuesForJobExecutionLifecycle() []string { + return []string{ + string(JobExecutionLifecycleCanceled), + string(JobExecutionLifecycleCreated), + string(JobExecutionLifecycleFailed), + string(JobExecutionLifecycleInProgress), + string(JobExecutionLifecycleSkipped), + string(JobExecutionLifecycleSucceeded), + string(JobExecutionLifecycleSucceededWithSkipped), + string(JobExecutionLifecycleTimedOut), + string(JobExecutionLifecycleWaitingForChildJobExecutions), + string(JobExecutionLifecycleWaitingForRetry), + } +} + +func (s *JobExecutionLifecycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobExecutionLifecycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobExecutionLifecycle(input string) (*JobExecutionLifecycle, error) { + vals := map[string]JobExecutionLifecycle{ + "canceled": JobExecutionLifecycleCanceled, + "created": JobExecutionLifecycleCreated, + "failed": JobExecutionLifecycleFailed, + "inprogress": JobExecutionLifecycleInProgress, + "skipped": JobExecutionLifecycleSkipped, + "succeeded": JobExecutionLifecycleSucceeded, + "succeededwithskipped": JobExecutionLifecycleSucceededWithSkipped, + "timedout": JobExecutionLifecycleTimedOut, + "waitingforchildjobexecutions": JobExecutionLifecycleWaitingForChildJobExecutions, + "waitingforretry": JobExecutionLifecycleWaitingForRetry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobExecutionLifecycle(input) + return &out, nil +} + +type JobTargetType string + +const ( + JobTargetTypeSqlDatabase JobTargetType = "SqlDatabase" + JobTargetTypeSqlElasticPool JobTargetType = "SqlElasticPool" + JobTargetTypeSqlServer JobTargetType = "SqlServer" + JobTargetTypeSqlShardMap JobTargetType = "SqlShardMap" + JobTargetTypeTargetGroup JobTargetType = "TargetGroup" +) + +func PossibleValuesForJobTargetType() []string { + return []string{ + string(JobTargetTypeSqlDatabase), + string(JobTargetTypeSqlElasticPool), + string(JobTargetTypeSqlServer), + string(JobTargetTypeSqlShardMap), + string(JobTargetTypeTargetGroup), + } +} + +func (s *JobTargetType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobTargetType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobTargetType(input string) (*JobTargetType, error) { + vals := map[string]JobTargetType{ + "sqldatabase": JobTargetTypeSqlDatabase, + "sqlelasticpool": JobTargetTypeSqlElasticPool, + "sqlserver": JobTargetTypeSqlServer, + "sqlshardmap": JobTargetTypeSqlShardMap, + "targetgroup": JobTargetTypeTargetGroup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobTargetType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + 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{ + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/id_execution.go b/resource-manager/sql/2023-08-01/jobstepexecutions/id_execution.go new file mode 100644 index 00000000000..785385d8d0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/id_execution.go @@ -0,0 +1,157 @@ +package jobstepexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExecutionId{}) +} + +var _ resourceids.ResourceId = &ExecutionId{} + +// ExecutionId is a struct representing the Resource ID for a Execution +type ExecutionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + JobExecutionId string +} + +// NewExecutionID returns a new ExecutionId struct +func NewExecutionID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobExecutionId string) ExecutionId { + return ExecutionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + JobExecutionId: jobExecutionId, + } +} + +// ParseExecutionID parses 'input' into a ExecutionId +func ParseExecutionID(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExecutionIDInsensitively parses 'input' case-insensitively into a ExecutionId +// note: this method should only be used for API response data and not user input +func ParseExecutionIDInsensitively(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExecutionId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.JobExecutionId, ok = input.Parsed["jobExecutionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobExecutionId", input) + } + + return nil +} + +// ValidateExecutionID checks that 'input' can be parsed as a Execution ID +func ValidateExecutionID(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 := ParseExecutionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Execution ID +func (id ExecutionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/executions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.JobExecutionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Execution ID +func (id ExecutionId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionId"), + } +} + +// String returns a human-readable description of this Execution ID +func (id ExecutionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Job Execution: %q", id.JobExecutionId), + } + return fmt.Sprintf("Execution (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/id_execution_test.go b/resource-manager/sql/2023-08-01/jobstepexecutions/id_execution_test.go new file mode 100644 index 00000000000..048f71bf3f8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/id_execution_test.go @@ -0,0 +1,417 @@ +package jobstepexecutions + +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 = &ExecutionId{} + +func TestNewExecutionID(t *testing.T) { + id := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.JobExecutionId != "jobExecutionId" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionId") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExecutionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + } +} + +func TestParseExecutionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + JobExecutionId: "jObExEcUtIoNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + } +} + +func TestSegmentsForExecutionId(t *testing.T) { + segments := ExecutionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExecutionId 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/sql/2023-08-01/jobstepexecutions/id_executionstep.go b/resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep.go new file mode 100644 index 00000000000..5ac389b2eaf --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep.go @@ -0,0 +1,166 @@ +package jobstepexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExecutionStepId{}) +} + +var _ resourceids.ResourceId = &ExecutionStepId{} + +// ExecutionStepId is a struct representing the Resource ID for a Execution Step +type ExecutionStepId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + JobExecutionId string + StepName string +} + +// NewExecutionStepID returns a new ExecutionStepId struct +func NewExecutionStepID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobExecutionId string, stepName string) ExecutionStepId { + return ExecutionStepId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + JobExecutionId: jobExecutionId, + StepName: stepName, + } +} + +// ParseExecutionStepID parses 'input' into a ExecutionStepId +func ParseExecutionStepID(input string) (*ExecutionStepId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionStepId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionStepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExecutionStepIDInsensitively parses 'input' case-insensitively into a ExecutionStepId +// note: this method should only be used for API response data and not user input +func ParseExecutionStepIDInsensitively(input string) (*ExecutionStepId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionStepId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionStepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExecutionStepId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.JobExecutionId, ok = input.Parsed["jobExecutionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobExecutionId", input) + } + + if id.StepName, ok = input.Parsed["stepName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "stepName", input) + } + + return nil +} + +// ValidateExecutionStepID checks that 'input' can be parsed as a Execution Step ID +func ValidateExecutionStepID(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 := ParseExecutionStepID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Execution Step ID +func (id ExecutionStepId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/executions/%s/steps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.JobExecutionId, id.StepName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Execution Step ID +func (id ExecutionStepId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionId"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepName"), + } +} + +// String returns a human-readable description of this Execution Step ID +func (id ExecutionStepId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Job Execution: %q", id.JobExecutionId), + fmt.Sprintf("Step Name: %q", id.StepName), + } + return fmt.Sprintf("Execution Step (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep_test.go b/resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep_test.go new file mode 100644 index 00000000000..b6b5233484e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/id_executionstep_test.go @@ -0,0 +1,462 @@ +package jobstepexecutions + +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 = &ExecutionStepId{} + +func TestNewExecutionStepID(t *testing.T) { + id := NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.JobExecutionId != "jobExecutionId" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionId") + } + + if id.StepName != "stepName" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepName") + } +} + +func TestFormatExecutionStepID(t *testing.T) { + actual := NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExecutionStepID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionStepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionStepID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestParseExecutionStepIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionStepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + JobExecutionId: "jObExEcUtIoNiD", + StepName: "sTePnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionStepIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestSegmentsForExecutionStepId(t *testing.T) { + segments := ExecutionStepId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExecutionStepId 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/sql/2023-08-01/jobstepexecutions/method_get.go b/resource-manager/sql/2023-08-01/jobstepexecutions/method_get.go new file mode 100644 index 00000000000..0eb160b968b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/method_get.go @@ -0,0 +1,53 @@ +package jobstepexecutions + +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 *JobExecution +} + +// Get ... +func (c JobStepExecutionsClient) Get(ctx context.Context, id ExecutionStepId) (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 JobExecution + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/method_listbyjobexecution.go b/resource-manager/sql/2023-08-01/jobstepexecutions/method_listbyjobexecution.go new file mode 100644 index 00000000000..b3a448d3137 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/method_listbyjobexecution.go @@ -0,0 +1,158 @@ +package jobstepexecutions + +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 ListByJobExecutionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type ListByJobExecutionCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type ListByJobExecutionOperationOptions struct { + CreateTimeMax *string + CreateTimeMin *string + EndTimeMax *string + EndTimeMin *string + IsActive *bool + Skip *int64 + Top *int64 +} + +func DefaultListByJobExecutionOperationOptions() ListByJobExecutionOperationOptions { + return ListByJobExecutionOperationOptions{} +} + +func (o ListByJobExecutionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByJobExecutionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByJobExecutionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CreateTimeMax != nil { + out.Append("createTimeMax", fmt.Sprintf("%v", *o.CreateTimeMax)) + } + if o.CreateTimeMin != nil { + out.Append("createTimeMin", fmt.Sprintf("%v", *o.CreateTimeMin)) + } + if o.EndTimeMax != nil { + out.Append("endTimeMax", fmt.Sprintf("%v", *o.EndTimeMax)) + } + if o.EndTimeMin != nil { + out.Append("endTimeMin", fmt.Sprintf("%v", *o.EndTimeMin)) + } + if o.IsActive != nil { + out.Append("isActive", fmt.Sprintf("%v", *o.IsActive)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByJobExecutionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByJobExecutionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByJobExecution ... +func (c JobStepExecutionsClient) ListByJobExecution(ctx context.Context, id ExecutionId, options ListByJobExecutionOperationOptions) (result ListByJobExecutionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByJobExecutionCustomPager{}, + Path: fmt.Sprintf("%s/steps", 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 *[]JobExecution `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByJobExecutionComplete retrieves all the results into a single object +func (c JobStepExecutionsClient) ListByJobExecutionComplete(ctx context.Context, id ExecutionId, options ListByJobExecutionOperationOptions) (ListByJobExecutionCompleteResult, error) { + return c.ListByJobExecutionCompleteMatchingPredicate(ctx, id, options, JobExecutionOperationPredicate{}) +} + +// ListByJobExecutionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobStepExecutionsClient) ListByJobExecutionCompleteMatchingPredicate(ctx context.Context, id ExecutionId, options ListByJobExecutionOperationOptions, predicate JobExecutionOperationPredicate) (result ListByJobExecutionCompleteResult, err error) { + items := make([]JobExecution, 0) + + resp, err := c.ListByJobExecution(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByJobExecutionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecution.go b/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecution.go new file mode 100644 index 00000000000..a7361f60af2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecution.go @@ -0,0 +1,11 @@ +package jobstepexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecution struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobExecutionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutionproperties.go b/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutionproperties.go new file mode 100644 index 00000000000..dfee2c5daa7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutionproperties.go @@ -0,0 +1,74 @@ +package jobstepexecutions + +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 JobExecutionProperties struct { + CreateTime *string `json:"createTime,omitempty"` + CurrentAttemptStartTime *string `json:"currentAttemptStartTime,omitempty"` + CurrentAttempts *int64 `json:"currentAttempts,omitempty"` + EndTime *string `json:"endTime,omitempty"` + JobExecutionId *string `json:"jobExecutionId,omitempty"` + JobVersion *int64 `json:"jobVersion,omitempty"` + LastMessage *string `json:"lastMessage,omitempty"` + Lifecycle *JobExecutionLifecycle `json:"lifecycle,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + StartTime *string `json:"startTime,omitempty"` + StepId *int64 `json:"stepId,omitempty"` + StepName *string `json:"stepName,omitempty"` + Target *JobExecutionTarget `json:"target,omitempty"` +} + +func (o *JobExecutionProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} + +func (o *JobExecutionProperties) GetCurrentAttemptStartTimeAsTime() (*time.Time, error) { + if o.CurrentAttemptStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CurrentAttemptStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetCurrentAttemptStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CurrentAttemptStartTime = &formatted +} + +func (o *JobExecutionProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobExecutionProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutiontarget.go b/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutiontarget.go new file mode 100644 index 00000000000..f7643a6db42 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/model_jobexecutiontarget.go @@ -0,0 +1,10 @@ +package jobstepexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionTarget struct { + DatabaseName *string `json:"databaseName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Type *JobTargetType `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobstepexecutions/predicates.go b/resource-manager/sql/2023-08-01/jobstepexecutions/predicates.go new file mode 100644 index 00000000000..9108f574a01 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/predicates.go @@ -0,0 +1,27 @@ +package jobstepexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobExecutionOperationPredicate) Matches(input JobExecution) 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/sql/2023-08-01/jobstepexecutions/version.go b/resource-manager/sql/2023-08-01/jobstepexecutions/version.go new file mode 100644 index 00000000000..3a522b3e5fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobstepexecutions/version.go @@ -0,0 +1,10 @@ +package jobstepexecutions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobstepexecutions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/README.md b/resource-manager/sql/2023-08-01/jobsteps/README.md new file mode 100644 index 00000000000..f458c0dc614 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/README.md @@ -0,0 +1,123 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobsteps` Documentation + +The `jobsteps` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobsteps" +``` + + +### Client Initialization + +```go +client := jobsteps.NewJobStepsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobStepsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobsteps.NewStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "stepName") + +payload := jobsteps.JobStep{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobStepsClient.Delete` + +```go +ctx := context.TODO() +id := jobsteps.NewStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "stepName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobStepsClient.Get` + +```go +ctx := context.TODO() +id := jobsteps.NewStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "stepName") + +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: `JobStepsClient.GetByVersion` + +```go +ctx := context.TODO() +id := jobsteps.NewVersionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName", "stepName") + +read, err := client.GetByVersion(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobStepsClient.ListByJob` + +```go +ctx := context.TODO() +id := jobsteps.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +// alternatively `client.ListByJob(ctx, id)` can be used to do batched pagination +items, err := client.ListByJobComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobStepsClient.ListByVersion` + +```go +ctx := context.TODO() +id := jobsteps.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName") + +// alternatively `client.ListByVersion(ctx, id)` can be used to do batched pagination +items, err := client.ListByVersionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobsteps/client.go b/resource-manager/sql/2023-08-01/jobsteps/client.go new file mode 100644 index 00000000000..51ed069463b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/client.go @@ -0,0 +1,26 @@ +package jobsteps + +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 JobStepsClient struct { + Client *resourcemanager.Client +} + +func NewJobStepsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobStepsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobsteps", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobStepsClient: %+v", err) + } + + return &JobStepsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/constants.go b/resource-manager/sql/2023-08-01/jobsteps/constants.go new file mode 100644 index 00000000000..799623e6119 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/constants.go @@ -0,0 +1,124 @@ +package jobsteps + +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 JobStepActionSource string + +const ( + JobStepActionSourceInline JobStepActionSource = "Inline" +) + +func PossibleValuesForJobStepActionSource() []string { + return []string{ + string(JobStepActionSourceInline), + } +} + +func (s *JobStepActionSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobStepActionSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobStepActionSource(input string) (*JobStepActionSource, error) { + vals := map[string]JobStepActionSource{ + "inline": JobStepActionSourceInline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobStepActionSource(input) + return &out, nil +} + +type JobStepActionType string + +const ( + JobStepActionTypeTSql JobStepActionType = "TSql" +) + +func PossibleValuesForJobStepActionType() []string { + return []string{ + string(JobStepActionTypeTSql), + } +} + +func (s *JobStepActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobStepActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobStepActionType(input string) (*JobStepActionType, error) { + vals := map[string]JobStepActionType{ + "tsql": JobStepActionTypeTSql, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobStepActionType(input) + return &out, nil +} + +type JobStepOutputType string + +const ( + JobStepOutputTypeSqlDatabase JobStepOutputType = "SqlDatabase" +) + +func PossibleValuesForJobStepOutputType() []string { + return []string{ + string(JobStepOutputTypeSqlDatabase), + } +} + +func (s *JobStepOutputType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobStepOutputType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobStepOutputType(input string) (*JobStepOutputType, error) { + vals := map[string]JobStepOutputType{ + "sqldatabase": JobStepOutputTypeSqlDatabase, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobStepOutputType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/id_job.go b/resource-manager/sql/2023-08-01/jobsteps/id_job.go new file mode 100644 index 00000000000..6a38c8edcd3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_job.go @@ -0,0 +1,148 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobId{}) +} + +var _ resourceids.ResourceId = &JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + return nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/id_job_test.go b/resource-manager/sql/2023-08-01/jobsteps/id_job_test.go new file mode 100644 index 00000000000..c575d9648be --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_job_test.go @@ -0,0 +1,372 @@ +package jobsteps + +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 = &JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/sql/2023-08-01/jobsteps/id_step.go b/resource-manager/sql/2023-08-01/jobsteps/id_step.go new file mode 100644 index 00000000000..22d315998db --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_step.go @@ -0,0 +1,157 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StepId{}) +} + +var _ resourceids.ResourceId = &StepId{} + +// StepId is a struct representing the Resource ID for a Step +type StepId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + StepName string +} + +// NewStepID returns a new StepId struct +func NewStepID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, stepName string) StepId { + return StepId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + StepName: stepName, + } +} + +// ParseStepID parses 'input' into a StepId +func ParseStepID(input string) (*StepId, error) { + parser := resourceids.NewParserFromResourceIdType(&StepId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStepIDInsensitively parses 'input' case-insensitively into a StepId +// note: this method should only be used for API response data and not user input +func ParseStepIDInsensitively(input string) (*StepId, error) { + parser := resourceids.NewParserFromResourceIdType(&StepId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StepId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.StepName, ok = input.Parsed["stepName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "stepName", input) + } + + return nil +} + +// ValidateStepID checks that 'input' can be parsed as a Step ID +func ValidateStepID(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 := ParseStepID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Step ID +func (id StepId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/steps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.StepName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Step ID +func (id StepId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepName"), + } +} + +// String returns a human-readable description of this Step ID +func (id StepId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Step Name: %q", id.StepName), + } + return fmt.Sprintf("Step (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/id_step_test.go b/resource-manager/sql/2023-08-01/jobsteps/id_step_test.go new file mode 100644 index 00000000000..284d8ac4226 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_step_test.go @@ -0,0 +1,417 @@ +package jobsteps + +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 = &StepId{} + +func TestNewStepID(t *testing.T) { + id := NewStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "stepName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.StepName != "stepName" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepName") + } +} + +func TestFormatStepID(t *testing.T) { + actual := NewStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "stepName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps/stepName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStepID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps/stepName", + Expected: &StepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps/stepName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStepID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestParseStepIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps/stepName", + Expected: &StepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/steps/stepName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/sTePs/sTePnAmE", + Expected: &StepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + StepName: "sTePnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/sTePs/sTePnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStepIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestSegmentsForStepId(t *testing.T) { + segments := StepId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StepId 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/sql/2023-08-01/jobsteps/id_version.go b/resource-manager/sql/2023-08-01/jobsteps/id_version.go new file mode 100644 index 00000000000..a66cf6dfc0a --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_version.go @@ -0,0 +1,157 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VersionId{}) +} + +var _ resourceids.ResourceId = &VersionId{} + +// VersionId is a struct representing the Resource ID for a Version +type VersionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + VersionName string +} + +// NewVersionID returns a new VersionId struct +func NewVersionID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, versionName string) VersionId { + return VersionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + VersionName: versionName, + } +} + +// ParseVersionID parses 'input' into a VersionId +func ParseVersionID(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVersionIDInsensitively parses 'input' case-insensitively into a VersionId +// note: this method should only be used for API response data and not user input +func ParseVersionIDInsensitively(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateVersionID checks that 'input' can be parsed as a Version ID +func ValidateVersionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Version ID +func (id VersionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Version ID +func (id VersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + } +} + +// String returns a human-readable description of this Version ID +func (id VersionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/id_version_test.go b/resource-manager/sql/2023-08-01/jobsteps/id_version_test.go new file mode 100644 index 00000000000..8a0387d811e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_version_test.go @@ -0,0 +1,417 @@ +package jobsteps + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &VersionId{} + +func TestNewVersionID(t *testing.T) { + id := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestParseVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + VersionName: "vErSiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestSegmentsForVersionId(t *testing.T) { + segments := VersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VersionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/id_versionstep.go b/resource-manager/sql/2023-08-01/jobsteps/id_versionstep.go new file mode 100644 index 00000000000..9391697e1af --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_versionstep.go @@ -0,0 +1,166 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VersionStepId{}) +} + +var _ resourceids.ResourceId = &VersionStepId{} + +// VersionStepId is a struct representing the Resource ID for a Version Step +type VersionStepId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + VersionName string + StepName string +} + +// NewVersionStepID returns a new VersionStepId struct +func NewVersionStepID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, versionName string, stepName string) VersionStepId { + return VersionStepId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + VersionName: versionName, + StepName: stepName, + } +} + +// ParseVersionStepID parses 'input' into a VersionStepId +func ParseVersionStepID(input string) (*VersionStepId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionStepId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionStepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVersionStepIDInsensitively parses 'input' case-insensitively into a VersionStepId +// note: this method should only be used for API response data and not user input +func ParseVersionStepIDInsensitively(input string) (*VersionStepId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionStepId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionStepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VersionStepId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + if id.StepName, ok = input.Parsed["stepName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "stepName", input) + } + + return nil +} + +// ValidateVersionStepID checks that 'input' can be parsed as a Version Step ID +func ValidateVersionStepID(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 := ParseVersionStepID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Version Step ID +func (id VersionStepId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/versions/%s/steps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.VersionName, id.StepName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Version Step ID +func (id VersionStepId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepName"), + } +} + +// String returns a human-readable description of this Version Step ID +func (id VersionStepId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Version Name: %q", id.VersionName), + fmt.Sprintf("Step Name: %q", id.StepName), + } + return fmt.Sprintf("Version Step (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/id_versionstep_test.go b/resource-manager/sql/2023-08-01/jobsteps/id_versionstep_test.go new file mode 100644 index 00000000000..d6438bf2d1b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/id_versionstep_test.go @@ -0,0 +1,462 @@ +package jobsteps + +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 = &VersionStepId{} + +func TestNewVersionStepID(t *testing.T) { + id := NewVersionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName", "stepName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } + + if id.StepName != "stepName" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepName") + } +} + +func TestFormatVersionStepID(t *testing.T) { + actual := NewVersionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName", "stepName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps/stepName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVersionStepID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionStepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps/stepName", + Expected: &VersionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + VersionName: "versionName", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps/stepName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionStepID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestParseVersionStepIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionStepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps/stepName", + Expected: &VersionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + VersionName: "versionName", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/steps/stepName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe/sTePs/sTePnAmE", + Expected: &VersionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + VersionName: "vErSiOnNaMe", + StepName: "sTePnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe/sTePs/sTePnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionStepIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestSegmentsForVersionStepId(t *testing.T) { + segments := VersionStepId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VersionStepId 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/sql/2023-08-01/jobsteps/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobsteps/method_createorupdate.go new file mode 100644 index 00000000000..20835ec1bf8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/method_createorupdate.go @@ -0,0 +1,58 @@ +package jobsteps + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *JobStep +} + +// CreateOrUpdate ... +func (c JobStepsClient) CreateOrUpdate(ctx context.Context, id StepId, input JobStep) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model JobStep + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/method_delete.go b/resource-manager/sql/2023-08-01/jobsteps/method_delete.go new file mode 100644 index 00000000000..ce7d62b6cb7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/method_delete.go @@ -0,0 +1,47 @@ +package jobsteps + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c JobStepsClient) Delete(ctx context.Context, id StepId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/method_get.go b/resource-manager/sql/2023-08-01/jobsteps/method_get.go new file mode 100644 index 00000000000..9fe63607acd --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/method_get.go @@ -0,0 +1,53 @@ +package jobsteps + +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 *JobStep +} + +// Get ... +func (c JobStepsClient) Get(ctx context.Context, id StepId) (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 JobStep + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/method_getbyversion.go b/resource-manager/sql/2023-08-01/jobsteps/method_getbyversion.go new file mode 100644 index 00000000000..61fe0bd36ef --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/method_getbyversion.go @@ -0,0 +1,53 @@ +package jobsteps + +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 GetByVersionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *JobStep +} + +// GetByVersion ... +func (c JobStepsClient) GetByVersion(ctx context.Context, id VersionStepId) (result GetByVersionOperationResponse, 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 JobStep + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/method_listbyjob.go b/resource-manager/sql/2023-08-01/jobsteps/method_listbyjob.go new file mode 100644 index 00000000000..74a6d7dde41 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/method_listbyjob.go @@ -0,0 +1,105 @@ +package jobsteps + +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 ListByJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobStep +} + +type ListByJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobStep +} + +type ListByJobCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByJobCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByJob ... +func (c JobStepsClient) ListByJob(ctx context.Context, id JobId) (result ListByJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByJobCustomPager{}, + Path: fmt.Sprintf("%s/steps", 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 *[]JobStep `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByJobComplete retrieves all the results into a single object +func (c JobStepsClient) ListByJobComplete(ctx context.Context, id JobId) (ListByJobCompleteResult, error) { + return c.ListByJobCompleteMatchingPredicate(ctx, id, JobStepOperationPredicate{}) +} + +// ListByJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobStepsClient) ListByJobCompleteMatchingPredicate(ctx context.Context, id JobId, predicate JobStepOperationPredicate) (result ListByJobCompleteResult, err error) { + items := make([]JobStep, 0) + + resp, err := c.ListByJob(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/method_listbyversion.go b/resource-manager/sql/2023-08-01/jobsteps/method_listbyversion.go new file mode 100644 index 00000000000..f13eb451fce --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/method_listbyversion.go @@ -0,0 +1,105 @@ +package jobsteps + +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 ListByVersionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobStep +} + +type ListByVersionCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobStep +} + +type ListByVersionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByVersionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByVersion ... +func (c JobStepsClient) ListByVersion(ctx context.Context, id VersionId) (result ListByVersionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByVersionCustomPager{}, + Path: fmt.Sprintf("%s/steps", 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 *[]JobStep `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByVersionComplete retrieves all the results into a single object +func (c JobStepsClient) ListByVersionComplete(ctx context.Context, id VersionId) (ListByVersionCompleteResult, error) { + return c.ListByVersionCompleteMatchingPredicate(ctx, id, JobStepOperationPredicate{}) +} + +// ListByVersionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobStepsClient) ListByVersionCompleteMatchingPredicate(ctx context.Context, id VersionId, predicate JobStepOperationPredicate) (result ListByVersionCompleteResult, err error) { + items := make([]JobStep, 0) + + resp, err := c.ListByVersion(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByVersionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/model_jobstep.go b/resource-manager/sql/2023-08-01/jobsteps/model_jobstep.go new file mode 100644 index 00000000000..309812daeb1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/model_jobstep.go @@ -0,0 +1,11 @@ +package jobsteps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobStep struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobStepProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/model_jobstepaction.go b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepaction.go new file mode 100644 index 00000000000..a86d27e81af --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepaction.go @@ -0,0 +1,10 @@ +package jobsteps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobStepAction struct { + Source *JobStepActionSource `json:"source,omitempty"` + Type *JobStepActionType `json:"type,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/model_jobstepexecutionoptions.go b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepexecutionoptions.go new file mode 100644 index 00000000000..c0fc907b36a --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepexecutionoptions.go @@ -0,0 +1,12 @@ +package jobsteps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobStepExecutionOptions struct { + InitialRetryIntervalSeconds *int64 `json:"initialRetryIntervalSeconds,omitempty"` + MaximumRetryIntervalSeconds *int64 `json:"maximumRetryIntervalSeconds,omitempty"` + RetryAttempts *int64 `json:"retryAttempts,omitempty"` + RetryIntervalBackoffMultiplier *float64 `json:"retryIntervalBackoffMultiplier,omitempty"` + TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/model_jobstepoutput.go b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepoutput.go new file mode 100644 index 00000000000..886a4f9cf34 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepoutput.go @@ -0,0 +1,15 @@ +package jobsteps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobStepOutput struct { + Credential *string `json:"credential,omitempty"` + DatabaseName string `json:"databaseName"` + ResourceGroupName *string `json:"resourceGroupName,omitempty"` + SchemaName *string `json:"schemaName,omitempty"` + ServerName string `json:"serverName"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + TableName string `json:"tableName"` + Type *JobStepOutputType `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/model_jobstepproperties.go b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepproperties.go new file mode 100644 index 00000000000..38a46218234 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/model_jobstepproperties.go @@ -0,0 +1,13 @@ +package jobsteps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobStepProperties struct { + Action JobStepAction `json:"action"` + Credential *string `json:"credential,omitempty"` + ExecutionOptions *JobStepExecutionOptions `json:"executionOptions,omitempty"` + Output *JobStepOutput `json:"output,omitempty"` + StepId *int64 `json:"stepId,omitempty"` + TargetGroup string `json:"targetGroup"` +} diff --git a/resource-manager/sql/2023-08-01/jobsteps/predicates.go b/resource-manager/sql/2023-08-01/jobsteps/predicates.go new file mode 100644 index 00000000000..2011b5d8053 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/predicates.go @@ -0,0 +1,27 @@ +package jobsteps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobStepOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobStepOperationPredicate) Matches(input JobStep) 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/sql/2023-08-01/jobsteps/version.go b/resource-manager/sql/2023-08-01/jobsteps/version.go new file mode 100644 index 00000000000..5651369d71d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobsteps/version.go @@ -0,0 +1,10 @@ +package jobsteps + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobsteps/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/README.md b/resource-manager/sql/2023-08-01/jobtargetexecutions/README.md new file mode 100644 index 00000000000..991f964addd --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobtargetexecutions` Documentation + +The `jobtargetexecutions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobtargetexecutions" +``` + + +### Client Initialization + +```go +client := jobtargetexecutions.NewJobTargetExecutionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobTargetExecutionsClient.Get` + +```go +ctx := context.TODO() +id := jobtargetexecutions.NewTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName", "targetId") + +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: `JobTargetExecutionsClient.ListByJobExecution` + +```go +ctx := context.TODO() +id := jobtargetexecutions.NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + +// alternatively `client.ListByJobExecution(ctx, id, jobtargetexecutions.DefaultListByJobExecutionOperationOptions())` can be used to do batched pagination +items, err := client.ListByJobExecutionComplete(ctx, id, jobtargetexecutions.DefaultListByJobExecutionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `JobTargetExecutionsClient.ListByStep` + +```go +ctx := context.TODO() +id := jobtargetexecutions.NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName") + +// alternatively `client.ListByStep(ctx, id, jobtargetexecutions.DefaultListByStepOperationOptions())` can be used to do batched pagination +items, err := client.ListByStepComplete(ctx, id, jobtargetexecutions.DefaultListByStepOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/client.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/client.go new file mode 100644 index 00000000000..5e5c95f15ea --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/client.go @@ -0,0 +1,26 @@ +package jobtargetexecutions + +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 JobTargetExecutionsClient struct { + Client *resourcemanager.Client +} + +func NewJobTargetExecutionsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobTargetExecutionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobtargetexecutions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobTargetExecutionsClient: %+v", err) + } + + return &JobTargetExecutionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/constants.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/constants.go new file mode 100644 index 00000000000..f61696c2f36 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/constants.go @@ -0,0 +1,175 @@ +package jobtargetexecutions + +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 JobExecutionLifecycle string + +const ( + JobExecutionLifecycleCanceled JobExecutionLifecycle = "Canceled" + JobExecutionLifecycleCreated JobExecutionLifecycle = "Created" + JobExecutionLifecycleFailed JobExecutionLifecycle = "Failed" + JobExecutionLifecycleInProgress JobExecutionLifecycle = "InProgress" + JobExecutionLifecycleSkipped JobExecutionLifecycle = "Skipped" + JobExecutionLifecycleSucceeded JobExecutionLifecycle = "Succeeded" + JobExecutionLifecycleSucceededWithSkipped JobExecutionLifecycle = "SucceededWithSkipped" + JobExecutionLifecycleTimedOut JobExecutionLifecycle = "TimedOut" + JobExecutionLifecycleWaitingForChildJobExecutions JobExecutionLifecycle = "WaitingForChildJobExecutions" + JobExecutionLifecycleWaitingForRetry JobExecutionLifecycle = "WaitingForRetry" +) + +func PossibleValuesForJobExecutionLifecycle() []string { + return []string{ + string(JobExecutionLifecycleCanceled), + string(JobExecutionLifecycleCreated), + string(JobExecutionLifecycleFailed), + string(JobExecutionLifecycleInProgress), + string(JobExecutionLifecycleSkipped), + string(JobExecutionLifecycleSucceeded), + string(JobExecutionLifecycleSucceededWithSkipped), + string(JobExecutionLifecycleTimedOut), + string(JobExecutionLifecycleWaitingForChildJobExecutions), + string(JobExecutionLifecycleWaitingForRetry), + } +} + +func (s *JobExecutionLifecycle) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobExecutionLifecycle(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobExecutionLifecycle(input string) (*JobExecutionLifecycle, error) { + vals := map[string]JobExecutionLifecycle{ + "canceled": JobExecutionLifecycleCanceled, + "created": JobExecutionLifecycleCreated, + "failed": JobExecutionLifecycleFailed, + "inprogress": JobExecutionLifecycleInProgress, + "skipped": JobExecutionLifecycleSkipped, + "succeeded": JobExecutionLifecycleSucceeded, + "succeededwithskipped": JobExecutionLifecycleSucceededWithSkipped, + "timedout": JobExecutionLifecycleTimedOut, + "waitingforchildjobexecutions": JobExecutionLifecycleWaitingForChildJobExecutions, + "waitingforretry": JobExecutionLifecycleWaitingForRetry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobExecutionLifecycle(input) + return &out, nil +} + +type JobTargetType string + +const ( + JobTargetTypeSqlDatabase JobTargetType = "SqlDatabase" + JobTargetTypeSqlElasticPool JobTargetType = "SqlElasticPool" + JobTargetTypeSqlServer JobTargetType = "SqlServer" + JobTargetTypeSqlShardMap JobTargetType = "SqlShardMap" + JobTargetTypeTargetGroup JobTargetType = "TargetGroup" +) + +func PossibleValuesForJobTargetType() []string { + return []string{ + string(JobTargetTypeSqlDatabase), + string(JobTargetTypeSqlElasticPool), + string(JobTargetTypeSqlServer), + string(JobTargetTypeSqlShardMap), + string(JobTargetTypeTargetGroup), + } +} + +func (s *JobTargetType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobTargetType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobTargetType(input string) (*JobTargetType, error) { + vals := map[string]JobTargetType{ + "sqldatabase": JobTargetTypeSqlDatabase, + "sqlelasticpool": JobTargetTypeSqlElasticPool, + "sqlserver": JobTargetTypeSqlServer, + "sqlshardmap": JobTargetTypeSqlShardMap, + "targetgroup": JobTargetTypeTargetGroup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobTargetType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + 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{ + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution.go new file mode 100644 index 00000000000..16a6951d076 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution.go @@ -0,0 +1,157 @@ +package jobtargetexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExecutionId{}) +} + +var _ resourceids.ResourceId = &ExecutionId{} + +// ExecutionId is a struct representing the Resource ID for a Execution +type ExecutionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + JobExecutionId string +} + +// NewExecutionID returns a new ExecutionId struct +func NewExecutionID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobExecutionId string) ExecutionId { + return ExecutionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + JobExecutionId: jobExecutionId, + } +} + +// ParseExecutionID parses 'input' into a ExecutionId +func ParseExecutionID(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExecutionIDInsensitively parses 'input' case-insensitively into a ExecutionId +// note: this method should only be used for API response data and not user input +func ParseExecutionIDInsensitively(input string) (*ExecutionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExecutionId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.JobExecutionId, ok = input.Parsed["jobExecutionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobExecutionId", input) + } + + return nil +} + +// ValidateExecutionID checks that 'input' can be parsed as a Execution ID +func ValidateExecutionID(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 := ParseExecutionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Execution ID +func (id ExecutionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/executions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.JobExecutionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Execution ID +func (id ExecutionId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionId"), + } +} + +// String returns a human-readable description of this Execution ID +func (id ExecutionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Job Execution: %q", id.JobExecutionId), + } + return fmt.Sprintf("Execution (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution_test.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution_test.go new file mode 100644 index 00000000000..d9ba4776d9f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_execution_test.go @@ -0,0 +1,417 @@ +package jobtargetexecutions + +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 = &ExecutionId{} + +func TestNewExecutionID(t *testing.T) { + id := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.JobExecutionId != "jobExecutionId" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionId") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExecutionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + } +} + +func TestParseExecutionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + JobExecutionId: "jObExEcUtIoNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + } +} + +func TestSegmentsForExecutionId(t *testing.T) { + segments := ExecutionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExecutionId 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/sql/2023-08-01/jobtargetexecutions/id_executionstep.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep.go new file mode 100644 index 00000000000..33b391c1025 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep.go @@ -0,0 +1,166 @@ +package jobtargetexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExecutionStepId{}) +} + +var _ resourceids.ResourceId = &ExecutionStepId{} + +// ExecutionStepId is a struct representing the Resource ID for a Execution Step +type ExecutionStepId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + JobExecutionId string + StepName string +} + +// NewExecutionStepID returns a new ExecutionStepId struct +func NewExecutionStepID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobExecutionId string, stepName string) ExecutionStepId { + return ExecutionStepId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + JobExecutionId: jobExecutionId, + StepName: stepName, + } +} + +// ParseExecutionStepID parses 'input' into a ExecutionStepId +func ParseExecutionStepID(input string) (*ExecutionStepId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionStepId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionStepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExecutionStepIDInsensitively parses 'input' case-insensitively into a ExecutionStepId +// note: this method should only be used for API response data and not user input +func ParseExecutionStepIDInsensitively(input string) (*ExecutionStepId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExecutionStepId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExecutionStepId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExecutionStepId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.JobExecutionId, ok = input.Parsed["jobExecutionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobExecutionId", input) + } + + if id.StepName, ok = input.Parsed["stepName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "stepName", input) + } + + return nil +} + +// ValidateExecutionStepID checks that 'input' can be parsed as a Execution Step ID +func ValidateExecutionStepID(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 := ParseExecutionStepID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Execution Step ID +func (id ExecutionStepId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/executions/%s/steps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.JobExecutionId, id.StepName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Execution Step ID +func (id ExecutionStepId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionId"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepName"), + } +} + +// String returns a human-readable description of this Execution Step ID +func (id ExecutionStepId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Job Execution: %q", id.JobExecutionId), + fmt.Sprintf("Step Name: %q", id.StepName), + } + return fmt.Sprintf("Execution Step (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep_test.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep_test.go new file mode 100644 index 00000000000..0806efa5121 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_executionstep_test.go @@ -0,0 +1,462 @@ +package jobtargetexecutions + +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 = &ExecutionStepId{} + +func TestNewExecutionStepID(t *testing.T) { + id := NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.JobExecutionId != "jobExecutionId" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionId") + } + + if id.StepName != "stepName" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepName") + } +} + +func TestFormatExecutionStepID(t *testing.T) { + actual := NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExecutionStepID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionStepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionStepID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestParseExecutionStepIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExecutionStepId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + StepName: "stepName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + JobExecutionId: "jObExEcUtIoNiD", + StepName: "sTePnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExecutionStepIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + } +} + +func TestSegmentsForExecutionStepId(t *testing.T) { + segments := ExecutionStepId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExecutionStepId 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/sql/2023-08-01/jobtargetexecutions/id_target.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_target.go new file mode 100644 index 00000000000..9e1239fba3f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_target.go @@ -0,0 +1,175 @@ +package jobtargetexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TargetId{}) +} + +var _ resourceids.ResourceId = &TargetId{} + +// TargetId is a struct representing the Resource ID for a Target +type TargetId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + JobExecutionId string + StepName string + TargetId string +} + +// NewTargetID returns a new TargetId struct +func NewTargetID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, jobExecutionId string, stepName string, targetId string) TargetId { + return TargetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + JobExecutionId: jobExecutionId, + StepName: stepName, + TargetId: targetId, + } +} + +// ParseTargetID parses 'input' into a TargetId +func ParseTargetID(input string) (*TargetId, error) { + parser := resourceids.NewParserFromResourceIdType(&TargetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TargetId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTargetIDInsensitively parses 'input' case-insensitively into a TargetId +// note: this method should only be used for API response data and not user input +func ParseTargetIDInsensitively(input string) (*TargetId, error) { + parser := resourceids.NewParserFromResourceIdType(&TargetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TargetId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TargetId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.JobExecutionId, ok = input.Parsed["jobExecutionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobExecutionId", input) + } + + if id.StepName, ok = input.Parsed["stepName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "stepName", input) + } + + if id.TargetId, ok = input.Parsed["targetId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "targetId", input) + } + + return nil +} + +// ValidateTargetID checks that 'input' can be parsed as a Target ID +func ValidateTargetID(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 := ParseTargetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Target ID +func (id TargetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/executions/%s/steps/%s/targets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.JobExecutionId, id.StepName, id.TargetId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Target ID +func (id TargetId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionId"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepName"), + resourceids.StaticSegment("staticTargets", "targets", "targets"), + resourceids.UserSpecifiedSegment("targetId", "targetId"), + } +} + +// String returns a human-readable description of this Target ID +func (id TargetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Job Execution: %q", id.JobExecutionId), + fmt.Sprintf("Step Name: %q", id.StepName), + fmt.Sprintf("Target: %q", id.TargetId), + } + return fmt.Sprintf("Target (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/id_target_test.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_target_test.go new file mode 100644 index 00000000000..6caad898067 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/id_target_test.go @@ -0,0 +1,507 @@ +package jobtargetexecutions + +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 = &TargetId{} + +func TestNewTargetID(t *testing.T) { + id := NewTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName", "targetId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.JobExecutionId != "jobExecutionId" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionId") + } + + if id.StepName != "stepName" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepName") + } + + if id.TargetId != "targetId" { + t.Fatalf("Expected %q but got %q for Segment 'TargetId'", id.TargetId, "targetId") + } +} + +func TestFormatTargetID(t *testing.T) { + actual := NewTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "jobExecutionId", "stepName", "targetId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets/targetId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTargetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TargetId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets/targetId", + Expected: &TargetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + StepName: "stepName", + TargetId: "targetId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets/targetId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTargetID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + if actual.TargetId != v.Expected.TargetId { + t.Fatalf("Expected %q but got %q for TargetId", v.Expected.TargetId, actual.TargetId) + } + + } +} + +func TestParseTargetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TargetId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE/tArGeTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets/targetId", + Expected: &TargetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + JobExecutionId: "jobExecutionId", + StepName: "stepName", + TargetId: "targetId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/executions/jobExecutionId/steps/stepName/targets/targetId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE/tArGeTs/tArGeTiD", + Expected: &TargetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + JobExecutionId: "jObExEcUtIoNiD", + StepName: "sTePnAmE", + TargetId: "tArGeTiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/eXeCuTiOnS/jObExEcUtIoNiD/sTePs/sTePnAmE/tArGeTs/tArGeTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTargetIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.JobExecutionId != v.Expected.JobExecutionId { + t.Fatalf("Expected %q but got %q for JobExecutionId", v.Expected.JobExecutionId, actual.JobExecutionId) + } + + if actual.StepName != v.Expected.StepName { + t.Fatalf("Expected %q but got %q for StepName", v.Expected.StepName, actual.StepName) + } + + if actual.TargetId != v.Expected.TargetId { + t.Fatalf("Expected %q but got %q for TargetId", v.Expected.TargetId, actual.TargetId) + } + + } +} + +func TestSegmentsForTargetId(t *testing.T) { + segments := TargetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TargetId 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/sql/2023-08-01/jobtargetexecutions/method_get.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/method_get.go new file mode 100644 index 00000000000..5f1676b9a64 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/method_get.go @@ -0,0 +1,53 @@ +package jobtargetexecutions + +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 *JobExecution +} + +// Get ... +func (c JobTargetExecutionsClient) Get(ctx context.Context, id TargetId) (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 JobExecution + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbyjobexecution.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbyjobexecution.go new file mode 100644 index 00000000000..a98a024e117 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbyjobexecution.go @@ -0,0 +1,158 @@ +package jobtargetexecutions + +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 ListByJobExecutionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type ListByJobExecutionCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type ListByJobExecutionOperationOptions struct { + CreateTimeMax *string + CreateTimeMin *string + EndTimeMax *string + EndTimeMin *string + IsActive *bool + Skip *int64 + Top *int64 +} + +func DefaultListByJobExecutionOperationOptions() ListByJobExecutionOperationOptions { + return ListByJobExecutionOperationOptions{} +} + +func (o ListByJobExecutionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByJobExecutionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByJobExecutionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CreateTimeMax != nil { + out.Append("createTimeMax", fmt.Sprintf("%v", *o.CreateTimeMax)) + } + if o.CreateTimeMin != nil { + out.Append("createTimeMin", fmt.Sprintf("%v", *o.CreateTimeMin)) + } + if o.EndTimeMax != nil { + out.Append("endTimeMax", fmt.Sprintf("%v", *o.EndTimeMax)) + } + if o.EndTimeMin != nil { + out.Append("endTimeMin", fmt.Sprintf("%v", *o.EndTimeMin)) + } + if o.IsActive != nil { + out.Append("isActive", fmt.Sprintf("%v", *o.IsActive)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByJobExecutionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByJobExecutionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByJobExecution ... +func (c JobTargetExecutionsClient) ListByJobExecution(ctx context.Context, id ExecutionId, options ListByJobExecutionOperationOptions) (result ListByJobExecutionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByJobExecutionCustomPager{}, + Path: fmt.Sprintf("%s/targets", 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 *[]JobExecution `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByJobExecutionComplete retrieves all the results into a single object +func (c JobTargetExecutionsClient) ListByJobExecutionComplete(ctx context.Context, id ExecutionId, options ListByJobExecutionOperationOptions) (ListByJobExecutionCompleteResult, error) { + return c.ListByJobExecutionCompleteMatchingPredicate(ctx, id, options, JobExecutionOperationPredicate{}) +} + +// ListByJobExecutionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobTargetExecutionsClient) ListByJobExecutionCompleteMatchingPredicate(ctx context.Context, id ExecutionId, options ListByJobExecutionOperationOptions, predicate JobExecutionOperationPredicate) (result ListByJobExecutionCompleteResult, err error) { + items := make([]JobExecution, 0) + + resp, err := c.ListByJobExecution(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByJobExecutionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbystep.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbystep.go new file mode 100644 index 00000000000..9f647e1f496 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/method_listbystep.go @@ -0,0 +1,158 @@ +package jobtargetexecutions + +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 ListByStepOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobExecution +} + +type ListByStepCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobExecution +} + +type ListByStepOperationOptions struct { + CreateTimeMax *string + CreateTimeMin *string + EndTimeMax *string + EndTimeMin *string + IsActive *bool + Skip *int64 + Top *int64 +} + +func DefaultListByStepOperationOptions() ListByStepOperationOptions { + return ListByStepOperationOptions{} +} + +func (o ListByStepOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStepOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByStepOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.CreateTimeMax != nil { + out.Append("createTimeMax", fmt.Sprintf("%v", *o.CreateTimeMax)) + } + if o.CreateTimeMin != nil { + out.Append("createTimeMin", fmt.Sprintf("%v", *o.CreateTimeMin)) + } + if o.EndTimeMax != nil { + out.Append("endTimeMax", fmt.Sprintf("%v", *o.EndTimeMax)) + } + if o.EndTimeMin != nil { + out.Append("endTimeMin", fmt.Sprintf("%v", *o.EndTimeMin)) + } + if o.IsActive != nil { + out.Append("isActive", fmt.Sprintf("%v", *o.IsActive)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByStepCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByStepCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByStep ... +func (c JobTargetExecutionsClient) ListByStep(ctx context.Context, id ExecutionStepId, options ListByStepOperationOptions) (result ListByStepOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByStepCustomPager{}, + Path: fmt.Sprintf("%s/targets", 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 *[]JobExecution `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStepComplete retrieves all the results into a single object +func (c JobTargetExecutionsClient) ListByStepComplete(ctx context.Context, id ExecutionStepId, options ListByStepOperationOptions) (ListByStepCompleteResult, error) { + return c.ListByStepCompleteMatchingPredicate(ctx, id, options, JobExecutionOperationPredicate{}) +} + +// ListByStepCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobTargetExecutionsClient) ListByStepCompleteMatchingPredicate(ctx context.Context, id ExecutionStepId, options ListByStepOperationOptions, predicate JobExecutionOperationPredicate) (result ListByStepCompleteResult, err error) { + items := make([]JobExecution, 0) + + resp, err := c.ListByStep(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByStepCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecution.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecution.go new file mode 100644 index 00000000000..33ddea7a85e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecution.go @@ -0,0 +1,11 @@ +package jobtargetexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecution struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobExecutionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutionproperties.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutionproperties.go new file mode 100644 index 00000000000..1f01113051e --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutionproperties.go @@ -0,0 +1,74 @@ +package jobtargetexecutions + +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 JobExecutionProperties struct { + CreateTime *string `json:"createTime,omitempty"` + CurrentAttemptStartTime *string `json:"currentAttemptStartTime,omitempty"` + CurrentAttempts *int64 `json:"currentAttempts,omitempty"` + EndTime *string `json:"endTime,omitempty"` + JobExecutionId *string `json:"jobExecutionId,omitempty"` + JobVersion *int64 `json:"jobVersion,omitempty"` + LastMessage *string `json:"lastMessage,omitempty"` + Lifecycle *JobExecutionLifecycle `json:"lifecycle,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + StartTime *string `json:"startTime,omitempty"` + StepId *int64 `json:"stepId,omitempty"` + StepName *string `json:"stepName,omitempty"` + Target *JobExecutionTarget `json:"target,omitempty"` +} + +func (o *JobExecutionProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} + +func (o *JobExecutionProperties) GetCurrentAttemptStartTimeAsTime() (*time.Time, error) { + if o.CurrentAttemptStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CurrentAttemptStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetCurrentAttemptStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CurrentAttemptStartTime = &formatted +} + +func (o *JobExecutionProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *JobExecutionProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *JobExecutionProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutiontarget.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutiontarget.go new file mode 100644 index 00000000000..ef4e983cdc0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/model_jobexecutiontarget.go @@ -0,0 +1,10 @@ +package jobtargetexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionTarget struct { + DatabaseName *string `json:"databaseName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Type *JobTargetType `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobtargetexecutions/predicates.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/predicates.go new file mode 100644 index 00000000000..b2a71b3428f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/predicates.go @@ -0,0 +1,27 @@ +package jobtargetexecutions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobExecutionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobExecutionOperationPredicate) Matches(input JobExecution) 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/sql/2023-08-01/jobtargetexecutions/version.go b/resource-manager/sql/2023-08-01/jobtargetexecutions/version.go new file mode 100644 index 00000000000..9845959a774 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetexecutions/version.go @@ -0,0 +1,10 @@ +package jobtargetexecutions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobtargetexecutions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/README.md b/resource-manager/sql/2023-08-01/jobtargetgroups/README.md new file mode 100644 index 00000000000..9451114eb97 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobtargetgroups` Documentation + +The `jobtargetgroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobtargetgroups" +``` + + +### Client Initialization + +```go +client := jobtargetgroups.NewJobTargetGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobTargetGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := jobtargetgroups.NewTargetGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "targetGroupName") + +payload := jobtargetgroups.JobTargetGroup{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobTargetGroupsClient.Delete` + +```go +ctx := context.TODO() +id := jobtargetgroups.NewTargetGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "targetGroupName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `JobTargetGroupsClient.Get` + +```go +ctx := context.TODO() +id := jobtargetgroups.NewTargetGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "targetGroupName") + +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: `JobTargetGroupsClient.ListByAgent` + +```go +ctx := context.TODO() +id := jobtargetgroups.NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + +// alternatively `client.ListByAgent(ctx, id)` can be used to do batched pagination +items, err := client.ListByAgentComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/client.go b/resource-manager/sql/2023-08-01/jobtargetgroups/client.go new file mode 100644 index 00000000000..0b3a0245e33 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/client.go @@ -0,0 +1,26 @@ +package jobtargetgroups + +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 JobTargetGroupsClient struct { + Client *resourcemanager.Client +} + +func NewJobTargetGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobTargetGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobtargetgroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobTargetGroupsClient: %+v", err) + } + + return &JobTargetGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/constants.go b/resource-manager/sql/2023-08-01/jobtargetgroups/constants.go new file mode 100644 index 00000000000..61a33d6ee92 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/constants.go @@ -0,0 +1,101 @@ +package jobtargetgroups + +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 JobTargetGroupMembershipType string + +const ( + JobTargetGroupMembershipTypeExclude JobTargetGroupMembershipType = "Exclude" + JobTargetGroupMembershipTypeInclude JobTargetGroupMembershipType = "Include" +) + +func PossibleValuesForJobTargetGroupMembershipType() []string { + return []string{ + string(JobTargetGroupMembershipTypeExclude), + string(JobTargetGroupMembershipTypeInclude), + } +} + +func (s *JobTargetGroupMembershipType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobTargetGroupMembershipType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobTargetGroupMembershipType(input string) (*JobTargetGroupMembershipType, error) { + vals := map[string]JobTargetGroupMembershipType{ + "exclude": JobTargetGroupMembershipTypeExclude, + "include": JobTargetGroupMembershipTypeInclude, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobTargetGroupMembershipType(input) + return &out, nil +} + +type JobTargetType string + +const ( + JobTargetTypeSqlDatabase JobTargetType = "SqlDatabase" + JobTargetTypeSqlElasticPool JobTargetType = "SqlElasticPool" + JobTargetTypeSqlServer JobTargetType = "SqlServer" + JobTargetTypeSqlShardMap JobTargetType = "SqlShardMap" + JobTargetTypeTargetGroup JobTargetType = "TargetGroup" +) + +func PossibleValuesForJobTargetType() []string { + return []string{ + string(JobTargetTypeSqlDatabase), + string(JobTargetTypeSqlElasticPool), + string(JobTargetTypeSqlServer), + string(JobTargetTypeSqlShardMap), + string(JobTargetTypeTargetGroup), + } +} + +func (s *JobTargetType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobTargetType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseJobTargetType(input string) (*JobTargetType, error) { + vals := map[string]JobTargetType{ + "sqldatabase": JobTargetTypeSqlDatabase, + "sqlelasticpool": JobTargetTypeSqlElasticPool, + "sqlserver": JobTargetTypeSqlServer, + "sqlshardmap": JobTargetTypeSqlShardMap, + "targetgroup": JobTargetTypeTargetGroup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := JobTargetType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent.go b/resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent.go new file mode 100644 index 00000000000..cb117aa256f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent.go @@ -0,0 +1,139 @@ +package jobtargetgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobAgentId{}) +} + +var _ resourceids.ResourceId = &JobAgentId{} + +// JobAgentId is a struct representing the Resource ID for a Job Agent +type JobAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string +} + +// NewJobAgentID returns a new JobAgentId struct +func NewJobAgentID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string) JobAgentId { + return JobAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + } +} + +// ParseJobAgentID parses 'input' into a JobAgentId +func ParseJobAgentID(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobAgentIDInsensitively parses 'input' case-insensitively into a JobAgentId +// note: this method should only be used for API response data and not user input +func ParseJobAgentIDInsensitively(input string) (*JobAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + return nil +} + +// ValidateJobAgentID checks that 'input' can be parsed as a Job Agent ID +func ValidateJobAgentID(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 := ParseJobAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job Agent ID +func (id JobAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job Agent ID +func (id JobAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + } +} + +// String returns a human-readable description of this Job Agent ID +func (id JobAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + } + return fmt.Sprintf("Job Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent_test.go b/resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent_test.go new file mode 100644 index 00000000000..2cb3fcb759b --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/id_jobagent_test.go @@ -0,0 +1,327 @@ +package jobtargetgroups + +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 = &JobAgentId{} + +func TestNewJobAgentID(t *testing.T) { + id := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestParseJobAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + } +} + +func TestSegmentsForJobAgentId(t *testing.T) { + segments := JobAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobAgentId 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/sql/2023-08-01/jobtargetgroups/id_targetgroup.go b/resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup.go new file mode 100644 index 00000000000..7f230329039 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup.go @@ -0,0 +1,148 @@ +package jobtargetgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TargetGroupId{}) +} + +var _ resourceids.ResourceId = &TargetGroupId{} + +// TargetGroupId is a struct representing the Resource ID for a Target Group +type TargetGroupId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + TargetGroupName string +} + +// NewTargetGroupID returns a new TargetGroupId struct +func NewTargetGroupID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, targetGroupName string) TargetGroupId { + return TargetGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + TargetGroupName: targetGroupName, + } +} + +// ParseTargetGroupID parses 'input' into a TargetGroupId +func ParseTargetGroupID(input string) (*TargetGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&TargetGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TargetGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTargetGroupIDInsensitively parses 'input' case-insensitively into a TargetGroupId +// note: this method should only be used for API response data and not user input +func ParseTargetGroupIDInsensitively(input string) (*TargetGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&TargetGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TargetGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TargetGroupId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.TargetGroupName, ok = input.Parsed["targetGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "targetGroupName", input) + } + + return nil +} + +// ValidateTargetGroupID checks that 'input' can be parsed as a Target Group ID +func ValidateTargetGroupID(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 := ParseTargetGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Target Group ID +func (id TargetGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/targetGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.TargetGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Target Group ID +func (id TargetGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticTargetGroups", "targetGroups", "targetGroups"), + resourceids.UserSpecifiedSegment("targetGroupName", "targetGroupName"), + } +} + +// String returns a human-readable description of this Target Group ID +func (id TargetGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Target Group Name: %q", id.TargetGroupName), + } + return fmt.Sprintf("Target Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup_test.go b/resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup_test.go new file mode 100644 index 00000000000..0e8dd0036fc --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/id_targetgroup_test.go @@ -0,0 +1,372 @@ +package jobtargetgroups + +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 = &TargetGroupId{} + +func TestNewTargetGroupID(t *testing.T) { + id := NewTargetGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "targetGroupName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.TargetGroupName != "targetGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'TargetGroupName'", id.TargetGroupName, "targetGroupName") + } +} + +func TestFormatTargetGroupID(t *testing.T) { + actual := NewTargetGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "targetGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups/targetGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTargetGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TargetGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups/targetGroupName", + Expected: &TargetGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + TargetGroupName: "targetGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups/targetGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTargetGroupID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.TargetGroupName != v.Expected.TargetGroupName { + t.Fatalf("Expected %q but got %q for TargetGroupName", v.Expected.TargetGroupName, actual.TargetGroupName) + } + + } +} + +func TestParseTargetGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TargetGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/tArGeTgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups/targetGroupName", + Expected: &TargetGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + TargetGroupName: "targetGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/targetGroups/targetGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/tArGeTgRoUpS/tArGeTgRoUpNaMe", + Expected: &TargetGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + TargetGroupName: "tArGeTgRoUpNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/tArGeTgRoUpS/tArGeTgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTargetGroupIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.TargetGroupName != v.Expected.TargetGroupName { + t.Fatalf("Expected %q but got %q for TargetGroupName", v.Expected.TargetGroupName, actual.TargetGroupName) + } + + } +} + +func TestSegmentsForTargetGroupId(t *testing.T) { + segments := TargetGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TargetGroupId 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/sql/2023-08-01/jobtargetgroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/jobtargetgroups/method_createorupdate.go new file mode 100644 index 00000000000..a4c7de8d4fb --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/method_createorupdate.go @@ -0,0 +1,58 @@ +package jobtargetgroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *JobTargetGroup +} + +// CreateOrUpdate ... +func (c JobTargetGroupsClient) CreateOrUpdate(ctx context.Context, id TargetGroupId, input JobTargetGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model JobTargetGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/method_delete.go b/resource-manager/sql/2023-08-01/jobtargetgroups/method_delete.go new file mode 100644 index 00000000000..05f0cf9a24d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/method_delete.go @@ -0,0 +1,47 @@ +package jobtargetgroups + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c JobTargetGroupsClient) Delete(ctx context.Context, id TargetGroupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/method_get.go b/resource-manager/sql/2023-08-01/jobtargetgroups/method_get.go new file mode 100644 index 00000000000..bf1e5978670 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/method_get.go @@ -0,0 +1,53 @@ +package jobtargetgroups + +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 *JobTargetGroup +} + +// Get ... +func (c JobTargetGroupsClient) Get(ctx context.Context, id TargetGroupId) (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 JobTargetGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/method_listbyagent.go b/resource-manager/sql/2023-08-01/jobtargetgroups/method_listbyagent.go new file mode 100644 index 00000000000..7b8417fda2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/method_listbyagent.go @@ -0,0 +1,105 @@ +package jobtargetgroups + +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 ListByAgentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]JobTargetGroup +} + +type ListByAgentCompleteResult struct { + LatestHttpResponse *http.Response + Items []JobTargetGroup +} + +type ListByAgentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByAgentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByAgent ... +func (c JobTargetGroupsClient) ListByAgent(ctx context.Context, id JobAgentId) (result ListByAgentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByAgentCustomPager{}, + Path: fmt.Sprintf("%s/targetGroups", 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 *[]JobTargetGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAgentComplete retrieves all the results into a single object +func (c JobTargetGroupsClient) ListByAgentComplete(ctx context.Context, id JobAgentId) (ListByAgentCompleteResult, error) { + return c.ListByAgentCompleteMatchingPredicate(ctx, id, JobTargetGroupOperationPredicate{}) +} + +// ListByAgentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobTargetGroupsClient) ListByAgentCompleteMatchingPredicate(ctx context.Context, id JobAgentId, predicate JobTargetGroupOperationPredicate) (result ListByAgentCompleteResult, err error) { + items := make([]JobTargetGroup, 0) + + resp, err := c.ListByAgent(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAgentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtarget.go b/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtarget.go new file mode 100644 index 00000000000..f9b2afac9f2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtarget.go @@ -0,0 +1,14 @@ +package jobtargetgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobTarget struct { + DatabaseName *string `json:"databaseName,omitempty"` + ElasticPoolName *string `json:"elasticPoolName,omitempty"` + MembershipType *JobTargetGroupMembershipType `json:"membershipType,omitempty"` + RefreshCredential *string `json:"refreshCredential,omitempty"` + ServerName *string `json:"serverName,omitempty"` + ShardMapName *string `json:"shardMapName,omitempty"` + Type JobTargetType `json:"type"` +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroup.go b/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroup.go new file mode 100644 index 00000000000..31f6e41b7db --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroup.go @@ -0,0 +1,11 @@ +package jobtargetgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobTargetGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *JobTargetGroupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroupproperties.go b/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroupproperties.go new file mode 100644 index 00000000000..073bb27faef --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/model_jobtargetgroupproperties.go @@ -0,0 +1,8 @@ +package jobtargetgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobTargetGroupProperties struct { + Members []JobTarget `json:"members"` +} diff --git a/resource-manager/sql/2023-08-01/jobtargetgroups/predicates.go b/resource-manager/sql/2023-08-01/jobtargetgroups/predicates.go new file mode 100644 index 00000000000..b3389a0f643 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/predicates.go @@ -0,0 +1,27 @@ +package jobtargetgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobTargetGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p JobTargetGroupOperationPredicate) Matches(input JobTargetGroup) 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/sql/2023-08-01/jobtargetgroups/version.go b/resource-manager/sql/2023-08-01/jobtargetgroups/version.go new file mode 100644 index 00000000000..314c108f30d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobtargetgroups/version.go @@ -0,0 +1,10 @@ +package jobtargetgroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobtargetgroups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/jobversions/README.md b/resource-manager/sql/2023-08-01/jobversions/README.md new file mode 100644 index 00000000000..cb9962ecee7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobversions` Documentation + +The `jobversions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/jobversions" +``` + + +### Client Initialization + +```go +client := jobversions.NewJobVersionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `JobVersionsClient.Get` + +```go +ctx := context.TODO() +id := jobversions.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName") + +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: `JobVersionsClient.ListByJob` + +```go +ctx := context.TODO() +id := jobversions.NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + +// alternatively `client.ListByJob(ctx, id)` can be used to do batched pagination +items, err := client.ListByJobComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/jobversions/client.go b/resource-manager/sql/2023-08-01/jobversions/client.go new file mode 100644 index 00000000000..34b9c35d823 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/client.go @@ -0,0 +1,26 @@ +package jobversions + +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 JobVersionsClient struct { + Client *resourcemanager.Client +} + +func NewJobVersionsClientWithBaseURI(sdkApi sdkEnv.Api) (*JobVersionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "jobversions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating JobVersionsClient: %+v", err) + } + + return &JobVersionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/jobversions/id_job.go b/resource-manager/sql/2023-08-01/jobversions/id_job.go new file mode 100644 index 00000000000..93d1be9b9ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/id_job.go @@ -0,0 +1,148 @@ +package jobversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&JobId{}) +} + +var _ resourceids.ResourceId = &JobId{} + +// JobId is a struct representing the Resource ID for a Job +type JobId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string +} + +// NewJobID returns a new JobId struct +func NewJobID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string) JobId { + return JobId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + } +} + +// ParseJobID parses 'input' into a JobId +func ParseJobID(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseJobIDInsensitively parses 'input' case-insensitively into a JobId +// note: this method should only be used for API response data and not user input +func ParseJobIDInsensitively(input string) (*JobId, error) { + parser := resourceids.NewParserFromResourceIdType(&JobId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := JobId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *JobId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + return nil +} + +// ValidateJobID checks that 'input' can be parsed as a Job ID +func ValidateJobID(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 := ParseJobID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Job ID +func (id JobId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Job ID +func (id JobId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + } +} + +// String returns a human-readable description of this Job ID +func (id JobId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + } + return fmt.Sprintf("Job (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobversions/id_job_test.go b/resource-manager/sql/2023-08-01/jobversions/id_job_test.go new file mode 100644 index 00000000000..730ac8031dd --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/id_job_test.go @@ -0,0 +1,372 @@ +package jobversions + +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 = &JobId{} + +func TestNewJobID(t *testing.T) { + id := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseJobID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestParseJobIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *JobId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseJobIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + } +} + +func TestSegmentsForJobId(t *testing.T) { + segments := JobId{}.Segments() + if len(segments) == 0 { + t.Fatalf("JobId 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/sql/2023-08-01/jobversions/id_version.go b/resource-manager/sql/2023-08-01/jobversions/id_version.go new file mode 100644 index 00000000000..f7959fa39ea --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/id_version.go @@ -0,0 +1,157 @@ +package jobversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VersionId{}) +} + +var _ resourceids.ResourceId = &VersionId{} + +// VersionId is a struct representing the Resource ID for a Version +type VersionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + JobAgentName string + JobName string + VersionName string +} + +// NewVersionID returns a new VersionId struct +func NewVersionID(subscriptionId string, resourceGroupName string, serverName string, jobAgentName string, jobName string, versionName string) VersionId { + return VersionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + JobAgentName: jobAgentName, + JobName: jobName, + VersionName: versionName, + } +} + +// ParseVersionID parses 'input' into a VersionId +func ParseVersionID(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVersionIDInsensitively parses 'input' case-insensitively into a VersionId +// note: this method should only be used for API response data and not user input +func ParseVersionIDInsensitively(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.JobAgentName, ok = input.Parsed["jobAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobAgentName", input) + } + + if id.JobName, ok = input.Parsed["jobName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "jobName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateVersionID checks that 'input' can be parsed as a Version ID +func ValidateVersionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Version ID +func (id VersionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/jobAgents/%s/jobs/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.JobAgentName, id.JobName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Version ID +func (id VersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentName"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + } +} + +// String returns a human-readable description of this Version ID +func (id VersionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Job Agent Name: %q", id.JobAgentName), + fmt.Sprintf("Job Name: %q", id.JobName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/jobversions/id_version_test.go b/resource-manager/sql/2023-08-01/jobversions/id_version_test.go new file mode 100644 index 00000000000..269abce98da --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/id_version_test.go @@ -0,0 +1,417 @@ +package jobversions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &VersionId{} + +func TestNewVersionID(t *testing.T) { + id := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.JobAgentName != "jobAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentName") + } + + if id.JobName != "jobName" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "jobAgentName", "jobName", "versionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestParseVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + JobAgentName: "jobAgentName", + JobName: "jobName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/jobAgents/jobAgentName/jobs/jobName/versions/versionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + JobAgentName: "jObAgEnTnAmE", + JobName: "jObNaMe", + VersionName: "vErSiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/jObAgEnTs/jObAgEnTnAmE/jObS/jObNaMe/vErSiOnS/vErSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.JobAgentName != v.Expected.JobAgentName { + t.Fatalf("Expected %q but got %q for JobAgentName", v.Expected.JobAgentName, actual.JobAgentName) + } + + if actual.JobName != v.Expected.JobName { + t.Fatalf("Expected %q but got %q for JobName", v.Expected.JobName, actual.JobName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestSegmentsForVersionId(t *testing.T) { + segments := VersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VersionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/sql/2023-08-01/jobversions/method_get.go b/resource-manager/sql/2023-08-01/jobversions/method_get.go new file mode 100644 index 00000000000..02d5d8e4621 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/method_get.go @@ -0,0 +1,53 @@ +package jobversions + +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 *Resource +} + +// Get ... +func (c JobVersionsClient) Get(ctx context.Context, id VersionId) (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 Resource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/jobversions/method_listbyjob.go b/resource-manager/sql/2023-08-01/jobversions/method_listbyjob.go new file mode 100644 index 00000000000..0eb60597289 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/method_listbyjob.go @@ -0,0 +1,105 @@ +package jobversions + +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 ListByJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type ListByJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type ListByJobCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByJobCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByJob ... +func (c JobVersionsClient) ListByJob(ctx context.Context, id JobId) (result ListByJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByJobCustomPager{}, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByJobComplete retrieves all the results into a single object +func (c JobVersionsClient) ListByJobComplete(ctx context.Context, id JobId) (ListByJobCompleteResult, error) { + return c.ListByJobCompleteMatchingPredicate(ctx, id, ResourceOperationPredicate{}) +} + +// ListByJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c JobVersionsClient) ListByJobCompleteMatchingPredicate(ctx context.Context, id JobId, predicate ResourceOperationPredicate) (result ListByJobCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.ListByJob(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/jobversions/model_resource.go b/resource-manager/sql/2023-08-01/jobversions/model_resource.go new file mode 100644 index 00000000000..72476412a2d --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/model_resource.go @@ -0,0 +1,10 @@ +package jobversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/jobversions/predicates.go b/resource-manager/sql/2023-08-01/jobversions/predicates.go new file mode 100644 index 00000000000..c1092c878ce --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/predicates.go @@ -0,0 +1,27 @@ +package jobversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/sql/2023-08-01/jobversions/version.go b/resource-manager/sql/2023-08-01/jobversions/version.go new file mode 100644 index 00000000000..0af98056196 --- /dev/null +++ b/resource-manager/sql/2023-08-01/jobversions/version.go @@ -0,0 +1,10 @@ +package jobversions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/jobversions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/README.md b/resource-manager/sql/2023-08-01/ledgerdigestuploads/README.md new file mode 100644 index 00000000000..616379b926d --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/ledgerdigestuploads` Documentation + +The `ledgerdigestuploads` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/ledgerdigestuploads" +``` + + +### Client Initialization + +```go +client := ledgerdigestuploads.NewLedgerDigestUploadsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LedgerDigestUploadsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := ledgerdigestuploads.LedgerDigestUploads{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LedgerDigestUploadsClient.Disable` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +if err := client.DisableThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LedgerDigestUploadsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `LedgerDigestUploadsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/client.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/client.go new file mode 100644 index 00000000000..db269c39127 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/client.go @@ -0,0 +1,26 @@ +package ledgerdigestuploads + +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 LedgerDigestUploadsClient struct { + Client *resourcemanager.Client +} + +func NewLedgerDigestUploadsClientWithBaseURI(sdkApi sdkEnv.Api) (*LedgerDigestUploadsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "ledgerdigestuploads", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LedgerDigestUploadsClient: %+v", err) + } + + return &LedgerDigestUploadsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/constants.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/constants.go new file mode 100644 index 00000000000..fe4ba62234f --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/constants.go @@ -0,0 +1,51 @@ +package ledgerdigestuploads + +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 LedgerDigestUploadsState string + +const ( + LedgerDigestUploadsStateDisabled LedgerDigestUploadsState = "Disabled" + LedgerDigestUploadsStateEnabled LedgerDigestUploadsState = "Enabled" +) + +func PossibleValuesForLedgerDigestUploadsState() []string { + return []string{ + string(LedgerDigestUploadsStateDisabled), + string(LedgerDigestUploadsStateEnabled), + } +} + +func (s *LedgerDigestUploadsState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLedgerDigestUploadsState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLedgerDigestUploadsState(input string) (*LedgerDigestUploadsState, error) { + vals := map[string]LedgerDigestUploadsState{ + "disabled": LedgerDigestUploadsStateDisabled, + "enabled": LedgerDigestUploadsStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LedgerDigestUploadsState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_createorupdate.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_createorupdate.go new file mode 100644 index 00000000000..b750ec7aadc --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_createorupdate.go @@ -0,0 +1,76 @@ +package ledgerdigestuploads + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LedgerDigestUploads +} + +// CreateOrUpdate ... +func (c LedgerDigestUploadsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input LedgerDigestUploads) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/ledgerDigestUploads/current", 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 LedgerDigestUploadsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input LedgerDigestUploads) 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/sql/2023-08-01/ledgerdigestuploads/method_disable.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_disable.go new file mode 100644 index 00000000000..d27be547ba2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_disable.go @@ -0,0 +1,72 @@ +package ledgerdigestuploads + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DisableOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LedgerDigestUploads +} + +// Disable ... +func (c LedgerDigestUploadsClient) Disable(ctx context.Context, id commonids.SqlDatabaseId) (result DisableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/ledgerDigestUploads/current/disable", 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 +} + +// DisableThenPoll performs Disable then polls until it's completed +func (c LedgerDigestUploadsClient) DisableThenPoll(ctx context.Context, id commonids.SqlDatabaseId) error { + result, err := c.Disable(ctx, id) + if err != nil { + return fmt.Errorf("performing Disable: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Disable: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_get.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_get.go new file mode 100644 index 00000000000..33176ebdcbe --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_get.go @@ -0,0 +1,55 @@ +package ledgerdigestuploads + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LedgerDigestUploads +} + +// Get ... +func (c LedgerDigestUploadsClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/ledgerDigestUploads/current", 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 LedgerDigestUploads + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_listbydatabase.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_listbydatabase.go new file mode 100644 index 00000000000..4bf91908814 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/method_listbydatabase.go @@ -0,0 +1,106 @@ +package ledgerdigestuploads + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LedgerDigestUploads +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []LedgerDigestUploads +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c LedgerDigestUploadsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/ledgerDigestUploads", 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 *[]LedgerDigestUploads `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c LedgerDigestUploadsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, LedgerDigestUploadsOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LedgerDigestUploadsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate LedgerDigestUploadsOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]LedgerDigestUploads, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploads.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploads.go new file mode 100644 index 00000000000..ac8f3dd931d --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploads.go @@ -0,0 +1,11 @@ +package ledgerdigestuploads + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LedgerDigestUploads struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LedgerDigestUploadsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go new file mode 100644 index 00000000000..af8731e568d --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go @@ -0,0 +1,9 @@ +package ledgerdigestuploads + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LedgerDigestUploadsProperties struct { + DigestStorageEndpoint *string `json:"digestStorageEndpoint,omitempty"` + State *LedgerDigestUploadsState `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/ledgerdigestuploads/predicates.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/predicates.go new file mode 100644 index 00000000000..bf2a2ba00b9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/predicates.go @@ -0,0 +1,27 @@ +package ledgerdigestuploads + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LedgerDigestUploadsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LedgerDigestUploadsOperationPredicate) Matches(input LedgerDigestUploads) 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/sql/2023-08-01/ledgerdigestuploads/version.go b/resource-manager/sql/2023-08-01/ledgerdigestuploads/version.go new file mode 100644 index 00000000000..9ae11ea9b6d --- /dev/null +++ b/resource-manager/sql/2023-08-01/ledgerdigestuploads/version.go @@ -0,0 +1,10 @@ +package ledgerdigestuploads + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/ledgerdigestuploads/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/README.md b/resource-manager/sql/2023-08-01/locationcapabilities/README.md new file mode 100644 index 00000000000..fc8307c41fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/locationcapabilities` Documentation + +The `locationcapabilities` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/locationcapabilities" +``` + + +### Client Initialization + +```go +client := locationcapabilities.NewLocationCapabilitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LocationCapabilitiesClient.CapabilitiesListByLocation` + +```go +ctx := context.TODO() +id := locationcapabilities.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +read, err := client.CapabilitiesListByLocation(ctx, id, locationcapabilities.DefaultCapabilitiesListByLocationOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/client.go b/resource-manager/sql/2023-08-01/locationcapabilities/client.go new file mode 100644 index 00000000000..4b3add57b3b --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/client.go @@ -0,0 +1,26 @@ +package locationcapabilities + +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 LocationCapabilitiesClient struct { + Client *resourcemanager.Client +} + +func NewLocationCapabilitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*LocationCapabilitiesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "locationcapabilities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LocationCapabilitiesClient: %+v", err) + } + + return &LocationCapabilitiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/constants.go b/resource-manager/sql/2023-08-01/locationcapabilities/constants.go new file mode 100644 index 00000000000..9eaca8b3729 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/constants.go @@ -0,0 +1,374 @@ +package locationcapabilities + +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 CapabilityGroup string + +const ( + CapabilityGroupSupportedEditions CapabilityGroup = "supportedEditions" + CapabilityGroupSupportedElasticPoolEditions CapabilityGroup = "supportedElasticPoolEditions" + CapabilityGroupSupportedInstancePoolEditions CapabilityGroup = "supportedInstancePoolEditions" + CapabilityGroupSupportedJobAgentVersions CapabilityGroup = "supportedJobAgentVersions" + CapabilityGroupSupportedManagedInstanceEditions CapabilityGroup = "supportedManagedInstanceEditions" + CapabilityGroupSupportedManagedInstanceVersions CapabilityGroup = "supportedManagedInstanceVersions" +) + +func PossibleValuesForCapabilityGroup() []string { + return []string{ + string(CapabilityGroupSupportedEditions), + string(CapabilityGroupSupportedElasticPoolEditions), + string(CapabilityGroupSupportedInstancePoolEditions), + string(CapabilityGroupSupportedJobAgentVersions), + string(CapabilityGroupSupportedManagedInstanceEditions), + string(CapabilityGroupSupportedManagedInstanceVersions), + } +} + +func (s *CapabilityGroup) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCapabilityGroup(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCapabilityGroup(input string) (*CapabilityGroup, error) { + vals := map[string]CapabilityGroup{ + "supportededitions": CapabilityGroupSupportedEditions, + "supportedelasticpooleditions": CapabilityGroupSupportedElasticPoolEditions, + "supportedinstancepooleditions": CapabilityGroupSupportedInstancePoolEditions, + "supportedjobagentversions": CapabilityGroupSupportedJobAgentVersions, + "supportedmanagedinstanceeditions": CapabilityGroupSupportedManagedInstanceEditions, + "supportedmanagedinstanceversions": CapabilityGroupSupportedManagedInstanceVersions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CapabilityGroup(input) + return &out, nil +} + +type CapabilityStatus string + +const ( + CapabilityStatusAvailable CapabilityStatus = "Available" + CapabilityStatusDefault CapabilityStatus = "Default" + CapabilityStatusDisabled CapabilityStatus = "Disabled" + CapabilityStatusVisible CapabilityStatus = "Visible" +) + +func PossibleValuesForCapabilityStatus() []string { + return []string{ + string(CapabilityStatusAvailable), + string(CapabilityStatusDefault), + string(CapabilityStatusDisabled), + string(CapabilityStatusVisible), + } +} + +func (s *CapabilityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCapabilityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCapabilityStatus(input string) (*CapabilityStatus, error) { + vals := map[string]CapabilityStatus{ + "available": CapabilityStatusAvailable, + "default": CapabilityStatusDefault, + "disabled": CapabilityStatusDisabled, + "visible": CapabilityStatusVisible, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CapabilityStatus(input) + return &out, nil +} + +type FreeLimitExhaustionBehavior string + +const ( + FreeLimitExhaustionBehaviorAutoPause FreeLimitExhaustionBehavior = "AutoPause" + FreeLimitExhaustionBehaviorBillOverUsage FreeLimitExhaustionBehavior = "BillOverUsage" +) + +func PossibleValuesForFreeLimitExhaustionBehavior() []string { + return []string{ + string(FreeLimitExhaustionBehaviorAutoPause), + string(FreeLimitExhaustionBehaviorBillOverUsage), + } +} + +func (s *FreeLimitExhaustionBehavior) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFreeLimitExhaustionBehavior(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFreeLimitExhaustionBehavior(input string) (*FreeLimitExhaustionBehavior, error) { + vals := map[string]FreeLimitExhaustionBehavior{ + "autopause": FreeLimitExhaustionBehaviorAutoPause, + "billoverusage": FreeLimitExhaustionBehaviorBillOverUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FreeLimitExhaustionBehavior(input) + return &out, nil +} + +type LogSizeUnit string + +const ( + LogSizeUnitGigabytes LogSizeUnit = "Gigabytes" + LogSizeUnitMegabytes LogSizeUnit = "Megabytes" + LogSizeUnitPercent LogSizeUnit = "Percent" + LogSizeUnitPetabytes LogSizeUnit = "Petabytes" + LogSizeUnitTerabytes LogSizeUnit = "Terabytes" +) + +func PossibleValuesForLogSizeUnit() []string { + return []string{ + string(LogSizeUnitGigabytes), + string(LogSizeUnitMegabytes), + string(LogSizeUnitPercent), + string(LogSizeUnitPetabytes), + string(LogSizeUnitTerabytes), + } +} + +func (s *LogSizeUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLogSizeUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLogSizeUnit(input string) (*LogSizeUnit, error) { + vals := map[string]LogSizeUnit{ + "gigabytes": LogSizeUnitGigabytes, + "megabytes": LogSizeUnitMegabytes, + "percent": LogSizeUnitPercent, + "petabytes": LogSizeUnitPetabytes, + "terabytes": LogSizeUnitTerabytes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LogSizeUnit(input) + return &out, nil +} + +type MaxSizeUnit string + +const ( + MaxSizeUnitGigabytes MaxSizeUnit = "Gigabytes" + MaxSizeUnitMegabytes MaxSizeUnit = "Megabytes" + MaxSizeUnitPetabytes MaxSizeUnit = "Petabytes" + MaxSizeUnitTerabytes MaxSizeUnit = "Terabytes" +) + +func PossibleValuesForMaxSizeUnit() []string { + return []string{ + string(MaxSizeUnitGigabytes), + string(MaxSizeUnitMegabytes), + string(MaxSizeUnitPetabytes), + string(MaxSizeUnitTerabytes), + } +} + +func (s *MaxSizeUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMaxSizeUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMaxSizeUnit(input string) (*MaxSizeUnit, error) { + vals := map[string]MaxSizeUnit{ + "gigabytes": MaxSizeUnitGigabytes, + "megabytes": MaxSizeUnitMegabytes, + "petabytes": MaxSizeUnitPetabytes, + "terabytes": MaxSizeUnitTerabytes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MaxSizeUnit(input) + return &out, nil +} + +type PauseDelayTimeUnit string + +const ( + PauseDelayTimeUnitMinutes PauseDelayTimeUnit = "Minutes" +) + +func PossibleValuesForPauseDelayTimeUnit() []string { + return []string{ + string(PauseDelayTimeUnitMinutes), + } +} + +func (s *PauseDelayTimeUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePauseDelayTimeUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePauseDelayTimeUnit(input string) (*PauseDelayTimeUnit, error) { + vals := map[string]PauseDelayTimeUnit{ + "minutes": PauseDelayTimeUnitMinutes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PauseDelayTimeUnit(input) + return &out, nil +} + +type PerformanceLevelUnit string + +const ( + PerformanceLevelUnitDTU PerformanceLevelUnit = "DTU" + PerformanceLevelUnitVCores PerformanceLevelUnit = "VCores" +) + +func PossibleValuesForPerformanceLevelUnit() []string { + return []string{ + string(PerformanceLevelUnitDTU), + string(PerformanceLevelUnitVCores), + } +} + +func (s *PerformanceLevelUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePerformanceLevelUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePerformanceLevelUnit(input string) (*PerformanceLevelUnit, error) { + vals := map[string]PerformanceLevelUnit{ + "dtu": PerformanceLevelUnitDTU, + "vcores": PerformanceLevelUnitVCores, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PerformanceLevelUnit(input) + return &out, nil +} + +type StorageAccountType string + +const ( + StorageAccountTypeGRS StorageAccountType = "GRS" + StorageAccountTypeGZRS StorageAccountType = "GZRS" + StorageAccountTypeLRS StorageAccountType = "LRS" + StorageAccountTypeZRS StorageAccountType = "ZRS" +) + +func PossibleValuesForStorageAccountType() []string { + return []string{ + string(StorageAccountTypeGRS), + string(StorageAccountTypeGZRS), + string(StorageAccountTypeLRS), + string(StorageAccountTypeZRS), + } +} + +func (s *StorageAccountType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageAccountType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageAccountType(input string) (*StorageAccountType, error) { + vals := map[string]StorageAccountType{ + "grs": StorageAccountTypeGRS, + "gzrs": StorageAccountTypeGZRS, + "lrs": StorageAccountTypeLRS, + "zrs": StorageAccountTypeZRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageAccountType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/id_location.go b/resource-manager/sql/2023-08-01/locationcapabilities/id_location.go new file mode 100644 index 00000000000..6e6b2e8857c --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/id_location.go @@ -0,0 +1,121 @@ +package locationcapabilities + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/id_location_test.go b/resource-manager/sql/2023-08-01/locationcapabilities/id_location_test.go new file mode 100644 index 00000000000..820efda6598 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/id_location_test.go @@ -0,0 +1,237 @@ +package locationcapabilities + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/locationcapabilities/method_capabilitieslistbylocation.go b/resource-manager/sql/2023-08-01/locationcapabilities/method_capabilitieslistbylocation.go new file mode 100644 index 00000000000..1b60f18f5fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/method_capabilitieslistbylocation.go @@ -0,0 +1,83 @@ +package locationcapabilities + +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 CapabilitiesListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LocationCapabilities +} + +type CapabilitiesListByLocationOperationOptions struct { + Include *CapabilityGroup +} + +func DefaultCapabilitiesListByLocationOperationOptions() CapabilitiesListByLocationOperationOptions { + return CapabilitiesListByLocationOperationOptions{} +} + +func (o CapabilitiesListByLocationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CapabilitiesListByLocationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CapabilitiesListByLocationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Include != nil { + out.Append("include", fmt.Sprintf("%v", *o.Include)) + } + return &out +} + +// CapabilitiesListByLocation ... +func (c LocationCapabilitiesClient) CapabilitiesListByLocation(ctx context.Context, id LocationId, options CapabilitiesListByLocationOperationOptions) (result CapabilitiesListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/capabilities", 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 LocationCapabilities + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_autopausedelaytimerange.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_autopausedelaytimerange.go new file mode 100644 index 00000000000..c22119183c0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_autopausedelaytimerange.go @@ -0,0 +1,13 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutoPauseDelayTimeRange struct { + Default *int64 `json:"default,omitempty"` + DoNotPauseValue *int64 `json:"doNotPauseValue,omitempty"` + MaxValue *int64 `json:"maxValue,omitempty"` + MinValue *int64 `json:"minValue,omitempty"` + StepSize *int64 `json:"stepSize,omitempty"` + Unit *PauseDelayTimeUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_editioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_editioncapability.go new file mode 100644 index 00000000000..95fe5674bd2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_editioncapability.go @@ -0,0 +1,15 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EditionCapability struct { + Name *string `json:"name,omitempty"` + ReadScale *ReadScaleCapability `json:"readScale,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedServiceLevelObjectives *[]ServiceObjectiveCapability `json:"supportedServiceLevelObjectives,omitempty"` + SupportedStorageCapabilities *[]StorageCapability `json:"supportedStorageCapabilities,omitempty"` + ZonePinning *bool `json:"zonePinning,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpooleditioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpooleditioncapability.go new file mode 100644 index 00000000000..3b3b0d0cdfa --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpooleditioncapability.go @@ -0,0 +1,13 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolEditionCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedElasticPoolPerformanceLevels *[]ElasticPoolPerformanceLevelCapability `json:"supportedElasticPoolPerformanceLevels,omitempty"` + ZonePinning *bool `json:"zonePinning,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go new file mode 100644 index 00000000000..4cd27f60a29 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolPerDatabaseMaxPerformanceLevelCapability struct { + Limit *float64 `json:"limit,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedPerDatabaseMinPerformanceLevels *[]ElasticPoolPerDatabaseMinPerformanceLevelCapability `json:"supportedPerDatabaseMinPerformanceLevels,omitempty"` + Unit *PerformanceLevelUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go new file mode 100644 index 00000000000..5f1e9d6911f --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go @@ -0,0 +1,11 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolPerDatabaseMinPerformanceLevelCapability struct { + Limit *float64 `json:"limit,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + Unit *PerformanceLevelUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperformancelevelcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperformancelevelcapability.go new file mode 100644 index 00000000000..3a72b47ca98 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_elasticpoolperformancelevelcapability.go @@ -0,0 +1,23 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ElasticPoolPerformanceLevelCapability struct { + IncludedMaxSize *MaxSizeCapability `json:"includedMaxSize,omitempty"` + MaxDatabaseCount *int64 `json:"maxDatabaseCount,omitempty"` + PerformanceLevel *PerformanceLevelCapability `json:"performanceLevel,omitempty"` + Reason *string `json:"reason,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedAutoPauseDelay *AutoPauseDelayTimeRange `json:"supportedAutoPauseDelay,omitempty"` + SupportedLicenseTypes *[]LicenseTypeCapability `json:"supportedLicenseTypes,omitempty"` + SupportedMaintenanceConfigurations *[]MaintenanceConfigurationCapability `json:"supportedMaintenanceConfigurations,omitempty"` + SupportedMaxSizes *[]MaxSizeRangeCapability `json:"supportedMaxSizes,omitempty"` + SupportedMinCapacities *[]MinCapacityCapability `json:"supportedMinCapacities,omitempty"` + SupportedPerDatabaseAutoPauseDelay *PerDatabaseAutoPauseDelayTimeRange `json:"supportedPerDatabaseAutoPauseDelay,omitempty"` + SupportedPerDatabaseMaxPerformanceLevels *[]ElasticPoolPerDatabaseMaxPerformanceLevelCapability `json:"supportedPerDatabaseMaxPerformanceLevels,omitempty"` + SupportedPerDatabaseMaxSizes *[]MaxSizeRangeCapability `json:"supportedPerDatabaseMaxSizes,omitempty"` + SupportedZones *[]ZonePinningCapability `json:"supportedZones,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go new file mode 100644 index 00000000000..45883e3df94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go @@ -0,0 +1,9 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FreeLimitExhaustionBehaviorCapability struct { + ExhaustionBehaviorType *FreeLimitExhaustionBehavior `json:"exhaustionBehaviorType,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepooleditioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepooleditioncapability.go new file mode 100644 index 00000000000..607f5fb35bb --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepooleditioncapability.go @@ -0,0 +1,11 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePoolEditionCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedFamilies *[]InstancePoolFamilyCapability `json:"supportedFamilies,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolfamilycapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolfamilycapability.go new file mode 100644 index 00000000000..f4cae2b5ae9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolfamilycapability.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePoolFamilyCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedLicenseTypes *[]LicenseTypeCapability `json:"supportedLicenseTypes,omitempty"` + SupportedVcoresValues *[]InstancePoolVcoresCapability `json:"supportedVcoresValues,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolvcorescapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolvcorescapability.go new file mode 100644 index 00000000000..c64bb0adbbb --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_instancepoolvcorescapability.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InstancePoolVcoresCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + StorageLimit *MaxSizeCapability `json:"storageLimit,omitempty"` + Value *int64 `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagenteditioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagenteditioncapability.go new file mode 100644 index 00000000000..bcdd20d97c3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagenteditioncapability.go @@ -0,0 +1,11 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentEditionCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedServiceLevelObjectives *[]JobAgentServiceLevelObjectiveCapability `json:"supportedServiceLevelObjectives,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentservicelevelobjectivecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentservicelevelobjectivecapability.go new file mode 100644 index 00000000000..5e3ae3a3c73 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentservicelevelobjectivecapability.go @@ -0,0 +1,11 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentServiceLevelObjectiveCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentversioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentversioncapability.go new file mode 100644 index 00000000000..ef40b29e5fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_jobagentversioncapability.go @@ -0,0 +1,11 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type JobAgentVersionCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedEditions *[]JobAgentEditionCapability `json:"supportedEditions,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_licensetypecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_licensetypecapability.go new file mode 100644 index 00000000000..0a7375fba7c --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_licensetypecapability.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LicenseTypeCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_locationcapabilities.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_locationcapabilities.go new file mode 100644 index 00000000000..7329b1b76d1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_locationcapabilities.go @@ -0,0 +1,13 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LocationCapabilities struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedJobAgentVersions *[]JobAgentVersionCapability `json:"supportedJobAgentVersions,omitempty"` + SupportedManagedInstanceVersions *[]ManagedInstanceVersionCapability `json:"supportedManagedInstanceVersions,omitempty"` + SupportedServerVersions *[]ServerVersionCapability `json:"supportedServerVersions,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_logsizecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_logsizecapability.go new file mode 100644 index 00000000000..a5249b4100e --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_logsizecapability.go @@ -0,0 +1,9 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogSizeCapability struct { + Limit *int64 `json:"limit,omitempty"` + Unit *LogSizeUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_maintenanceconfigurationcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_maintenanceconfigurationcapability.go new file mode 100644 index 00000000000..2a67aeb7d8f --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_maintenanceconfigurationcapability.go @@ -0,0 +1,11 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceConfigurationCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceeditioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceeditioncapability.go new file mode 100644 index 00000000000..b77450b145b --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceeditioncapability.go @@ -0,0 +1,13 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceEditionCapability struct { + IsGeneralPurposeV2 *bool `json:"isGeneralPurposeV2,omitempty"` + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedFamilies *[]ManagedInstanceFamilyCapability `json:"supportedFamilies,omitempty"` + SupportedStorageCapabilities *[]StorageCapability `json:"supportedStorageCapabilities,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancefamilycapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancefamilycapability.go new file mode 100644 index 00000000000..a1edfe8a653 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancefamilycapability.go @@ -0,0 +1,14 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceFamilyCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Sku *string `json:"sku,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedLicenseTypes *[]LicenseTypeCapability `json:"supportedLicenseTypes,omitempty"` + SupportedVcoresValues *[]ManagedInstanceVcoresCapability `json:"supportedVcoresValues,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go new file mode 100644 index 00000000000..fde89141037 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceMaintenanceConfigurationCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancevcorescapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancevcorescapability.go new file mode 100644 index 00000000000..492092afcae --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstancevcorescapability.go @@ -0,0 +1,25 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceVcoresCapability struct { + IncludedMaxSize *MaxSizeCapability `json:"includedMaxSize,omitempty"` + IncludedStorageIOps *int64 `json:"includedStorageIOps,omitempty"` + IncludedStorageThroughputMBps *int64 `json:"includedStorageThroughputMBps,omitempty"` + InstancePoolSupported *bool `json:"instancePoolSupported,omitempty"` + IopsIncludedValueOverrideFactorPerSelectedStorageGB *float64 `json:"iopsIncludedValueOverrideFactorPerSelectedStorageGB,omitempty"` + IopsMinValueOverrideFactorPerSelectedStorageGB *float64 `json:"iopsMinValueOverrideFactorPerSelectedStorageGB,omitempty"` + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + StandaloneSupported *bool `json:"standaloneSupported,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedMaintenanceConfigurations *[]ManagedInstanceMaintenanceConfigurationCapability `json:"supportedMaintenanceConfigurations,omitempty"` + SupportedMemoryLimitsMB *MaxLimitRangeCapability `json:"supportedMemoryLimitsMB,omitempty"` + SupportedStorageIOps *MaxLimitRangeCapability `json:"supportedStorageIOps,omitempty"` + SupportedStorageSizes *[]MaxSizeRangeCapability `json:"supportedStorageSizes,omitempty"` + SupportedStorageThroughputMBps *MaxLimitRangeCapability `json:"supportedStorageThroughputMBps,omitempty"` + ThroughputMBpsIncludedValueOverrideFactorPerSelectedStorageGB *float64 `json:"throughputMBpsIncludedValueOverrideFactorPerSelectedStorageGB,omitempty"` + ThroughputMBpsMinValueOverrideFactorPerSelectedStorageGB *float64 `json:"throughputMBpsMinValueOverrideFactorPerSelectedStorageGB,omitempty"` + Value *int64 `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceversioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceversioncapability.go new file mode 100644 index 00000000000..cc445f2b163 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_managedinstanceversioncapability.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceVersionCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedEditions *[]ManagedInstanceEditionCapability `json:"supportedEditions,omitempty"` + SupportedInstancePoolEditions *[]InstancePoolEditionCapability `json:"supportedInstancePoolEditions,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_maxlimitrangecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_maxlimitrangecapability.go new file mode 100644 index 00000000000..3f5e70f60a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_maxlimitrangecapability.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaxLimitRangeCapability struct { + MaxValue *int64 `json:"maxValue,omitempty"` + MinValue *int64 `json:"minValue,omitempty"` + Reason *string `json:"reason,omitempty"` + ScaleSize *int64 `json:"scaleSize,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizecapability.go new file mode 100644 index 00000000000..43eb99185a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizecapability.go @@ -0,0 +1,9 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaxSizeCapability struct { + Limit *int64 `json:"limit,omitempty"` + Unit *MaxSizeUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizerangecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizerangecapability.go new file mode 100644 index 00000000000..c648238bad9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_maxsizerangecapability.go @@ -0,0 +1,13 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaxSizeRangeCapability struct { + LogSize *LogSizeCapability `json:"logSize,omitempty"` + MaxValue *MaxSizeCapability `json:"maxValue,omitempty"` + MinValue *MaxSizeCapability `json:"minValue,omitempty"` + Reason *string `json:"reason,omitempty"` + ScaleSize *MaxSizeCapability `json:"scaleSize,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_mincapacitycapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_mincapacitycapability.go new file mode 100644 index 00000000000..4d55b823db9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_mincapacitycapability.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MinCapacityCapability struct { + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + Value *float64 `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_perdatabaseautopausedelaytimerange.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_perdatabaseautopausedelaytimerange.go new file mode 100644 index 00000000000..3f84a5c2673 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_perdatabaseautopausedelaytimerange.go @@ -0,0 +1,13 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PerDatabaseAutoPauseDelayTimeRange struct { + Default *int64 `json:"default,omitempty"` + DoNotPauseValue *int64 `json:"doNotPauseValue,omitempty"` + MaxValue *int64 `json:"maxValue,omitempty"` + MinValue *int64 `json:"minValue,omitempty"` + StepSize *int64 `json:"stepSize,omitempty"` + Unit *PauseDelayTimeUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_performancelevelcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_performancelevelcapability.go new file mode 100644 index 00000000000..442b95ccbf5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_performancelevelcapability.go @@ -0,0 +1,9 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PerformanceLevelCapability struct { + Unit *PerformanceLevelUnit `json:"unit,omitempty"` + Value *float64 `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_readscalecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_readscalecapability.go new file mode 100644 index 00000000000..666d6277e83 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_readscalecapability.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReadScaleCapability struct { + MaxNumberOfReplicas *int64 `json:"maxNumberOfReplicas,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_serverversioncapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_serverversioncapability.go new file mode 100644 index 00000000000..526f6618229 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_serverversioncapability.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVersionCapability struct { + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedEditions *[]EditionCapability `json:"supportedEditions,omitempty"` + SupportedElasticPoolEditions *[]ElasticPoolEditionCapability `json:"supportedElasticPoolEditions,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_serviceobjectivecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_serviceobjectivecapability.go new file mode 100644 index 00000000000..ba90c7286b3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_serviceobjectivecapability.go @@ -0,0 +1,24 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServiceObjectiveCapability struct { + ComputeModel *string `json:"computeModel,omitempty"` + Id *string `json:"id,omitempty"` + IncludedMaxSize *MaxSizeCapability `json:"includedMaxSize,omitempty"` + Name *string `json:"name,omitempty"` + PerformanceLevel *PerformanceLevelCapability `json:"performanceLevel,omitempty"` + Reason *string `json:"reason,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + SupportedAutoPauseDelay *AutoPauseDelayTimeRange `json:"supportedAutoPauseDelay,omitempty"` + SupportedFreeLimitExhaustionBehaviors *[]FreeLimitExhaustionBehaviorCapability `json:"supportedFreeLimitExhaustionBehaviors,omitempty"` + SupportedLicenseTypes *[]LicenseTypeCapability `json:"supportedLicenseTypes,omitempty"` + SupportedMaintenanceConfigurations *[]MaintenanceConfigurationCapability `json:"supportedMaintenanceConfigurations,omitempty"` + SupportedMaxSizes *[]MaxSizeRangeCapability `json:"supportedMaxSizes,omitempty"` + SupportedMinCapacities *[]MinCapacityCapability `json:"supportedMinCapacities,omitempty"` + SupportedZones *[]ZonePinningCapability `json:"supportedZones,omitempty"` + ZonePinning *bool `json:"zonePinning,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_sku.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_sku.go new file mode 100644 index 00000000000..5d6bfbf8d6b --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_sku.go @@ -0,0 +1,12 @@ +package locationcapabilities + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_storagecapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_storagecapability.go new file mode 100644 index 00000000000..ae16270f9d0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_storagecapability.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StorageCapability struct { + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` + StorageAccountType *StorageAccountType `json:"storageAccountType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/model_zonepinningcapability.go b/resource-manager/sql/2023-08-01/locationcapabilities/model_zonepinningcapability.go new file mode 100644 index 00000000000..5869ed388dd --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/model_zonepinningcapability.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ZonePinningCapability struct { + AvailabilityZone *string `json:"availabilityZone,omitempty"` + Reason *string `json:"reason,omitempty"` + Status *CapabilityStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/locationcapabilities/version.go b/resource-manager/sql/2023-08-01/locationcapabilities/version.go new file mode 100644 index 00000000000..0a516a3f354 --- /dev/null +++ b/resource-manager/sql/2023-08-01/locationcapabilities/version.go @@ -0,0 +1,10 @@ +package locationcapabilities + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/locationcapabilities/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/README.md b/resource-manager/sql/2023-08-01/longtermretentionbackups/README.md new file mode 100644 index 00000000000..1f18d4843b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/README.md @@ -0,0 +1,280 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionbackups` Documentation + +The `longtermretentionbackups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionbackups" +``` + + +### Client Initialization + +```go +client := longtermretentionbackups.NewLongTermRetentionBackupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ChangeAccessTier` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +payload := longtermretentionbackups.ChangeLongTermRetentionBackupAccessTierParameters{ + // ... +} + + +if err := client.ChangeAccessTierThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ChangeAccessTierByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +payload := longtermretentionbackups.ChangeLongTermRetentionBackupAccessTierParameters{ + // ... +} + + +if err := client.ChangeAccessTierByResourceGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.Copy` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +payload := longtermretentionbackups.CopyLongTermRetentionBackupParameters{ + // ... +} + + +if err := client.CopyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.CopyByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +payload := longtermretentionbackups.CopyLongTermRetentionBackupParameters{ + // ... +} + + +if err := client.CopyByResourceGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.Delete` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.DeleteByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +if err := client.DeleteByResourceGroupThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.Get` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +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: `LongTermRetentionBackupsClient.GetByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +read, err := client.GetByResourceGroup(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName") + +// alternatively `client.ListByDatabase(ctx, id, longtermretentionbackups.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, longtermretentionbackups.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ListByLocation` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.ListByLocation(ctx, id, longtermretentionbackups.DefaultListByLocationOperationOptions())` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id, longtermretentionbackups.DefaultListByLocationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ListByResourceGroupDatabase` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLocationLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName") + +// alternatively `client.ListByResourceGroupDatabase(ctx, id, longtermretentionbackups.DefaultListByResourceGroupDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupDatabaseComplete(ctx, id, longtermretentionbackups.DefaultListByResourceGroupDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ListByResourceGroupLocation` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +// alternatively `client.ListByResourceGroupLocation(ctx, id, longtermretentionbackups.DefaultListByResourceGroupLocationOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupLocationComplete(ctx, id, longtermretentionbackups.DefaultListByResourceGroupLocationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ListByResourceGroupServer` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLocationLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName") + +// alternatively `client.ListByResourceGroupServer(ctx, id, longtermretentionbackups.DefaultListByResourceGroupServerOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupServerComplete(ctx, id, longtermretentionbackups.DefaultListByResourceGroupServerOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.ListByServer` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName") + +// alternatively `client.ListByServer(ctx, id, longtermretentionbackups.DefaultListByServerOperationOptions())` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id, longtermretentionbackups.DefaultListByServerOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.Update` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +payload := longtermretentionbackups.UpdateLongTermRetentionBackupParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionBackupsClient.UpdateByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionbackups.NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + +payload := longtermretentionbackups.UpdateLongTermRetentionBackupParameters{ + // ... +} + + +if err := client.UpdateByResourceGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/client.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/client.go new file mode 100644 index 00000000000..9e4e155a0b4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/client.go @@ -0,0 +1,26 @@ +package longtermretentionbackups + +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 LongTermRetentionBackupsClient struct { + Client *resourcemanager.Client +} + +func NewLongTermRetentionBackupsClientWithBaseURI(sdkApi sdkEnv.Api) (*LongTermRetentionBackupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "longtermretentionbackups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LongTermRetentionBackupsClient: %+v", err) + } + + return &LongTermRetentionBackupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/constants.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/constants.go new file mode 100644 index 00000000000..58adb551b2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/constants.go @@ -0,0 +1,142 @@ +package longtermretentionbackups + +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 BackupStorageAccessTier string + +const ( + BackupStorageAccessTierArchive BackupStorageAccessTier = "Archive" + BackupStorageAccessTierHot BackupStorageAccessTier = "Hot" +) + +func PossibleValuesForBackupStorageAccessTier() []string { + return []string{ + string(BackupStorageAccessTierArchive), + string(BackupStorageAccessTierHot), + } +} + +func (s *BackupStorageAccessTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageAccessTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageAccessTier(input string) (*BackupStorageAccessTier, error) { + vals := map[string]BackupStorageAccessTier{ + "archive": BackupStorageAccessTierArchive, + "hot": BackupStorageAccessTierHot, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageAccessTier(input) + return &out, nil +} + +type BackupStorageRedundancy string + +const ( + BackupStorageRedundancyGeo BackupStorageRedundancy = "Geo" + BackupStorageRedundancyGeoZone BackupStorageRedundancy = "GeoZone" + BackupStorageRedundancyLocal BackupStorageRedundancy = "Local" + BackupStorageRedundancyZone BackupStorageRedundancy = "Zone" +) + +func PossibleValuesForBackupStorageRedundancy() []string { + return []string{ + string(BackupStorageRedundancyGeo), + string(BackupStorageRedundancyGeoZone), + string(BackupStorageRedundancyLocal), + string(BackupStorageRedundancyZone), + } +} + +func (s *BackupStorageRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageRedundancy(input string) (*BackupStorageRedundancy, error) { + vals := map[string]BackupStorageRedundancy{ + "geo": BackupStorageRedundancyGeo, + "geozone": BackupStorageRedundancyGeoZone, + "local": BackupStorageRedundancyLocal, + "zone": BackupStorageRedundancyZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageRedundancy(input) + return &out, nil +} + +type DatabaseState string + +const ( + DatabaseStateAll DatabaseState = "All" + DatabaseStateDeleted DatabaseState = "Deleted" + DatabaseStateLive DatabaseState = "Live" +) + +func PossibleValuesForDatabaseState() []string { + return []string{ + string(DatabaseStateAll), + string(DatabaseStateDeleted), + string(DatabaseStateLive), + } +} + +func (s *DatabaseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseState(input string) (*DatabaseState, error) { + vals := map[string]DatabaseState{ + "all": DatabaseStateAll, + "deleted": DatabaseStateDeleted, + "live": DatabaseStateLive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_location.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_location.go new file mode 100644 index 00000000000..4fd71456ca5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_location.go @@ -0,0 +1,121 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_location_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_location_test.go new file mode 100644 index 00000000000..d3c76fb8bc4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_location_test.go @@ -0,0 +1,237 @@ +package longtermretentionbackups + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver.go new file mode 100644 index 00000000000..14adde9cbad --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver.go @@ -0,0 +1,139 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationLongTermRetentionServerId{}) +} + +var _ resourceids.ResourceId = &LocationLongTermRetentionServerId{} + +// LocationLongTermRetentionServerId is a struct representing the Resource ID for a Location Long Term Retention Server +type LocationLongTermRetentionServerId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + LongTermRetentionServerName string +} + +// NewLocationLongTermRetentionServerID returns a new LocationLongTermRetentionServerId struct +func NewLocationLongTermRetentionServerID(subscriptionId string, resourceGroupName string, locationName string, longTermRetentionServerName string) LocationLongTermRetentionServerId { + return LocationLongTermRetentionServerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + LongTermRetentionServerName: longTermRetentionServerName, + } +} + +// ParseLocationLongTermRetentionServerID parses 'input' into a LocationLongTermRetentionServerId +func ParseLocationLongTermRetentionServerID(input string) (*LocationLongTermRetentionServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationLongTermRetentionServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationLongTermRetentionServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationLongTermRetentionServerIDInsensitively parses 'input' case-insensitively into a LocationLongTermRetentionServerId +// note: this method should only be used for API response data and not user input +func ParseLocationLongTermRetentionServerIDInsensitively(input string) (*LocationLongTermRetentionServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationLongTermRetentionServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationLongTermRetentionServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationLongTermRetentionServerId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionServerName, ok = input.Parsed["longTermRetentionServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionServerName", input) + } + + return nil +} + +// ValidateLocationLongTermRetentionServerID checks that 'input' can be parsed as a Location Long Term Retention Server ID +func ValidateLocationLongTermRetentionServerID(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 := ParseLocationLongTermRetentionServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location Long Term Retention Server ID +func (id LocationLongTermRetentionServerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionServers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.LongTermRetentionServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location Long Term Retention Server ID +func (id LocationLongTermRetentionServerId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerName"), + } +} + +// String returns a human-readable description of this Location Long Term Retention Server ID +func (id LocationLongTermRetentionServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Server Name: %q", id.LongTermRetentionServerName), + } + return fmt.Sprintf("Location Long Term Retention Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver_test.go new file mode 100644 index 00000000000..40feb99a65c --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserver_test.go @@ -0,0 +1,327 @@ +package longtermretentionbackups + +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 = &LocationLongTermRetentionServerId{} + +func TestNewLocationLongTermRetentionServerID(t *testing.T) { + id := NewLocationLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerName") + } +} + +func TestFormatLocationLongTermRetentionServerID(t *testing.T) { + actual := NewLocationLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationLongTermRetentionServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationLongTermRetentionServerId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Expected: &LocationLongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationLongTermRetentionServerID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + } +} + +func TestParseLocationLongTermRetentionServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationLongTermRetentionServerId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Expected: &LocationLongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe", + Expected: &LocationLongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErNaMe", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationLongTermRetentionServerIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + } +} + +func TestSegmentsForLocationLongTermRetentionServerId(t *testing.T) { + segments := LocationLongTermRetentionServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationLongTermRetentionServerId 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/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go new file mode 100644 index 00000000000..3203a975dba --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go @@ -0,0 +1,148 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationLongTermRetentionServerLongTermRetentionDatabaseId{}) +} + +var _ resourceids.ResourceId = &LocationLongTermRetentionServerLongTermRetentionDatabaseId{} + +// LocationLongTermRetentionServerLongTermRetentionDatabaseId is a struct representing the Resource ID for a Location Long Term Retention Server Long Term Retention Database +type LocationLongTermRetentionServerLongTermRetentionDatabaseId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + LongTermRetentionServerName string + LongTermRetentionDatabaseName string +} + +// NewLocationLongTermRetentionServerLongTermRetentionDatabaseID returns a new LocationLongTermRetentionServerLongTermRetentionDatabaseId struct +func NewLocationLongTermRetentionServerLongTermRetentionDatabaseID(subscriptionId string, resourceGroupName string, locationName string, longTermRetentionServerName string, longTermRetentionDatabaseName string) LocationLongTermRetentionServerLongTermRetentionDatabaseId { + return LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + LongTermRetentionServerName: longTermRetentionServerName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + } +} + +// ParseLocationLongTermRetentionServerLongTermRetentionDatabaseID parses 'input' into a LocationLongTermRetentionServerLongTermRetentionDatabaseId +func ParseLocationLongTermRetentionServerLongTermRetentionDatabaseID(input string) (*LocationLongTermRetentionServerLongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationLongTermRetentionServerLongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationLongTermRetentionServerLongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively parses 'input' case-insensitively into a LocationLongTermRetentionServerLongTermRetentionDatabaseId +// note: this method should only be used for API response data and not user input +func ParseLocationLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively(input string) (*LocationLongTermRetentionServerLongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationLongTermRetentionServerLongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationLongTermRetentionServerLongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationLongTermRetentionServerLongTermRetentionDatabaseId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionServerName, ok = input.Parsed["longTermRetentionServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionServerName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + return nil +} + +// ValidateLocationLongTermRetentionServerLongTermRetentionDatabaseID checks that 'input' can be parsed as a Location Long Term Retention Server Long Term Retention Database ID +func ValidateLocationLongTermRetentionServerLongTermRetentionDatabaseID(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 := ParseLocationLongTermRetentionServerLongTermRetentionDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location Long Term Retention Server Long Term Retention Database ID +func (id LocationLongTermRetentionServerLongTermRetentionDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionServers/%s/longTermRetentionDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.LongTermRetentionServerName, id.LongTermRetentionDatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location Long Term Retention Server Long Term Retention Database ID +func (id LocationLongTermRetentionServerLongTermRetentionDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + } +} + +// String returns a human-readable description of this Location Long Term Retention Server Long Term Retention Database ID +func (id LocationLongTermRetentionServerLongTermRetentionDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Server Name: %q", id.LongTermRetentionServerName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + } + return fmt.Sprintf("Location Long Term Retention Server Long Term Retention Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go new file mode 100644 index 00000000000..5065c17ff0e --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go @@ -0,0 +1,372 @@ +package longtermretentionbackups + +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 = &LocationLongTermRetentionServerLongTermRetentionDatabaseId{} + +func TestNewLocationLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + id := NewLocationLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } +} + +func TestFormatLocationLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLocationLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationLongTermRetentionServerLongTermRetentionDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationLongTermRetentionServerLongTermRetentionDatabaseID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestParseLocationLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationLongTermRetentionServerLongTermRetentionDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Expected: &LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErNaMe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestSegmentsForLocationLongTermRetentionServerLongTermRetentionDatabaseId(t *testing.T) { + segments := LocationLongTermRetentionServerLongTermRetentionDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationLongTermRetentionServerLongTermRetentionDatabaseId 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/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup.go new file mode 100644 index 00000000000..1864404b59e --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup.go @@ -0,0 +1,148 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionBackupId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionBackupId{} + +// LongTermRetentionBackupId is a struct representing the Resource ID for a Long Term Retention Backup +type LongTermRetentionBackupId struct { + SubscriptionId string + LocationName string + LongTermRetentionServerName string + LongTermRetentionDatabaseName string + LongTermRetentionBackupName string +} + +// NewLongTermRetentionBackupID returns a new LongTermRetentionBackupId struct +func NewLongTermRetentionBackupID(subscriptionId string, locationName string, longTermRetentionServerName string, longTermRetentionDatabaseName string, longTermRetentionBackupName string) LongTermRetentionBackupId { + return LongTermRetentionBackupId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + LongTermRetentionServerName: longTermRetentionServerName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + LongTermRetentionBackupName: longTermRetentionBackupName, + } +} + +// ParseLongTermRetentionBackupID parses 'input' into a LongTermRetentionBackupId +func ParseLongTermRetentionBackupID(input string) (*LongTermRetentionBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionBackupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionBackupIDInsensitively parses 'input' case-insensitively into a LongTermRetentionBackupId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionBackupIDInsensitively(input string) (*LongTermRetentionBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionBackupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionBackupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionServerName, ok = input.Parsed["longTermRetentionServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionServerName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + if id.LongTermRetentionBackupName, ok = input.Parsed["longTermRetentionBackupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionBackupName", input) + } + + return nil +} + +// ValidateLongTermRetentionBackupID checks that 'input' can be parsed as a Long Term Retention Backup ID +func ValidateLongTermRetentionBackupID(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 := ParseLongTermRetentionBackupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Backup ID +func (id LongTermRetentionBackupId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionServers/%s/longTermRetentionDatabases/%s/longTermRetentionBackups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.LongTermRetentionServerName, id.LongTermRetentionDatabaseName, id.LongTermRetentionBackupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Backup ID +func (id LongTermRetentionBackupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + resourceids.StaticSegment("staticLongTermRetentionBackups", "longTermRetentionBackups", "longTermRetentionBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionBackupName", "longTermRetentionBackupName"), + } +} + +// String returns a human-readable description of this Long Term Retention Backup ID +func (id LongTermRetentionBackupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Server Name: %q", id.LongTermRetentionServerName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + fmt.Sprintf("Long Term Retention Backup Name: %q", id.LongTermRetentionBackupName), + } + return fmt.Sprintf("Long Term Retention Backup (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup_test.go new file mode 100644 index 00000000000..a3271e85484 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionbackup_test.go @@ -0,0 +1,372 @@ +package longtermretentionbackups + +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 = &LongTermRetentionBackupId{} + +func TestNewLongTermRetentionBackupID(t *testing.T) { + id := NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } + + if id.LongTermRetentionBackupName != "longTermRetentionBackupName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionBackupName'", id.LongTermRetentionBackupName, "longTermRetentionBackupName") + } +} + +func TestFormatLongTermRetentionBackupID(t *testing.T) { + actual := NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionBackupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionBackupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName", + Expected: &LongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionBackupName: "longTermRetentionBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionBackupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionBackupName != v.Expected.LongTermRetentionBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionBackupName", v.Expected.LongTermRetentionBackupName, actual.LongTermRetentionBackupName) + } + + } +} + +func TestParseLongTermRetentionBackupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionBackupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnBaCkUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName", + Expected: &LongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionBackupName: "longTermRetentionBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpNaMe", + Expected: &LongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErNaMe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + LongTermRetentionBackupName: "lOnGtErMrEtEnTiOnBaCkUpNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionBackupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionBackupName != v.Expected.LongTermRetentionBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionBackupName", v.Expected.LongTermRetentionBackupName, actual.LongTermRetentionBackupName) + } + + } +} + +func TestSegmentsForLongTermRetentionBackupId(t *testing.T) { + segments := LongTermRetentionBackupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionBackupId 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/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go new file mode 100644 index 00000000000..f8410275897 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go @@ -0,0 +1,157 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionDatabaseLongTermRetentionBackupId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionDatabaseLongTermRetentionBackupId{} + +// LongTermRetentionDatabaseLongTermRetentionBackupId is a struct representing the Resource ID for a Long Term Retention Database Long Term Retention Backup +type LongTermRetentionDatabaseLongTermRetentionBackupId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + LongTermRetentionServerName string + LongTermRetentionDatabaseName string + LongTermRetentionBackupName string +} + +// NewLongTermRetentionDatabaseLongTermRetentionBackupID returns a new LongTermRetentionDatabaseLongTermRetentionBackupId struct +func NewLongTermRetentionDatabaseLongTermRetentionBackupID(subscriptionId string, resourceGroupName string, locationName string, longTermRetentionServerName string, longTermRetentionDatabaseName string, longTermRetentionBackupName string) LongTermRetentionDatabaseLongTermRetentionBackupId { + return LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + LongTermRetentionServerName: longTermRetentionServerName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + LongTermRetentionBackupName: longTermRetentionBackupName, + } +} + +// ParseLongTermRetentionDatabaseLongTermRetentionBackupID parses 'input' into a LongTermRetentionDatabaseLongTermRetentionBackupId +func ParseLongTermRetentionDatabaseLongTermRetentionBackupID(input string) (*LongTermRetentionDatabaseLongTermRetentionBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionDatabaseLongTermRetentionBackupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionDatabaseLongTermRetentionBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionDatabaseLongTermRetentionBackupIDInsensitively parses 'input' case-insensitively into a LongTermRetentionDatabaseLongTermRetentionBackupId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionDatabaseLongTermRetentionBackupIDInsensitively(input string) (*LongTermRetentionDatabaseLongTermRetentionBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionDatabaseLongTermRetentionBackupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionDatabaseLongTermRetentionBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionDatabaseLongTermRetentionBackupId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionServerName, ok = input.Parsed["longTermRetentionServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionServerName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + if id.LongTermRetentionBackupName, ok = input.Parsed["longTermRetentionBackupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionBackupName", input) + } + + return nil +} + +// ValidateLongTermRetentionDatabaseLongTermRetentionBackupID checks that 'input' can be parsed as a Long Term Retention Database Long Term Retention Backup ID +func ValidateLongTermRetentionDatabaseLongTermRetentionBackupID(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 := ParseLongTermRetentionDatabaseLongTermRetentionBackupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Database Long Term Retention Backup ID +func (id LongTermRetentionDatabaseLongTermRetentionBackupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionServers/%s/longTermRetentionDatabases/%s/longTermRetentionBackups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.LongTermRetentionServerName, id.LongTermRetentionDatabaseName, id.LongTermRetentionBackupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Database Long Term Retention Backup ID +func (id LongTermRetentionDatabaseLongTermRetentionBackupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + resourceids.StaticSegment("staticLongTermRetentionBackups", "longTermRetentionBackups", "longTermRetentionBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionBackupName", "longTermRetentionBackupName"), + } +} + +// String returns a human-readable description of this Long Term Retention Database Long Term Retention Backup ID +func (id LongTermRetentionDatabaseLongTermRetentionBackupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Server Name: %q", id.LongTermRetentionServerName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + fmt.Sprintf("Long Term Retention Backup Name: %q", id.LongTermRetentionBackupName), + } + return fmt.Sprintf("Long Term Retention Database Long Term Retention Backup (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go new file mode 100644 index 00000000000..1966b8ffb88 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go @@ -0,0 +1,417 @@ +package longtermretentionbackups + +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 = &LongTermRetentionDatabaseLongTermRetentionBackupId{} + +func TestNewLongTermRetentionDatabaseLongTermRetentionBackupID(t *testing.T) { + id := NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } + + if id.LongTermRetentionBackupName != "longTermRetentionBackupName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionBackupName'", id.LongTermRetentionBackupName, "longTermRetentionBackupName") + } +} + +func TestFormatLongTermRetentionDatabaseLongTermRetentionBackupID(t *testing.T) { + actual := NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName", "longTermRetentionBackupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionDatabaseLongTermRetentionBackupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionDatabaseLongTermRetentionBackupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName", + Expected: &LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionBackupName: "longTermRetentionBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionDatabaseLongTermRetentionBackupID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionBackupName != v.Expected.LongTermRetentionBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionBackupName", v.Expected.LongTermRetentionBackupName, actual.LongTermRetentionBackupName) + } + + } +} + +func TestParseLongTermRetentionDatabaseLongTermRetentionBackupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionDatabaseLongTermRetentionBackupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnBaCkUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName", + Expected: &LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionBackupName: "longTermRetentionBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionBackups/longTermRetentionBackupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpNaMe", + Expected: &LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErNaMe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + LongTermRetentionBackupName: "lOnGtErMrEtEnTiOnBaCkUpNaMe", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionDatabaseLongTermRetentionBackupIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionBackupName != v.Expected.LongTermRetentionBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionBackupName", v.Expected.LongTermRetentionBackupName, actual.LongTermRetentionBackupName) + } + + } +} + +func TestSegmentsForLongTermRetentionDatabaseLongTermRetentionBackupId(t *testing.T) { + segments := LongTermRetentionDatabaseLongTermRetentionBackupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionDatabaseLongTermRetentionBackupId 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/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver.go new file mode 100644 index 00000000000..930d8e1fabc --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver.go @@ -0,0 +1,130 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionServerId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionServerId{} + +// LongTermRetentionServerId is a struct representing the Resource ID for a Long Term Retention Server +type LongTermRetentionServerId struct { + SubscriptionId string + LocationName string + LongTermRetentionServerName string +} + +// NewLongTermRetentionServerID returns a new LongTermRetentionServerId struct +func NewLongTermRetentionServerID(subscriptionId string, locationName string, longTermRetentionServerName string) LongTermRetentionServerId { + return LongTermRetentionServerId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + LongTermRetentionServerName: longTermRetentionServerName, + } +} + +// ParseLongTermRetentionServerID parses 'input' into a LongTermRetentionServerId +func ParseLongTermRetentionServerID(input string) (*LongTermRetentionServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionServerIDInsensitively parses 'input' case-insensitively into a LongTermRetentionServerId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionServerIDInsensitively(input string) (*LongTermRetentionServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionServerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionServerName, ok = input.Parsed["longTermRetentionServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionServerName", input) + } + + return nil +} + +// ValidateLongTermRetentionServerID checks that 'input' can be parsed as a Long Term Retention Server ID +func ValidateLongTermRetentionServerID(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 := ParseLongTermRetentionServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Server ID +func (id LongTermRetentionServerId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionServers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.LongTermRetentionServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Server ID +func (id LongTermRetentionServerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerName"), + } +} + +// String returns a human-readable description of this Long Term Retention Server ID +func (id LongTermRetentionServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Server Name: %q", id.LongTermRetentionServerName), + } + return fmt.Sprintf("Long Term Retention Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver_test.go new file mode 100644 index 00000000000..603e1432621 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserver_test.go @@ -0,0 +1,282 @@ +package longtermretentionbackups + +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 = &LongTermRetentionServerId{} + +func TestNewLongTermRetentionServerID(t *testing.T) { + id := NewLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerName") + } +} + +func TestFormatLongTermRetentionServerID(t *testing.T) { + actual := NewLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Expected: &LongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionServerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + } +} + +func TestParseLongTermRetentionServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Expected: &LongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe", + Expected: &LongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionServerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + } +} + +func TestSegmentsForLongTermRetentionServerId(t *testing.T) { + segments := LongTermRetentionServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionServerId 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/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go new file mode 100644 index 00000000000..df66c5b2d5d --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go @@ -0,0 +1,139 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionServerLongTermRetentionDatabaseId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionServerLongTermRetentionDatabaseId{} + +// LongTermRetentionServerLongTermRetentionDatabaseId is a struct representing the Resource ID for a Long Term Retention Server Long Term Retention Database +type LongTermRetentionServerLongTermRetentionDatabaseId struct { + SubscriptionId string + LocationName string + LongTermRetentionServerName string + LongTermRetentionDatabaseName string +} + +// NewLongTermRetentionServerLongTermRetentionDatabaseID returns a new LongTermRetentionServerLongTermRetentionDatabaseId struct +func NewLongTermRetentionServerLongTermRetentionDatabaseID(subscriptionId string, locationName string, longTermRetentionServerName string, longTermRetentionDatabaseName string) LongTermRetentionServerLongTermRetentionDatabaseId { + return LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + LongTermRetentionServerName: longTermRetentionServerName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + } +} + +// ParseLongTermRetentionServerLongTermRetentionDatabaseID parses 'input' into a LongTermRetentionServerLongTermRetentionDatabaseId +func ParseLongTermRetentionServerLongTermRetentionDatabaseID(input string) (*LongTermRetentionServerLongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionServerLongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionServerLongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively parses 'input' case-insensitively into a LongTermRetentionServerLongTermRetentionDatabaseId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively(input string) (*LongTermRetentionServerLongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionServerLongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionServerLongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionServerLongTermRetentionDatabaseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionServerName, ok = input.Parsed["longTermRetentionServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionServerName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + return nil +} + +// ValidateLongTermRetentionServerLongTermRetentionDatabaseID checks that 'input' can be parsed as a Long Term Retention Server Long Term Retention Database ID +func ValidateLongTermRetentionServerLongTermRetentionDatabaseID(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 := ParseLongTermRetentionServerLongTermRetentionDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Server Long Term Retention Database ID +func (id LongTermRetentionServerLongTermRetentionDatabaseId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionServers/%s/longTermRetentionDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.LongTermRetentionServerName, id.LongTermRetentionDatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Server Long Term Retention Database ID +func (id LongTermRetentionServerLongTermRetentionDatabaseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + } +} + +// String returns a human-readable description of this Long Term Retention Server Long Term Retention Database ID +func (id LongTermRetentionServerLongTermRetentionDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Server Name: %q", id.LongTermRetentionServerName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + } + return fmt.Sprintf("Long Term Retention Server Long Term Retention Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go new file mode 100644 index 00000000000..a9c2f2d2286 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go @@ -0,0 +1,327 @@ +package longtermretentionbackups + +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 = &LongTermRetentionServerLongTermRetentionDatabaseId{} + +func TestNewLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + id := NewLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } +} + +func TestFormatLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionServerName", "longTermRetentionDatabaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionServerLongTermRetentionDatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionServerLongTermRetentionDatabaseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestParseLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionServerLongTermRetentionDatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionServerName: "longTermRetentionServerName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionServers/longTermRetentionServerName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Expected: &LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErNaMe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErNaMe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionServerLongTermRetentionDatabaseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionServerName != v.Expected.LongTermRetentionServerName { + t.Fatalf("Expected %q but got %q for LongTermRetentionServerName", v.Expected.LongTermRetentionServerName, actual.LongTermRetentionServerName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestSegmentsForLongTermRetentionServerLongTermRetentionDatabaseId(t *testing.T) { + segments := LongTermRetentionServerLongTermRetentionDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionServerLongTermRetentionDatabaseId 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/sql/2023-08-01/longtermretentionbackups/id_providerlocation.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation.go new file mode 100644 index 00000000000..de6c17d1b81 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation.go @@ -0,0 +1,130 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation_test.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation_test.go new file mode 100644 index 00000000000..c162576c656 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package longtermretentionbackups + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/sql/2023-08-01/longtermretentionbackups/method_changeaccesstier.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstier.go new file mode 100644 index 00000000000..a0ce37ae815 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstier.go @@ -0,0 +1,75 @@ +package longtermretentionbackups + +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 ChangeAccessTierOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionBackup +} + +// ChangeAccessTier ... +func (c LongTermRetentionBackupsClient) ChangeAccessTier(ctx context.Context, id LongTermRetentionBackupId, input ChangeLongTermRetentionBackupAccessTierParameters) (result ChangeAccessTierOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/changeAccessTier", 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 +} + +// ChangeAccessTierThenPoll performs ChangeAccessTier then polls until it's completed +func (c LongTermRetentionBackupsClient) ChangeAccessTierThenPoll(ctx context.Context, id LongTermRetentionBackupId, input ChangeLongTermRetentionBackupAccessTierParameters) error { + result, err := c.ChangeAccessTier(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ChangeAccessTier: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ChangeAccessTier: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go new file mode 100644 index 00000000000..7e14e8b1638 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go @@ -0,0 +1,75 @@ +package longtermretentionbackups + +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 ChangeAccessTierByResourceGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionBackup +} + +// ChangeAccessTierByResourceGroup ... +func (c LongTermRetentionBackupsClient) ChangeAccessTierByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId, input ChangeLongTermRetentionBackupAccessTierParameters) (result ChangeAccessTierByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/changeAccessTier", 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 +} + +// ChangeAccessTierByResourceGroupThenPoll performs ChangeAccessTierByResourceGroup then polls until it's completed +func (c LongTermRetentionBackupsClient) ChangeAccessTierByResourceGroupThenPoll(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId, input ChangeLongTermRetentionBackupAccessTierParameters) error { + result, err := c.ChangeAccessTierByResourceGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ChangeAccessTierByResourceGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ChangeAccessTierByResourceGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_copy.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_copy.go new file mode 100644 index 00000000000..79c174368d3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_copy.go @@ -0,0 +1,75 @@ +package longtermretentionbackups + +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 CopyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionBackupOperationResult +} + +// Copy ... +func (c LongTermRetentionBackupsClient) Copy(ctx context.Context, id LongTermRetentionBackupId, input CopyLongTermRetentionBackupParameters) (result CopyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/copy", 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 +} + +// CopyThenPoll performs Copy then polls until it's completed +func (c LongTermRetentionBackupsClient) CopyThenPoll(ctx context.Context, id LongTermRetentionBackupId, input CopyLongTermRetentionBackupParameters) error { + result, err := c.Copy(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Copy: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Copy: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_copybyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_copybyresourcegroup.go new file mode 100644 index 00000000000..21f5263a074 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_copybyresourcegroup.go @@ -0,0 +1,75 @@ +package longtermretentionbackups + +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 CopyByResourceGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionBackupOperationResult +} + +// CopyByResourceGroup ... +func (c LongTermRetentionBackupsClient) CopyByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId, input CopyLongTermRetentionBackupParameters) (result CopyByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/copy", 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 +} + +// CopyByResourceGroupThenPoll performs CopyByResourceGroup then polls until it's completed +func (c LongTermRetentionBackupsClient) CopyByResourceGroupThenPoll(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId, input CopyLongTermRetentionBackupParameters) error { + result, err := c.CopyByResourceGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CopyByResourceGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CopyByResourceGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_delete.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_delete.go new file mode 100644 index 00000000000..f4617e3252a --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_delete.go @@ -0,0 +1,70 @@ +package longtermretentionbackups + +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 LongTermRetentionBackupsClient) Delete(ctx context.Context, id LongTermRetentionBackupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 LongTermRetentionBackupsClient) DeleteThenPoll(ctx context.Context, id LongTermRetentionBackupId) 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/sql/2023-08-01/longtermretentionbackups/method_deletebyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_deletebyresourcegroup.go new file mode 100644 index 00000000000..1eae3a0c604 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_deletebyresourcegroup.go @@ -0,0 +1,70 @@ +package longtermretentionbackups + +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 DeleteByResourceGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteByResourceGroup ... +func (c LongTermRetentionBackupsClient) DeleteByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId) (result DeleteByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 +} + +// DeleteByResourceGroupThenPoll performs DeleteByResourceGroup then polls until it's completed +func (c LongTermRetentionBackupsClient) DeleteByResourceGroupThenPoll(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId) error { + result, err := c.DeleteByResourceGroup(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteByResourceGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteByResourceGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_get.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_get.go new file mode 100644 index 00000000000..280c8df487d --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_get.go @@ -0,0 +1,53 @@ +package longtermretentionbackups + +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 *LongTermRetentionBackup +} + +// Get ... +func (c LongTermRetentionBackupsClient) Get(ctx context.Context, id LongTermRetentionBackupId) (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 LongTermRetentionBackup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_getbyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_getbyresourcegroup.go new file mode 100644 index 00000000000..22cd05eceda --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_getbyresourcegroup.go @@ -0,0 +1,53 @@ +package longtermretentionbackups + +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 GetByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionBackup +} + +// GetByResourceGroup ... +func (c LongTermRetentionBackupsClient) GetByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId) (result GetByResourceGroupOperationResponse, 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 LongTermRetentionBackup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbydatabase.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbydatabase.go new file mode 100644 index 00000000000..7405e8c77cb --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbydatabase.go @@ -0,0 +1,138 @@ +package longtermretentionbackups + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionBackup +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionBackup +} + +type ListByDatabaseOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c LongTermRetentionBackupsClient) ListByDatabase(ctx context.Context, id LongTermRetentionServerLongTermRetentionDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionBackups", 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 *[]LongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c LongTermRetentionBackupsClient) ListByDatabaseComplete(ctx context.Context, id LongTermRetentionServerLongTermRetentionDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, LongTermRetentionBackupOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionBackupsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id LongTermRetentionServerLongTermRetentionDatabaseId, options ListByDatabaseOperationOptions, predicate LongTermRetentionBackupOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]LongTermRetentionBackup, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbylocation.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbylocation.go new file mode 100644 index 00000000000..31449bbc121 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbylocation.go @@ -0,0 +1,138 @@ +package longtermretentionbackups + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionBackup +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionBackup +} + +type ListByLocationOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByLocationOperationOptions() ListByLocationOperationOptions { + return ListByLocationOperationOptions{} +} + +func (o ListByLocationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByLocationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByLocationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c LongTermRetentionBackupsClient) ListByLocation(ctx context.Context, id LocationId, options ListByLocationOperationOptions) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionBackups", 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 *[]LongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c LongTermRetentionBackupsClient) ListByLocationComplete(ctx context.Context, id LocationId, options ListByLocationOperationOptions) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, options, LongTermRetentionBackupOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionBackupsClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, options ListByLocationOperationOptions, predicate LongTermRetentionBackupOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]LongTermRetentionBackup, 0) + + resp, err := c.ListByLocation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupdatabase.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupdatabase.go new file mode 100644 index 00000000000..7daf1b2ca94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupdatabase.go @@ -0,0 +1,138 @@ +package longtermretentionbackups + +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 ListByResourceGroupDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionBackup +} + +type ListByResourceGroupDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionBackup +} + +type ListByResourceGroupDatabaseOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByResourceGroupDatabaseOperationOptions() ListByResourceGroupDatabaseOperationOptions { + return ListByResourceGroupDatabaseOperationOptions{} +} + +func (o ListByResourceGroupDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByResourceGroupDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroupDatabase ... +func (c LongTermRetentionBackupsClient) ListByResourceGroupDatabase(ctx context.Context, id LocationLongTermRetentionServerLongTermRetentionDatabaseId, options ListByResourceGroupDatabaseOperationOptions) (result ListByResourceGroupDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionBackups", 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 *[]LongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupDatabaseComplete retrieves all the results into a single object +func (c LongTermRetentionBackupsClient) ListByResourceGroupDatabaseComplete(ctx context.Context, id LocationLongTermRetentionServerLongTermRetentionDatabaseId, options ListByResourceGroupDatabaseOperationOptions) (ListByResourceGroupDatabaseCompleteResult, error) { + return c.ListByResourceGroupDatabaseCompleteMatchingPredicate(ctx, id, options, LongTermRetentionBackupOperationPredicate{}) +} + +// ListByResourceGroupDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionBackupsClient) ListByResourceGroupDatabaseCompleteMatchingPredicate(ctx context.Context, id LocationLongTermRetentionServerLongTermRetentionDatabaseId, options ListByResourceGroupDatabaseOperationOptions, predicate LongTermRetentionBackupOperationPredicate) (result ListByResourceGroupDatabaseCompleteResult, err error) { + items := make([]LongTermRetentionBackup, 0) + + resp, err := c.ListByResourceGroupDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegrouplocation.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegrouplocation.go new file mode 100644 index 00000000000..576995f4a18 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegrouplocation.go @@ -0,0 +1,138 @@ +package longtermretentionbackups + +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 ListByResourceGroupLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionBackup +} + +type ListByResourceGroupLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionBackup +} + +type ListByResourceGroupLocationOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByResourceGroupLocationOperationOptions() ListByResourceGroupLocationOperationOptions { + return ListByResourceGroupLocationOperationOptions{} +} + +func (o ListByResourceGroupLocationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupLocationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupLocationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByResourceGroupLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroupLocation ... +func (c LongTermRetentionBackupsClient) ListByResourceGroupLocation(ctx context.Context, id ProviderLocationId, options ListByResourceGroupLocationOperationOptions) (result ListByResourceGroupLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupLocationCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionBackups", 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 *[]LongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupLocationComplete retrieves all the results into a single object +func (c LongTermRetentionBackupsClient) ListByResourceGroupLocationComplete(ctx context.Context, id ProviderLocationId, options ListByResourceGroupLocationOperationOptions) (ListByResourceGroupLocationCompleteResult, error) { + return c.ListByResourceGroupLocationCompleteMatchingPredicate(ctx, id, options, LongTermRetentionBackupOperationPredicate{}) +} + +// ListByResourceGroupLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionBackupsClient) ListByResourceGroupLocationCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, options ListByResourceGroupLocationOperationOptions, predicate LongTermRetentionBackupOperationPredicate) (result ListByResourceGroupLocationCompleteResult, err error) { + items := make([]LongTermRetentionBackup, 0) + + resp, err := c.ListByResourceGroupLocation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupserver.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupserver.go new file mode 100644 index 00000000000..26fc8480b23 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyresourcegroupserver.go @@ -0,0 +1,138 @@ +package longtermretentionbackups + +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 ListByResourceGroupServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionBackup +} + +type ListByResourceGroupServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionBackup +} + +type ListByResourceGroupServerOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByResourceGroupServerOperationOptions() ListByResourceGroupServerOperationOptions { + return ListByResourceGroupServerOperationOptions{} +} + +func (o ListByResourceGroupServerOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupServerOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupServerOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByResourceGroupServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroupServer ... +func (c LongTermRetentionBackupsClient) ListByResourceGroupServer(ctx context.Context, id LocationLongTermRetentionServerId, options ListByResourceGroupServerOperationOptions) (result ListByResourceGroupServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupServerCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionBackups", 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 *[]LongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupServerComplete retrieves all the results into a single object +func (c LongTermRetentionBackupsClient) ListByResourceGroupServerComplete(ctx context.Context, id LocationLongTermRetentionServerId, options ListByResourceGroupServerOperationOptions) (ListByResourceGroupServerCompleteResult, error) { + return c.ListByResourceGroupServerCompleteMatchingPredicate(ctx, id, options, LongTermRetentionBackupOperationPredicate{}) +} + +// ListByResourceGroupServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionBackupsClient) ListByResourceGroupServerCompleteMatchingPredicate(ctx context.Context, id LocationLongTermRetentionServerId, options ListByResourceGroupServerOperationOptions, predicate LongTermRetentionBackupOperationPredicate) (result ListByResourceGroupServerCompleteResult, err error) { + items := make([]LongTermRetentionBackup, 0) + + resp, err := c.ListByResourceGroupServer(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyserver.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyserver.go new file mode 100644 index 00000000000..cbc1d3dea3e --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_listbyserver.go @@ -0,0 +1,138 @@ +package longtermretentionbackups + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionBackup +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionBackup +} + +type ListByServerOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByServerOperationOptions() ListByServerOperationOptions { + return ListByServerOperationOptions{} +} + +func (o ListByServerOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServerOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByServerOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c LongTermRetentionBackupsClient) ListByServer(ctx context.Context, id LongTermRetentionServerId, options ListByServerOperationOptions) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionBackups", 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 *[]LongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c LongTermRetentionBackupsClient) ListByServerComplete(ctx context.Context, id LongTermRetentionServerId, options ListByServerOperationOptions) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, options, LongTermRetentionBackupOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionBackupsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id LongTermRetentionServerId, options ListByServerOperationOptions, predicate LongTermRetentionBackupOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]LongTermRetentionBackup, 0) + + resp, err := c.ListByServer(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/method_update.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_update.go new file mode 100644 index 00000000000..e2ea48349b3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_update.go @@ -0,0 +1,75 @@ +package longtermretentionbackups + +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 *LongTermRetentionBackupOperationResult +} + +// Update ... +func (c LongTermRetentionBackupsClient) Update(ctx context.Context, id LongTermRetentionBackupId, input UpdateLongTermRetentionBackupParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/update", 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 LongTermRetentionBackupsClient) UpdateThenPoll(ctx context.Context, id LongTermRetentionBackupId, input UpdateLongTermRetentionBackupParameters) 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/sql/2023-08-01/longtermretentionbackups/method_updatebyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_updatebyresourcegroup.go new file mode 100644 index 00000000000..8e2e8570cea --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/method_updatebyresourcegroup.go @@ -0,0 +1,75 @@ +package longtermretentionbackups + +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 UpdateByResourceGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionBackupOperationResult +} + +// UpdateByResourceGroup ... +func (c LongTermRetentionBackupsClient) UpdateByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId, input UpdateLongTermRetentionBackupParameters) (result UpdateByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/update", 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 +} + +// UpdateByResourceGroupThenPoll performs UpdateByResourceGroup then polls until it's completed +func (c LongTermRetentionBackupsClient) UpdateByResourceGroupThenPoll(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionBackupId, input UpdateLongTermRetentionBackupParameters) error { + result, err := c.UpdateByResourceGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing UpdateByResourceGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpdateByResourceGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go new file mode 100644 index 00000000000..9f2dec33eb9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go @@ -0,0 +1,9 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ChangeLongTermRetentionBackupAccessTierParameters struct { + BackupStorageAccessTier string `json:"backupStorageAccessTier"` + OperationMode string `json:"operationMode"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparameters.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparameters.go new file mode 100644 index 00000000000..f0f21520e6e --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparameters.go @@ -0,0 +1,8 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyLongTermRetentionBackupParameters struct { + Properties *CopyLongTermRetentionBackupParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go new file mode 100644 index 00000000000..b268a2e99af --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go @@ -0,0 +1,13 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CopyLongTermRetentionBackupParametersProperties struct { + TargetBackupStorageRedundancy *BackupStorageRedundancy `json:"targetBackupStorageRedundancy,omitempty"` + TargetDatabaseName *string `json:"targetDatabaseName,omitempty"` + TargetResourceGroup *string `json:"targetResourceGroup,omitempty"` + TargetServerFullyQualifiedDomainName *string `json:"targetServerFullyQualifiedDomainName,omitempty"` + TargetServerResourceId *string `json:"targetServerResourceId,omitempty"` + TargetSubscriptionId *string `json:"targetSubscriptionId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackup.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackup.go new file mode 100644 index 00000000000..f3eb89aec4f --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackup.go @@ -0,0 +1,11 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LongTermRetentionBackup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LongTermRetentionBackupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupoperationresult.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupoperationresult.go new file mode 100644 index 00000000000..1397a0b2b36 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupoperationresult.go @@ -0,0 +1,11 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LongTermRetentionBackupOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LongTermRetentionOperationResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupproperties.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupproperties.go new file mode 100644 index 00000000000..d41b6be7c00 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionbackupproperties.go @@ -0,0 +1,71 @@ +package longtermretentionbackups + +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 LongTermRetentionBackupProperties struct { + BackupExpirationTime *string `json:"backupExpirationTime,omitempty"` + BackupStorageAccessTier *BackupStorageAccessTier `json:"backupStorageAccessTier,omitempty"` + BackupStorageRedundancy *BackupStorageRedundancy `json:"backupStorageRedundancy,omitempty"` + BackupTime *string `json:"backupTime,omitempty"` + DatabaseDeletionTime *string `json:"databaseDeletionTime,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + IsBackupImmutable *bool `json:"isBackupImmutable,omitempty"` + RequestedBackupStorageRedundancy *BackupStorageRedundancy `json:"requestedBackupStorageRedundancy,omitempty"` + ServerCreateTime *string `json:"serverCreateTime,omitempty"` + ServerName *string `json:"serverName,omitempty"` +} + +func (o *LongTermRetentionBackupProperties) GetBackupExpirationTimeAsTime() (*time.Time, error) { + if o.BackupExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BackupExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *LongTermRetentionBackupProperties) SetBackupExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BackupExpirationTime = &formatted +} + +func (o *LongTermRetentionBackupProperties) GetBackupTimeAsTime() (*time.Time, error) { + if o.BackupTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BackupTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *LongTermRetentionBackupProperties) SetBackupTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BackupTime = &formatted +} + +func (o *LongTermRetentionBackupProperties) GetDatabaseDeletionTimeAsTime() (*time.Time, error) { + if o.DatabaseDeletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DatabaseDeletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *LongTermRetentionBackupProperties) SetDatabaseDeletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DatabaseDeletionTime = &formatted +} + +func (o *LongTermRetentionBackupProperties) GetServerCreateTimeAsTime() (*time.Time, error) { + if o.ServerCreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ServerCreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *LongTermRetentionBackupProperties) SetServerCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ServerCreateTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionoperationresultproperties.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionoperationresultproperties.go new file mode 100644 index 00000000000..639effd6079 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_longtermretentionoperationresultproperties.go @@ -0,0 +1,14 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LongTermRetentionOperationResultProperties struct { + FromBackupResourceId *string `json:"fromBackupResourceId,omitempty"` + Message *string `json:"message,omitempty"` + OperationType *string `json:"operationType,omitempty"` + RequestId *string `json:"requestId,omitempty"` + Status *string `json:"status,omitempty"` + TargetBackupStorageRedundancy *BackupStorageRedundancy `json:"targetBackupStorageRedundancy,omitempty"` + ToBackupResourceId *string `json:"toBackupResourceId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go new file mode 100644 index 00000000000..61ab87d4f0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go @@ -0,0 +1,8 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateLongTermRetentionBackupParameters struct { + Properties *UpdateLongTermRetentionBackupParametersProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go new file mode 100644 index 00000000000..46862c0e3df --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go @@ -0,0 +1,8 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateLongTermRetentionBackupParametersProperties struct { + RequestedBackupStorageRedundancy *BackupStorageRedundancy `json:"requestedBackupStorageRedundancy,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionbackups/predicates.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/predicates.go new file mode 100644 index 00000000000..3f2817fce24 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/predicates.go @@ -0,0 +1,27 @@ +package longtermretentionbackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LongTermRetentionBackupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LongTermRetentionBackupOperationPredicate) Matches(input LongTermRetentionBackup) 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/sql/2023-08-01/longtermretentionbackups/version.go b/resource-manager/sql/2023-08-01/longtermretentionbackups/version.go new file mode 100644 index 00000000000..2098ed38acd --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionbackups/version.go @@ -0,0 +1,10 @@ +package longtermretentionbackups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/longtermretentionbackups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/README.md b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/README.md new file mode 100644 index 00000000000..e161568d819 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/README.md @@ -0,0 +1,178 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups` Documentation + +The `longtermretentionmanagedinstancebackups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups" +``` + + +### Client Initialization + +```go +client := longtermretentionmanagedinstancebackups.NewLongTermRetentionManagedInstanceBackupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.Delete` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.DeleteByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName") + +if err := client.DeleteByResourceGroupThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.Get` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName") + +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: `LongTermRetentionManagedInstanceBackupsClient.GetByResourceGroup` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName") + +read, err := client.GetByResourceGroup(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName") + +// alternatively `client.ListByDatabase(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.ListByInstance` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName") + +// alternatively `client.ListByInstance(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByInstanceOperationOptions())` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByInstanceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.ListByLocation` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.ListByLocation(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByLocationOperationOptions())` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByLocationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.ListByResourceGroupDatabase` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName") + +// alternatively `client.ListByResourceGroupDatabase(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByResourceGroupDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupDatabaseComplete(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByResourceGroupDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.ListByResourceGroupInstance` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewLocationLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName") + +// alternatively `client.ListByResourceGroupInstance(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByResourceGroupInstanceOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupInstanceComplete(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByResourceGroupInstanceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `LongTermRetentionManagedInstanceBackupsClient.ListByResourceGroupLocation` + +```go +ctx := context.TODO() +id := longtermretentionmanagedinstancebackups.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +// alternatively `client.ListByResourceGroupLocation(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByResourceGroupLocationOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupLocationComplete(ctx, id, longtermretentionmanagedinstancebackups.DefaultListByResourceGroupLocationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/client.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/client.go new file mode 100644 index 00000000000..c760d7410d6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/client.go @@ -0,0 +1,26 @@ +package longtermretentionmanagedinstancebackups + +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 LongTermRetentionManagedInstanceBackupsClient struct { + Client *resourcemanager.Client +} + +func NewLongTermRetentionManagedInstanceBackupsClientWithBaseURI(sdkApi sdkEnv.Api) (*LongTermRetentionManagedInstanceBackupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "longtermretentionmanagedinstancebackups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LongTermRetentionManagedInstanceBackupsClient: %+v", err) + } + + return &LongTermRetentionManagedInstanceBackupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/constants.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/constants.go new file mode 100644 index 00000000000..7fc6bf6e2ee --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/constants.go @@ -0,0 +1,142 @@ +package longtermretentionmanagedinstancebackups + +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 BackupStorageAccessTier string + +const ( + BackupStorageAccessTierArchive BackupStorageAccessTier = "Archive" + BackupStorageAccessTierHot BackupStorageAccessTier = "Hot" +) + +func PossibleValuesForBackupStorageAccessTier() []string { + return []string{ + string(BackupStorageAccessTierArchive), + string(BackupStorageAccessTierHot), + } +} + +func (s *BackupStorageAccessTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageAccessTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageAccessTier(input string) (*BackupStorageAccessTier, error) { + vals := map[string]BackupStorageAccessTier{ + "archive": BackupStorageAccessTierArchive, + "hot": BackupStorageAccessTierHot, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageAccessTier(input) + return &out, nil +} + +type BackupStorageRedundancy string + +const ( + BackupStorageRedundancyGeo BackupStorageRedundancy = "Geo" + BackupStorageRedundancyGeoZone BackupStorageRedundancy = "GeoZone" + BackupStorageRedundancyLocal BackupStorageRedundancy = "Local" + BackupStorageRedundancyZone BackupStorageRedundancy = "Zone" +) + +func PossibleValuesForBackupStorageRedundancy() []string { + return []string{ + string(BackupStorageRedundancyGeo), + string(BackupStorageRedundancyGeoZone), + string(BackupStorageRedundancyLocal), + string(BackupStorageRedundancyZone), + } +} + +func (s *BackupStorageRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageRedundancy(input string) (*BackupStorageRedundancy, error) { + vals := map[string]BackupStorageRedundancy{ + "geo": BackupStorageRedundancyGeo, + "geozone": BackupStorageRedundancyGeoZone, + "local": BackupStorageRedundancyLocal, + "zone": BackupStorageRedundancyZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageRedundancy(input) + return &out, nil +} + +type DatabaseState string + +const ( + DatabaseStateAll DatabaseState = "All" + DatabaseStateDeleted DatabaseState = "Deleted" + DatabaseStateLive DatabaseState = "Live" +) + +func PossibleValuesForDatabaseState() []string { + return []string{ + string(DatabaseStateAll), + string(DatabaseStateDeleted), + string(DatabaseStateLive), + } +} + +func (s *DatabaseState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseState(input string) (*DatabaseState, error) { + vals := map[string]DatabaseState{ + "all": DatabaseStateAll, + "deleted": DatabaseStateDeleted, + "live": DatabaseStateLive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location.go new file mode 100644 index 00000000000..067306e8e29 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location.go @@ -0,0 +1,121 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location_test.go new file mode 100644 index 00000000000..4282aaf3488 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_location_test.go @@ -0,0 +1,237 @@ +package longtermretentionmanagedinstancebackups + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go new file mode 100644 index 00000000000..805eb37ff92 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go @@ -0,0 +1,139 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationLongTermRetentionManagedInstanceId{}) +} + +var _ resourceids.ResourceId = &LocationLongTermRetentionManagedInstanceId{} + +// LocationLongTermRetentionManagedInstanceId is a struct representing the Resource ID for a Location Long Term Retention Managed Instance +type LocationLongTermRetentionManagedInstanceId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + LongTermRetentionManagedInstanceName string +} + +// NewLocationLongTermRetentionManagedInstanceID returns a new LocationLongTermRetentionManagedInstanceId struct +func NewLocationLongTermRetentionManagedInstanceID(subscriptionId string, resourceGroupName string, locationName string, longTermRetentionManagedInstanceName string) LocationLongTermRetentionManagedInstanceId { + return LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + LongTermRetentionManagedInstanceName: longTermRetentionManagedInstanceName, + } +} + +// ParseLocationLongTermRetentionManagedInstanceID parses 'input' into a LocationLongTermRetentionManagedInstanceId +func ParseLocationLongTermRetentionManagedInstanceID(input string) (*LocationLongTermRetentionManagedInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationLongTermRetentionManagedInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationLongTermRetentionManagedInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationLongTermRetentionManagedInstanceIDInsensitively parses 'input' case-insensitively into a LocationLongTermRetentionManagedInstanceId +// note: this method should only be used for API response data and not user input +func ParseLocationLongTermRetentionManagedInstanceIDInsensitively(input string) (*LocationLongTermRetentionManagedInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationLongTermRetentionManagedInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationLongTermRetentionManagedInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationLongTermRetentionManagedInstanceId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionManagedInstanceName, ok = input.Parsed["longTermRetentionManagedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceName", input) + } + + return nil +} + +// ValidateLocationLongTermRetentionManagedInstanceID checks that 'input' can be parsed as a Location Long Term Retention Managed Instance ID +func ValidateLocationLongTermRetentionManagedInstanceID(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 := ParseLocationLongTermRetentionManagedInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location Long Term Retention Managed Instance ID +func (id LocationLongTermRetentionManagedInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionManagedInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.LongTermRetentionManagedInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location Long Term Retention Managed Instance ID +func (id LocationLongTermRetentionManagedInstanceId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceName"), + } +} + +// String returns a human-readable description of this Location Long Term Retention Managed Instance ID +func (id LocationLongTermRetentionManagedInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Managed Instance Name: %q", id.LongTermRetentionManagedInstanceName), + } + return fmt.Sprintf("Location Long Term Retention Managed Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go new file mode 100644 index 00000000000..5b4163e0669 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go @@ -0,0 +1,327 @@ +package longtermretentionmanagedinstancebackups + +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 = &LocationLongTermRetentionManagedInstanceId{} + +func TestNewLocationLongTermRetentionManagedInstanceID(t *testing.T) { + id := NewLocationLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceName") + } +} + +func TestFormatLocationLongTermRetentionManagedInstanceID(t *testing.T) { + actual := NewLocationLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationLongTermRetentionManagedInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationLongTermRetentionManagedInstanceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Expected: &LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationLongTermRetentionManagedInstanceID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + } +} + +func TestParseLocationLongTermRetentionManagedInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationLongTermRetentionManagedInstanceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Expected: &LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + Expected: &LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationLongTermRetentionManagedInstanceIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + } +} + +func TestSegmentsForLocationLongTermRetentionManagedInstanceId(t *testing.T) { + segments := LocationLongTermRetentionManagedInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationLongTermRetentionManagedInstanceId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go new file mode 100644 index 00000000000..c7b7671f02e --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go @@ -0,0 +1,139 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionDatabaseId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionDatabaseId{} + +// LongTermRetentionDatabaseId is a struct representing the Resource ID for a Long Term Retention Database +type LongTermRetentionDatabaseId struct { + SubscriptionId string + LocationName string + LongTermRetentionManagedInstanceName string + LongTermRetentionDatabaseName string +} + +// NewLongTermRetentionDatabaseID returns a new LongTermRetentionDatabaseId struct +func NewLongTermRetentionDatabaseID(subscriptionId string, locationName string, longTermRetentionManagedInstanceName string, longTermRetentionDatabaseName string) LongTermRetentionDatabaseId { + return LongTermRetentionDatabaseId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + LongTermRetentionManagedInstanceName: longTermRetentionManagedInstanceName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + } +} + +// ParseLongTermRetentionDatabaseID parses 'input' into a LongTermRetentionDatabaseId +func ParseLongTermRetentionDatabaseID(input string) (*LongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionDatabaseIDInsensitively parses 'input' case-insensitively into a LongTermRetentionDatabaseId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionDatabaseIDInsensitively(input string) (*LongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionDatabaseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionManagedInstanceName, ok = input.Parsed["longTermRetentionManagedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + return nil +} + +// ValidateLongTermRetentionDatabaseID checks that 'input' can be parsed as a Long Term Retention Database ID +func ValidateLongTermRetentionDatabaseID(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 := ParseLongTermRetentionDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Database ID +func (id LongTermRetentionDatabaseId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionManagedInstances/%s/longTermRetentionDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.LongTermRetentionManagedInstanceName, id.LongTermRetentionDatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Database ID +func (id LongTermRetentionDatabaseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + } +} + +// String returns a human-readable description of this Long Term Retention Database ID +func (id LongTermRetentionDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Managed Instance Name: %q", id.LongTermRetentionManagedInstanceName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + } + return fmt.Sprintf("Long Term Retention Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go new file mode 100644 index 00000000000..a5caeee809c --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go @@ -0,0 +1,327 @@ +package longtermretentionmanagedinstancebackups + +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 = &LongTermRetentionDatabaseId{} + +func TestNewLongTermRetentionDatabaseID(t *testing.T) { + id := NewLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } +} + +func TestFormatLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionDatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionDatabaseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestParseLongTermRetentionDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionDatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Expected: &LongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionDatabaseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestSegmentsForLongTermRetentionDatabaseId(t *testing.T) { + segments := LongTermRetentionDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionDatabaseId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go new file mode 100644 index 00000000000..58e7e784b09 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go @@ -0,0 +1,157 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{} + +// LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId is a struct representing the Resource ID for a Long Term Retention Database Long Term Retention Managed Instance Backup +type LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + LongTermRetentionManagedInstanceName string + LongTermRetentionDatabaseName string + LongTermRetentionManagedInstanceBackupName string +} + +// NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID returns a new LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId struct +func NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(subscriptionId string, resourceGroupName string, locationName string, longTermRetentionManagedInstanceName string, longTermRetentionDatabaseName string, longTermRetentionManagedInstanceBackupName string) LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId { + return LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + LongTermRetentionManagedInstanceName: longTermRetentionManagedInstanceName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + LongTermRetentionManagedInstanceBackupName: longTermRetentionManagedInstanceBackupName, + } +} + +// ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID parses 'input' into a LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId +func ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(input string) (*LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupIDInsensitively parses 'input' case-insensitively into a LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupIDInsensitively(input string) (*LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionManagedInstanceName, ok = input.Parsed["longTermRetentionManagedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + if id.LongTermRetentionManagedInstanceBackupName, ok = input.Parsed["longTermRetentionManagedInstanceBackupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceBackupName", input) + } + + return nil +} + +// ValidateLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID checks that 'input' can be parsed as a Long Term Retention Database Long Term Retention Managed Instance Backup ID +func ValidateLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(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 := ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Database Long Term Retention Managed Instance Backup ID +func (id LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionManagedInstances/%s/longTermRetentionDatabases/%s/longTermRetentionManagedInstanceBackups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.LongTermRetentionManagedInstanceName, id.LongTermRetentionDatabaseName, id.LongTermRetentionManagedInstanceBackupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Database Long Term Retention Managed Instance Backup ID +func (id LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceBackupName", "longTermRetentionManagedInstanceBackupName"), + } +} + +// String returns a human-readable description of this Long Term Retention Database Long Term Retention Managed Instance Backup ID +func (id LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Managed Instance Name: %q", id.LongTermRetentionManagedInstanceName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + fmt.Sprintf("Long Term Retention Managed Instance Backup Name: %q", id.LongTermRetentionManagedInstanceBackupName), + } + return fmt.Sprintf("Long Term Retention Database Long Term Retention Managed Instance Backup (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go new file mode 100644 index 00000000000..c0aadb986a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go @@ -0,0 +1,417 @@ +package longtermretentionmanagedinstancebackups + +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 = &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{} + +func TestNewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(t *testing.T) { + id := NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } + + if id.LongTermRetentionManagedInstanceBackupName != "longTermRetentionManagedInstanceBackupName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceBackupName'", id.LongTermRetentionManagedInstanceBackupName, "longTermRetentionManagedInstanceBackupName") + } +} + +func TestFormatLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(t *testing.T) { + actual := NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName", + Expected: &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionManagedInstanceBackupName != v.Expected.LongTermRetentionManagedInstanceBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceBackupName", v.Expected.LongTermRetentionManagedInstanceBackupName, actual.LongTermRetentionManagedInstanceBackupName) + } + + } +} + +func TestParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName", + Expected: &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPnAmE", + Expected: &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + LongTermRetentionManagedInstanceBackupName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionManagedInstanceBackupName != v.Expected.LongTermRetentionManagedInstanceBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceBackupName", v.Expected.LongTermRetentionManagedInstanceBackupName, actual.LongTermRetentionManagedInstanceBackupName) + } + + } +} + +func TestSegmentsForLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId(t *testing.T) { + segments := LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go new file mode 100644 index 00000000000..740b763d4d3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go @@ -0,0 +1,130 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionManagedInstanceId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionManagedInstanceId{} + +// LongTermRetentionManagedInstanceId is a struct representing the Resource ID for a Long Term Retention Managed Instance +type LongTermRetentionManagedInstanceId struct { + SubscriptionId string + LocationName string + LongTermRetentionManagedInstanceName string +} + +// NewLongTermRetentionManagedInstanceID returns a new LongTermRetentionManagedInstanceId struct +func NewLongTermRetentionManagedInstanceID(subscriptionId string, locationName string, longTermRetentionManagedInstanceName string) LongTermRetentionManagedInstanceId { + return LongTermRetentionManagedInstanceId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + LongTermRetentionManagedInstanceName: longTermRetentionManagedInstanceName, + } +} + +// ParseLongTermRetentionManagedInstanceID parses 'input' into a LongTermRetentionManagedInstanceId +func ParseLongTermRetentionManagedInstanceID(input string) (*LongTermRetentionManagedInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionManagedInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionManagedInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionManagedInstanceIDInsensitively parses 'input' case-insensitively into a LongTermRetentionManagedInstanceId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionManagedInstanceIDInsensitively(input string) (*LongTermRetentionManagedInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionManagedInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionManagedInstanceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionManagedInstanceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionManagedInstanceName, ok = input.Parsed["longTermRetentionManagedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceName", input) + } + + return nil +} + +// ValidateLongTermRetentionManagedInstanceID checks that 'input' can be parsed as a Long Term Retention Managed Instance ID +func ValidateLongTermRetentionManagedInstanceID(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 := ParseLongTermRetentionManagedInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Managed Instance ID +func (id LongTermRetentionManagedInstanceId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionManagedInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.LongTermRetentionManagedInstanceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Managed Instance ID +func (id LongTermRetentionManagedInstanceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceName"), + } +} + +// String returns a human-readable description of this Long Term Retention Managed Instance ID +func (id LongTermRetentionManagedInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Managed Instance Name: %q", id.LongTermRetentionManagedInstanceName), + } + return fmt.Sprintf("Long Term Retention Managed Instance (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go new file mode 100644 index 00000000000..ff6564e842e --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go @@ -0,0 +1,282 @@ +package longtermretentionmanagedinstancebackups + +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 = &LongTermRetentionManagedInstanceId{} + +func TestNewLongTermRetentionManagedInstanceID(t *testing.T) { + id := NewLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceName") + } +} + +func TestFormatLongTermRetentionManagedInstanceID(t *testing.T) { + actual := NewLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionManagedInstanceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionManagedInstanceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Expected: &LongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionManagedInstanceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + } +} + +func TestParseLongTermRetentionManagedInstanceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionManagedInstanceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Expected: &LongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + Expected: &LongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionManagedInstanceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + } +} + +func TestSegmentsForLongTermRetentionManagedInstanceId(t *testing.T) { + segments := LongTermRetentionManagedInstanceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionManagedInstanceId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go new file mode 100644 index 00000000000..3b3d731c1a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go @@ -0,0 +1,148 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionManagedInstanceBackupId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionManagedInstanceBackupId{} + +// LongTermRetentionManagedInstanceBackupId is a struct representing the Resource ID for a Long Term Retention Managed Instance Backup +type LongTermRetentionManagedInstanceBackupId struct { + SubscriptionId string + LocationName string + LongTermRetentionManagedInstanceName string + LongTermRetentionDatabaseName string + LongTermRetentionManagedInstanceBackupName string +} + +// NewLongTermRetentionManagedInstanceBackupID returns a new LongTermRetentionManagedInstanceBackupId struct +func NewLongTermRetentionManagedInstanceBackupID(subscriptionId string, locationName string, longTermRetentionManagedInstanceName string, longTermRetentionDatabaseName string, longTermRetentionManagedInstanceBackupName string) LongTermRetentionManagedInstanceBackupId { + return LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + LongTermRetentionManagedInstanceName: longTermRetentionManagedInstanceName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + LongTermRetentionManagedInstanceBackupName: longTermRetentionManagedInstanceBackupName, + } +} + +// ParseLongTermRetentionManagedInstanceBackupID parses 'input' into a LongTermRetentionManagedInstanceBackupId +func ParseLongTermRetentionManagedInstanceBackupID(input string) (*LongTermRetentionManagedInstanceBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionManagedInstanceBackupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionManagedInstanceBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionManagedInstanceBackupIDInsensitively parses 'input' case-insensitively into a LongTermRetentionManagedInstanceBackupId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionManagedInstanceBackupIDInsensitively(input string) (*LongTermRetentionManagedInstanceBackupId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionManagedInstanceBackupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionManagedInstanceBackupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionManagedInstanceBackupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionManagedInstanceName, ok = input.Parsed["longTermRetentionManagedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + if id.LongTermRetentionManagedInstanceBackupName, ok = input.Parsed["longTermRetentionManagedInstanceBackupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceBackupName", input) + } + + return nil +} + +// ValidateLongTermRetentionManagedInstanceBackupID checks that 'input' can be parsed as a Long Term Retention Managed Instance Backup ID +func ValidateLongTermRetentionManagedInstanceBackupID(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 := ParseLongTermRetentionManagedInstanceBackupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Managed Instance Backup ID +func (id LongTermRetentionManagedInstanceBackupId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionManagedInstances/%s/longTermRetentionDatabases/%s/longTermRetentionManagedInstanceBackups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.LongTermRetentionManagedInstanceName, id.LongTermRetentionDatabaseName, id.LongTermRetentionManagedInstanceBackupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Managed Instance Backup ID +func (id LongTermRetentionManagedInstanceBackupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceBackupName", "longTermRetentionManagedInstanceBackupName"), + } +} + +// String returns a human-readable description of this Long Term Retention Managed Instance Backup ID +func (id LongTermRetentionManagedInstanceBackupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Managed Instance Name: %q", id.LongTermRetentionManagedInstanceName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + fmt.Sprintf("Long Term Retention Managed Instance Backup Name: %q", id.LongTermRetentionManagedInstanceBackupName), + } + return fmt.Sprintf("Long Term Retention Managed Instance Backup (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go new file mode 100644 index 00000000000..36426a0f2f3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go @@ -0,0 +1,372 @@ +package longtermretentionmanagedinstancebackups + +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 = &LongTermRetentionManagedInstanceBackupId{} + +func TestNewLongTermRetentionManagedInstanceBackupID(t *testing.T) { + id := NewLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } + + if id.LongTermRetentionManagedInstanceBackupName != "longTermRetentionManagedInstanceBackupName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceBackupName'", id.LongTermRetentionManagedInstanceBackupName, "longTermRetentionManagedInstanceBackupName") + } +} + +func TestFormatLongTermRetentionManagedInstanceBackupID(t *testing.T) { + actual := NewLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName", "longTermRetentionManagedInstanceBackupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionManagedInstanceBackupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionManagedInstanceBackupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName", + Expected: &LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionManagedInstanceBackupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionManagedInstanceBackupName != v.Expected.LongTermRetentionManagedInstanceBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceBackupName", v.Expected.LongTermRetentionManagedInstanceBackupName, actual.LongTermRetentionManagedInstanceBackupName) + } + + } +} + +func TestParseLongTermRetentionManagedInstanceBackupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionManagedInstanceBackupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName", + Expected: &LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPnAmE", + Expected: &LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + LongTermRetentionManagedInstanceBackupName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionManagedInstanceBackupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + if actual.LongTermRetentionManagedInstanceBackupName != v.Expected.LongTermRetentionManagedInstanceBackupName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceBackupName", v.Expected.LongTermRetentionManagedInstanceBackupName, actual.LongTermRetentionManagedInstanceBackupName) + } + + } +} + +func TestSegmentsForLongTermRetentionManagedInstanceBackupId(t *testing.T) { + segments := LongTermRetentionManagedInstanceBackupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionManagedInstanceBackupId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go new file mode 100644 index 00000000000..ad834089454 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go @@ -0,0 +1,148 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{}) +} + +var _ resourceids.ResourceId = &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{} + +// LongTermRetentionManagedInstanceLongTermRetentionDatabaseId is a struct representing the Resource ID for a Long Term Retention Managed Instance Long Term Retention Database +type LongTermRetentionManagedInstanceLongTermRetentionDatabaseId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + LongTermRetentionManagedInstanceName string + LongTermRetentionDatabaseName string +} + +// NewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID returns a new LongTermRetentionManagedInstanceLongTermRetentionDatabaseId struct +func NewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(subscriptionId string, resourceGroupName string, locationName string, longTermRetentionManagedInstanceName string, longTermRetentionDatabaseName string) LongTermRetentionManagedInstanceLongTermRetentionDatabaseId { + return LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + LongTermRetentionManagedInstanceName: longTermRetentionManagedInstanceName, + LongTermRetentionDatabaseName: longTermRetentionDatabaseName, + } +} + +// ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseID parses 'input' into a LongTermRetentionManagedInstanceLongTermRetentionDatabaseId +func ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(input string) (*LongTermRetentionManagedInstanceLongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseIDInsensitively parses 'input' case-insensitively into a LongTermRetentionManagedInstanceLongTermRetentionDatabaseId +// note: this method should only be used for API response data and not user input +func ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseIDInsensitively(input string) (*LongTermRetentionManagedInstanceLongTermRetentionDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LongTermRetentionManagedInstanceLongTermRetentionDatabaseId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.LongTermRetentionManagedInstanceName, ok = input.Parsed["longTermRetentionManagedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionManagedInstanceName", input) + } + + if id.LongTermRetentionDatabaseName, ok = input.Parsed["longTermRetentionDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "longTermRetentionDatabaseName", input) + } + + return nil +} + +// ValidateLongTermRetentionManagedInstanceLongTermRetentionDatabaseID checks that 'input' can be parsed as a Long Term Retention Managed Instance Long Term Retention Database ID +func ValidateLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(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 := ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Long Term Retention Managed Instance Long Term Retention Database ID +func (id LongTermRetentionManagedInstanceLongTermRetentionDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/longTermRetentionManagedInstances/%s/longTermRetentionDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.LongTermRetentionManagedInstanceName, id.LongTermRetentionDatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Long Term Retention Managed Instance Long Term Retention Database ID +func (id LongTermRetentionManagedInstanceLongTermRetentionDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceName"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseName"), + } +} + +// String returns a human-readable description of this Long Term Retention Managed Instance Long Term Retention Database ID +func (id LongTermRetentionManagedInstanceLongTermRetentionDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Long Term Retention Managed Instance Name: %q", id.LongTermRetentionManagedInstanceName), + fmt.Sprintf("Long Term Retention Database Name: %q", id.LongTermRetentionDatabaseName), + } + return fmt.Sprintf("Long Term Retention Managed Instance Long Term Retention Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go new file mode 100644 index 00000000000..8a82b5f12e2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go @@ -0,0 +1,372 @@ +package longtermretentionmanagedinstancebackups + +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 = &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{} + +func TestNewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(t *testing.T) { + id := NewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceName") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseName") + } +} + +func TestFormatLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "longTermRetentionManagedInstanceName", "longTermRetentionDatabaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionManagedInstanceLongTermRetentionDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LongTermRetentionManagedInstanceLongTermRetentionDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName", + Expected: &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceName", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/longTermRetentionManagedInstances/longTermRetentionManagedInstanceName/longTermRetentionDatabases/longTermRetentionDatabaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + Expected: &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeNaMe", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEnAmE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLongTermRetentionManagedInstanceLongTermRetentionDatabaseIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.LongTermRetentionManagedInstanceName != v.Expected.LongTermRetentionManagedInstanceName { + t.Fatalf("Expected %q but got %q for LongTermRetentionManagedInstanceName", v.Expected.LongTermRetentionManagedInstanceName, actual.LongTermRetentionManagedInstanceName) + } + + if actual.LongTermRetentionDatabaseName != v.Expected.LongTermRetentionDatabaseName { + t.Fatalf("Expected %q but got %q for LongTermRetentionDatabaseName", v.Expected.LongTermRetentionDatabaseName, actual.LongTermRetentionDatabaseName) + } + + } +} + +func TestSegmentsForLongTermRetentionManagedInstanceLongTermRetentionDatabaseId(t *testing.T) { + segments := LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LongTermRetentionManagedInstanceLongTermRetentionDatabaseId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation.go new file mode 100644 index 00000000000..f39c1d034a5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation.go @@ -0,0 +1,130 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation_test.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation_test.go new file mode 100644 index 00000000000..2b952a3eda9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package longtermretentionmanagedinstancebackups + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_delete.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_delete.go new file mode 100644 index 00000000000..53f24c648a0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_delete.go @@ -0,0 +1,70 @@ +package longtermretentionmanagedinstancebackups + +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 LongTermRetentionManagedInstanceBackupsClient) Delete(ctx context.Context, id LongTermRetentionManagedInstanceBackupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 LongTermRetentionManagedInstanceBackupsClient) DeleteThenPoll(ctx context.Context, id LongTermRetentionManagedInstanceBackupId) 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go new file mode 100644 index 00000000000..29ca9bcbe03 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go @@ -0,0 +1,70 @@ +package longtermretentionmanagedinstancebackups + +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 DeleteByResourceGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteByResourceGroup ... +func (c LongTermRetentionManagedInstanceBackupsClient) DeleteByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) (result DeleteByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 +} + +// DeleteByResourceGroupThenPoll performs DeleteByResourceGroup then polls until it's completed +func (c LongTermRetentionManagedInstanceBackupsClient) DeleteByResourceGroupThenPoll(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) error { + result, err := c.DeleteByResourceGroup(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteByResourceGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteByResourceGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_get.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_get.go new file mode 100644 index 00000000000..52afb6a0447 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_get.go @@ -0,0 +1,53 @@ +package longtermretentionmanagedinstancebackups + +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 *ManagedInstanceLongTermRetentionBackup +} + +// Get ... +func (c LongTermRetentionManagedInstanceBackupsClient) Get(ctx context.Context, id LongTermRetentionManagedInstanceBackupId) (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 ManagedInstanceLongTermRetentionBackup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go new file mode 100644 index 00000000000..b3da83c7539 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go @@ -0,0 +1,53 @@ +package longtermretentionmanagedinstancebackups + +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 GetByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceLongTermRetentionBackup +} + +// GetByResourceGroup ... +func (c LongTermRetentionManagedInstanceBackupsClient) GetByResourceGroup(ctx context.Context, id LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId) (result GetByResourceGroupOperationResponse, 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 ManagedInstanceLongTermRetentionBackup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbydatabase.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbydatabase.go new file mode 100644 index 00000000000..ffe527054b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbydatabase.go @@ -0,0 +1,138 @@ +package longtermretentionmanagedinstancebackups + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionBackup +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionBackup +} + +type ListByDatabaseOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c LongTermRetentionManagedInstanceBackupsClient) ListByDatabase(ctx context.Context, id LongTermRetentionDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", 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 *[]ManagedInstanceLongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c LongTermRetentionManagedInstanceBackupsClient) ListByDatabaseComplete(ctx context.Context, id LongTermRetentionDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, ManagedInstanceLongTermRetentionBackupOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionManagedInstanceBackupsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id LongTermRetentionDatabaseId, options ListByDatabaseOperationOptions, predicate ManagedInstanceLongTermRetentionBackupOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionBackup, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyinstance.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyinstance.go new file mode 100644 index 00000000000..ee445c5bb99 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyinstance.go @@ -0,0 +1,138 @@ +package longtermretentionmanagedinstancebackups + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionBackup +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionBackup +} + +type ListByInstanceOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByInstanceOperationOptions() ListByInstanceOperationOptions { + return ListByInstanceOperationOptions{} +} + +func (o ListByInstanceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByInstanceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByInstanceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c LongTermRetentionManagedInstanceBackupsClient) ListByInstance(ctx context.Context, id LongTermRetentionManagedInstanceId, options ListByInstanceOperationOptions) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", 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 *[]ManagedInstanceLongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c LongTermRetentionManagedInstanceBackupsClient) ListByInstanceComplete(ctx context.Context, id LongTermRetentionManagedInstanceId, options ListByInstanceOperationOptions) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, options, ManagedInstanceLongTermRetentionBackupOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionManagedInstanceBackupsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id LongTermRetentionManagedInstanceId, options ListByInstanceOperationOptions, predicate ManagedInstanceLongTermRetentionBackupOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionBackup, 0) + + resp, err := c.ListByInstance(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbylocation.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbylocation.go new file mode 100644 index 00000000000..bb957a98e53 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbylocation.go @@ -0,0 +1,150 @@ +package longtermretentionmanagedinstancebackups + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionBackup +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionBackup +} + +type ListByLocationOperationOptions struct { + DatabaseState *DatabaseState + Filter *string + OnlyLatestPerDatabase *bool + Skip *int64 + Top *int64 +} + +func DefaultListByLocationOperationOptions() ListByLocationOperationOptions { + return ListByLocationOperationOptions{} +} + +func (o ListByLocationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByLocationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByLocationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c LongTermRetentionManagedInstanceBackupsClient) ListByLocation(ctx context.Context, id LocationId, options ListByLocationOperationOptions) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", 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 *[]ManagedInstanceLongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c LongTermRetentionManagedInstanceBackupsClient) ListByLocationComplete(ctx context.Context, id LocationId, options ListByLocationOperationOptions) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, options, ManagedInstanceLongTermRetentionBackupOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionManagedInstanceBackupsClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, options ListByLocationOperationOptions, predicate ManagedInstanceLongTermRetentionBackupOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionBackup, 0) + + resp, err := c.ListByLocation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go new file mode 100644 index 00000000000..630b3198164 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go @@ -0,0 +1,138 @@ +package longtermretentionmanagedinstancebackups + +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 ListByResourceGroupDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionBackup +} + +type ListByResourceGroupDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionBackup +} + +type ListByResourceGroupDatabaseOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByResourceGroupDatabaseOperationOptions() ListByResourceGroupDatabaseOperationOptions { + return ListByResourceGroupDatabaseOperationOptions{} +} + +func (o ListByResourceGroupDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByResourceGroupDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroupDatabase ... +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupDatabase(ctx context.Context, id LongTermRetentionManagedInstanceLongTermRetentionDatabaseId, options ListByResourceGroupDatabaseOperationOptions) (result ListByResourceGroupDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", 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 *[]ManagedInstanceLongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupDatabaseComplete retrieves all the results into a single object +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupDatabaseComplete(ctx context.Context, id LongTermRetentionManagedInstanceLongTermRetentionDatabaseId, options ListByResourceGroupDatabaseOperationOptions) (ListByResourceGroupDatabaseCompleteResult, error) { + return c.ListByResourceGroupDatabaseCompleteMatchingPredicate(ctx, id, options, ManagedInstanceLongTermRetentionBackupOperationPredicate{}) +} + +// ListByResourceGroupDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupDatabaseCompleteMatchingPredicate(ctx context.Context, id LongTermRetentionManagedInstanceLongTermRetentionDatabaseId, options ListByResourceGroupDatabaseOperationOptions, predicate ManagedInstanceLongTermRetentionBackupOperationPredicate) (result ListByResourceGroupDatabaseCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionBackup, 0) + + resp, err := c.ListByResourceGroupDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go new file mode 100644 index 00000000000..f0c0bf40d7d --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go @@ -0,0 +1,138 @@ +package longtermretentionmanagedinstancebackups + +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 ListByResourceGroupInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionBackup +} + +type ListByResourceGroupInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionBackup +} + +type ListByResourceGroupInstanceOperationOptions struct { + DatabaseState *DatabaseState + OnlyLatestPerDatabase *bool +} + +func DefaultListByResourceGroupInstanceOperationOptions() ListByResourceGroupInstanceOperationOptions { + return ListByResourceGroupInstanceOperationOptions{} +} + +func (o ListByResourceGroupInstanceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupInstanceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupInstanceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByResourceGroupInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroupInstance ... +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupInstance(ctx context.Context, id LocationLongTermRetentionManagedInstanceId, options ListByResourceGroupInstanceOperationOptions) (result ListByResourceGroupInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupInstanceCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", 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 *[]ManagedInstanceLongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupInstanceComplete retrieves all the results into a single object +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupInstanceComplete(ctx context.Context, id LocationLongTermRetentionManagedInstanceId, options ListByResourceGroupInstanceOperationOptions) (ListByResourceGroupInstanceCompleteResult, error) { + return c.ListByResourceGroupInstanceCompleteMatchingPredicate(ctx, id, options, ManagedInstanceLongTermRetentionBackupOperationPredicate{}) +} + +// ListByResourceGroupInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupInstanceCompleteMatchingPredicate(ctx context.Context, id LocationLongTermRetentionManagedInstanceId, options ListByResourceGroupInstanceOperationOptions, predicate ManagedInstanceLongTermRetentionBackupOperationPredicate) (result ListByResourceGroupInstanceCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionBackup, 0) + + resp, err := c.ListByResourceGroupInstance(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go new file mode 100644 index 00000000000..24092396c63 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go @@ -0,0 +1,150 @@ +package longtermretentionmanagedinstancebackups + +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 ListByResourceGroupLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionBackup +} + +type ListByResourceGroupLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionBackup +} + +type ListByResourceGroupLocationOperationOptions struct { + DatabaseState *DatabaseState + Filter *string + OnlyLatestPerDatabase *bool + Skip *int64 + Top *int64 +} + +func DefaultListByResourceGroupLocationOperationOptions() ListByResourceGroupLocationOperationOptions { + return ListByResourceGroupLocationOperationOptions{} +} + +func (o ListByResourceGroupLocationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupLocationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupLocationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatabaseState != nil { + out.Append("databaseState", fmt.Sprintf("%v", *o.DatabaseState)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByResourceGroupLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroupLocation ... +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupLocation(ctx context.Context, id ProviderLocationId, options ListByResourceGroupLocationOperationOptions) (result ListByResourceGroupLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupLocationCustomPager{}, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", 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 *[]ManagedInstanceLongTermRetentionBackup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupLocationComplete retrieves all the results into a single object +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupLocationComplete(ctx context.Context, id ProviderLocationId, options ListByResourceGroupLocationOperationOptions) (ListByResourceGroupLocationCompleteResult, error) { + return c.ListByResourceGroupLocationCompleteMatchingPredicate(ctx, id, options, ManagedInstanceLongTermRetentionBackupOperationPredicate{}) +} + +// ListByResourceGroupLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionManagedInstanceBackupsClient) ListByResourceGroupLocationCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, options ListByResourceGroupLocationOperationOptions, predicate ManagedInstanceLongTermRetentionBackupOperationPredicate) (result ListByResourceGroupLocationCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionBackup, 0) + + resp, err := c.ListByResourceGroupLocation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go new file mode 100644 index 00000000000..84ea87ca20c --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go @@ -0,0 +1,11 @@ +package longtermretentionmanagedinstancebackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceLongTermRetentionBackup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceLongTermRetentionBackupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go new file mode 100644 index 00000000000..13a07ccde61 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go @@ -0,0 +1,69 @@ +package longtermretentionmanagedinstancebackups + +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 ManagedInstanceLongTermRetentionBackupProperties struct { + BackupExpirationTime *string `json:"backupExpirationTime,omitempty"` + BackupStorageAccessTier *BackupStorageAccessTier `json:"backupStorageAccessTier,omitempty"` + BackupStorageRedundancy *BackupStorageRedundancy `json:"backupStorageRedundancy,omitempty"` + BackupTime *string `json:"backupTime,omitempty"` + DatabaseDeletionTime *string `json:"databaseDeletionTime,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + ManagedInstanceCreateTime *string `json:"managedInstanceCreateTime,omitempty"` + ManagedInstanceName *string `json:"managedInstanceName,omitempty"` +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) GetBackupExpirationTimeAsTime() (*time.Time, error) { + if o.BackupExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BackupExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) SetBackupExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BackupExpirationTime = &formatted +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) GetBackupTimeAsTime() (*time.Time, error) { + if o.BackupTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.BackupTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) SetBackupTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.BackupTime = &formatted +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) GetDatabaseDeletionTimeAsTime() (*time.Time, error) { + if o.DatabaseDeletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DatabaseDeletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) SetDatabaseDeletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DatabaseDeletionTime = &formatted +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) GetManagedInstanceCreateTimeAsTime() (*time.Time, error) { + if o.ManagedInstanceCreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ManagedInstanceCreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceLongTermRetentionBackupProperties) SetManagedInstanceCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ManagedInstanceCreateTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/predicates.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/predicates.go new file mode 100644 index 00000000000..0110d8aa257 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/predicates.go @@ -0,0 +1,27 @@ +package longtermretentionmanagedinstancebackups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceLongTermRetentionBackupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceLongTermRetentionBackupOperationPredicate) Matches(input ManagedInstanceLongTermRetentionBackup) 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/sql/2023-08-01/longtermretentionmanagedinstancebackups/version.go b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/version.go new file mode 100644 index 00000000000..a573eaed0dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionmanagedinstancebackups/version.go @@ -0,0 +1,10 @@ +package longtermretentionmanagedinstancebackups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/longtermretentionmanagedinstancebackups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/README.md b/resource-manager/sql/2023-08-01/longtermretentionpolicies/README.md new file mode 100644 index 00000000000..5d27d0413a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionpolicies` Documentation + +The `longtermretentionpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/longtermretentionpolicies" +``` + + +### Client Initialization + +```go +client := longtermretentionpolicies.NewLongTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LongTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := longtermretentionpolicies.LongTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `LongTermRetentionPoliciesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/client.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/client.go new file mode 100644 index 00000000000..6cb0156b421 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/client.go @@ -0,0 +1,26 @@ +package longtermretentionpolicies + +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 LongTermRetentionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewLongTermRetentionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*LongTermRetentionPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "longtermretentionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LongTermRetentionPoliciesClient: %+v", err) + } + + return &LongTermRetentionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..a7d188908b9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package longtermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionPolicy +} + +// CreateOrUpdate ... +func (c LongTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input LongTermRetentionPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c LongTermRetentionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input LongTermRetentionPolicy) 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/sql/2023-08-01/longtermretentionpolicies/method_get.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_get.go new file mode 100644 index 00000000000..094e02d9471 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_get.go @@ -0,0 +1,55 @@ +package longtermretentionpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LongTermRetentionPolicy +} + +// Get ... +func (c LongTermRetentionPoliciesClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies/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 LongTermRetentionPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..7a18447288b --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,106 @@ +package longtermretentionpolicies + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LongTermRetentionPolicy +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []LongTermRetentionPolicy +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c LongTermRetentionPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies", 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 *[]LongTermRetentionPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c LongTermRetentionPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, LongTermRetentionPolicyOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LongTermRetentionPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate LongTermRetentionPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]LongTermRetentionPolicy, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/model_baselongtermretentionpolicyproperties.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/model_baselongtermretentionpolicyproperties.go new file mode 100644 index 00000000000..b867c61a727 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/model_baselongtermretentionpolicyproperties.go @@ -0,0 +1,11 @@ +package longtermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaseLongTermRetentionPolicyProperties struct { + MonthlyRetention *string `json:"monthlyRetention,omitempty"` + WeekOfYear *int64 `json:"weekOfYear,omitempty"` + WeeklyRetention *string `json:"weeklyRetention,omitempty"` + YearlyRetention *string `json:"yearlyRetention,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/model_longtermretentionpolicy.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/model_longtermretentionpolicy.go new file mode 100644 index 00000000000..77f4b88aea8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/model_longtermretentionpolicy.go @@ -0,0 +1,11 @@ +package longtermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LongTermRetentionPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BaseLongTermRetentionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/longtermretentionpolicies/predicates.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/predicates.go new file mode 100644 index 00000000000..66b4b6c12ed --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/predicates.go @@ -0,0 +1,27 @@ +package longtermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LongTermRetentionPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LongTermRetentionPolicyOperationPredicate) Matches(input LongTermRetentionPolicy) 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/sql/2023-08-01/longtermretentionpolicies/version.go b/resource-manager/sql/2023-08-01/longtermretentionpolicies/version.go new file mode 100644 index 00000000000..6012d144862 --- /dev/null +++ b/resource-manager/sql/2023-08-01/longtermretentionpolicies/version.go @@ -0,0 +1,10 @@ +package longtermretentionpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/longtermretentionpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/README.md b/resource-manager/sql/2023-08-01/maintenancewindowoptions/README.md new file mode 100644 index 00000000000..137fb8fb318 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/maintenancewindowoptions` Documentation + +The `maintenancewindowoptions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/maintenancewindowoptions" +``` + + +### Client Initialization + +```go +client := maintenancewindowoptions.NewMaintenanceWindowOptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MaintenanceWindowOptionsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.Get(ctx, id, maintenancewindowoptions.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/client.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/client.go new file mode 100644 index 00000000000..48e61cf6a23 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/client.go @@ -0,0 +1,26 @@ +package maintenancewindowoptions + +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 MaintenanceWindowOptionsClient struct { + Client *resourcemanager.Client +} + +func NewMaintenanceWindowOptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*MaintenanceWindowOptionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "maintenancewindowoptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MaintenanceWindowOptionsClient: %+v", err) + } + + return &MaintenanceWindowOptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/constants.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/constants.go new file mode 100644 index 00000000000..1ebcd9e550e --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/constants.go @@ -0,0 +1,66 @@ +package maintenancewindowoptions + +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 DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/method_get.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/method_get.go new file mode 100644 index 00000000000..9070bdecbc9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/method_get.go @@ -0,0 +1,84 @@ +package maintenancewindowoptions + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MaintenanceWindowOptions +} + +type GetOperationOptions struct { + MaintenanceWindowOptionsName *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.MaintenanceWindowOptionsName != nil { + out.Append("maintenanceWindowOptionsName", fmt.Sprintf("%v", *o.MaintenanceWindowOptionsName)) + } + return &out +} + +// Get ... +func (c MaintenanceWindowOptionsClient) Get(ctx context.Context, id commonids.SqlDatabaseId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/maintenanceWindowOptions/current", 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 MaintenanceWindowOptions + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptions.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptions.go new file mode 100644 index 00000000000..77cc4d79886 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptions.go @@ -0,0 +1,11 @@ +package maintenancewindowoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowOptions struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MaintenanceWindowOptionsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go new file mode 100644 index 00000000000..d2f339ce856 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go @@ -0,0 +1,14 @@ +package maintenancewindowoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowOptionsProperties struct { + AllowMultipleMaintenanceWindowsPerCycle *bool `json:"allowMultipleMaintenanceWindowsPerCycle,omitempty"` + DefaultDurationInMinutes *int64 `json:"defaultDurationInMinutes,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` + MaintenanceWindowCycles *[]MaintenanceWindowTimeRange `json:"maintenanceWindowCycles,omitempty"` + MinCycles *int64 `json:"minCycles,omitempty"` + MinDurationInMinutes *int64 `json:"minDurationInMinutes,omitempty"` + TimeGranularityInMinutes *int64 `json:"timeGranularityInMinutes,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowtimerange.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowtimerange.go new file mode 100644 index 00000000000..a6f4a47a058 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/model_maintenancewindowtimerange.go @@ -0,0 +1,10 @@ +package maintenancewindowoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowTimeRange struct { + DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"` + Duration *string `json:"duration,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindowoptions/version.go b/resource-manager/sql/2023-08-01/maintenancewindowoptions/version.go new file mode 100644 index 00000000000..1fda0abc829 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindowoptions/version.go @@ -0,0 +1,10 @@ +package maintenancewindowoptions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/maintenancewindowoptions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/README.md b/resource-manager/sql/2023-08-01/maintenancewindows/README.md new file mode 100644 index 00000000000..1af59ddf56c --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/maintenancewindows` Documentation + +The `maintenancewindows` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/maintenancewindows" +``` + + +### Client Initialization + +```go +client := maintenancewindows.NewMaintenanceWindowsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MaintenanceWindowsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := maintenancewindows.MaintenanceWindows{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, maintenancewindows.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MaintenanceWindowsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +read, err := client.Get(ctx, id, maintenancewindows.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/client.go b/resource-manager/sql/2023-08-01/maintenancewindows/client.go new file mode 100644 index 00000000000..ea7db39e0d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/client.go @@ -0,0 +1,26 @@ +package maintenancewindows + +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 MaintenanceWindowsClient struct { + Client *resourcemanager.Client +} + +func NewMaintenanceWindowsClientWithBaseURI(sdkApi sdkEnv.Api) (*MaintenanceWindowsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "maintenancewindows", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MaintenanceWindowsClient: %+v", err) + } + + return &MaintenanceWindowsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/constants.go b/resource-manager/sql/2023-08-01/maintenancewindows/constants.go new file mode 100644 index 00000000000..d8a7a41328a --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/constants.go @@ -0,0 +1,66 @@ +package maintenancewindows + +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 DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/method_createorupdate.go b/resource-manager/sql/2023-08-01/maintenancewindows/method_createorupdate.go new file mode 100644 index 00000000000..2bc30cada7d --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/method_createorupdate.go @@ -0,0 +1,81 @@ +package maintenancewindows + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type CreateOrUpdateOperationOptions struct { + MaintenanceWindowName *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.MaintenanceWindowName != nil { + out.Append("maintenanceWindowName", fmt.Sprintf("%v", *o.MaintenanceWindowName)) + } + return &out +} + +// CreateOrUpdate ... +func (c MaintenanceWindowsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input MaintenanceWindows, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/maintenanceWindows/current", 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/method_get.go b/resource-manager/sql/2023-08-01/maintenancewindows/method_get.go new file mode 100644 index 00000000000..e8b85a9a880 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/method_get.go @@ -0,0 +1,84 @@ +package maintenancewindows + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MaintenanceWindows +} + +type GetOperationOptions struct { + MaintenanceWindowName *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.MaintenanceWindowName != nil { + out.Append("maintenanceWindowName", fmt.Sprintf("%v", *o.MaintenanceWindowName)) + } + return &out +} + +// Get ... +func (c MaintenanceWindowsClient) Get(ctx context.Context, id commonids.SqlDatabaseId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/maintenanceWindows/current", 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 MaintenanceWindows + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindows.go b/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindows.go new file mode 100644 index 00000000000..7c843fed669 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindows.go @@ -0,0 +1,11 @@ +package maintenancewindows + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindows struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MaintenanceWindowsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowsproperties.go b/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowsproperties.go new file mode 100644 index 00000000000..06c60a8dbb4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowsproperties.go @@ -0,0 +1,8 @@ +package maintenancewindows + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowsProperties struct { + TimeRanges *[]MaintenanceWindowTimeRange `json:"timeRanges,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowtimerange.go b/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowtimerange.go new file mode 100644 index 00000000000..abf0406242f --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/model_maintenancewindowtimerange.go @@ -0,0 +1,10 @@ +package maintenancewindows + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowTimeRange struct { + DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"` + Duration *string `json:"duration,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/maintenancewindows/version.go b/resource-manager/sql/2023-08-01/maintenancewindows/version.go new file mode 100644 index 00000000000..f8c91f8df0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/maintenancewindows/version.go @@ -0,0 +1,10 @@ +package maintenancewindows + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/maintenancewindows/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/README.md b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/README.md new file mode 100644 index 00000000000..0c2a2394d7e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/README.md @@ -0,0 +1,88 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies` Documentation + +The `managedbackupshorttermretentionpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies" +``` + + +### Client Initialization + +```go +client := managedbackupshorttermretentionpolicies.NewManagedBackupShortTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedBackupShortTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := managedbackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedBackupShortTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedBackupShortTermRetentionPoliciesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedBackupShortTermRetentionPoliciesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := managedbackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/client.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/client.go new file mode 100644 index 00000000000..ded8568660a --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/client.go @@ -0,0 +1,26 @@ +package managedbackupshorttermretentionpolicies + +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 ManagedBackupShortTermRetentionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewManagedBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedBackupShortTermRetentionPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedbackupshorttermretentionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedBackupShortTermRetentionPoliciesClient: %+v", err) + } + + return &ManagedBackupShortTermRetentionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..e7fb1a0180e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedbackupshorttermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedBackupShortTermRetentionPolicy +} + +// CreateOrUpdate ... +func (c ManagedBackupShortTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedBackupShortTermRetentionPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedBackupShortTermRetentionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedBackupShortTermRetentionPolicy) 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/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_get.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_get.go new file mode 100644 index 00000000000..e79878dc564 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_get.go @@ -0,0 +1,55 @@ +package managedbackupshorttermretentionpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedBackupShortTermRetentionPolicy +} + +// Get ... +func (c ManagedBackupShortTermRetentionPoliciesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 ManagedBackupShortTermRetentionPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..abd1880b463 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,106 @@ +package managedbackupshorttermretentionpolicies + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedBackupShortTermRetentionPolicy +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedBackupShortTermRetentionPolicy +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedBackupShortTermRetentionPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies", 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 *[]ManagedBackupShortTermRetentionPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedBackupShortTermRetentionPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ManagedBackupShortTermRetentionPolicyOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedBackupShortTermRetentionPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate ManagedBackupShortTermRetentionPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedBackupShortTermRetentionPolicy, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_update.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_update.go new file mode 100644 index 00000000000..fa0a7cba6f8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/method_update.go @@ -0,0 +1,76 @@ +package managedbackupshorttermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedBackupShortTermRetentionPolicy +} + +// Update ... +func (c ManagedBackupShortTermRetentionPoliciesClient) Update(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedBackupShortTermRetentionPolicy) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ManagedBackupShortTermRetentionPoliciesClient) UpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedBackupShortTermRetentionPolicy) 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/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go new file mode 100644 index 00000000000..9550c29a4e0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go @@ -0,0 +1,11 @@ +package managedbackupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedBackupShortTermRetentionPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedBackupShortTermRetentionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go new file mode 100644 index 00000000000..c7e8ce4271d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go @@ -0,0 +1,8 @@ +package managedbackupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedBackupShortTermRetentionPolicyProperties struct { + RetentionDays *int64 `json:"retentionDays,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/predicates.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/predicates.go new file mode 100644 index 00000000000..fb75828a875 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/predicates.go @@ -0,0 +1,27 @@ +package managedbackupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedBackupShortTermRetentionPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedBackupShortTermRetentionPolicyOperationPredicate) Matches(input ManagedBackupShortTermRetentionPolicy) 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/sql/2023-08-01/managedbackupshorttermretentionpolicies/version.go b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/version.go new file mode 100644 index 00000000000..30090133bf5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedbackupshorttermretentionpolicies/version.go @@ -0,0 +1,10 @@ +package managedbackupshorttermretentionpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedbackupshorttermretentionpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..cf329e9ff4e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings` Documentation + +The `manageddatabaseadvancedthreatprotectionsettings` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := manageddatabaseadvancedthreatprotectionsettings.NewManagedDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabaseadvancedthreatprotectionsettings.ManagedDatabaseAdvancedThreatProtection{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseAdvancedThreatProtectionSettingsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedDatabaseAdvancedThreatProtectionSettingsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..41a8c523116 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/client.go @@ -0,0 +1,26 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 ManagedDatabaseAdvancedThreatProtectionSettingsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseAdvancedThreatProtectionSettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabaseadvancedthreatprotectionsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseAdvancedThreatProtectionSettingsClient: %+v", err) + } + + return &ManagedDatabaseAdvancedThreatProtectionSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..141a6cd1b84 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/constants.go @@ -0,0 +1,54 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 AdvancedThreatProtectionState string + +const ( + AdvancedThreatProtectionStateDisabled AdvancedThreatProtectionState = "Disabled" + AdvancedThreatProtectionStateEnabled AdvancedThreatProtectionState = "Enabled" + AdvancedThreatProtectionStateNew AdvancedThreatProtectionState = "New" +) + +func PossibleValuesForAdvancedThreatProtectionState() []string { + return []string{ + string(AdvancedThreatProtectionStateDisabled), + string(AdvancedThreatProtectionStateEnabled), + string(AdvancedThreatProtectionStateNew), + } +} + +func (s *AdvancedThreatProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvancedThreatProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvancedThreatProtectionState(input string) (*AdvancedThreatProtectionState, error) { + vals := map[string]AdvancedThreatProtectionState{ + "disabled": AdvancedThreatProtectionStateDisabled, + "enabled": AdvancedThreatProtectionStateEnabled, + "new": AdvancedThreatProtectionStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvancedThreatProtectionState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..3b9adb2f117 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go @@ -0,0 +1,60 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabaseAdvancedThreatProtection +} + +// CreateOrUpdate ... +func (c ManagedDatabaseAdvancedThreatProtectionSettingsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseAdvancedThreatProtection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 ManagedDatabaseAdvancedThreatProtection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..4bcb6059d45 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,55 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabaseAdvancedThreatProtection +} + +// Get ... +func (c ManagedDatabaseAdvancedThreatProtectionSettingsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 ManagedDatabaseAdvancedThreatProtection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go new file mode 100644 index 00000000000..b26815f2481 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go @@ -0,0 +1,106 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedDatabaseAdvancedThreatProtection +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedDatabaseAdvancedThreatProtection +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseAdvancedThreatProtectionSettingsClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings", 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 *[]ManagedDatabaseAdvancedThreatProtection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseAdvancedThreatProtectionSettingsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ManagedDatabaseAdvancedThreatProtectionOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseAdvancedThreatProtectionSettingsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate ManagedDatabaseAdvancedThreatProtectionOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedDatabaseAdvancedThreatProtection, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..e3ea0ac4686 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go @@ -0,0 +1,27 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 AdvancedThreatProtectionProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + State AdvancedThreatProtectionState `json:"state"` +} + +func (o *AdvancedThreatProtectionProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AdvancedThreatProtectionProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go new file mode 100644 index 00000000000..f19a3c27219 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go @@ -0,0 +1,16 @@ +package manageddatabaseadvancedthreatprotectionsettings + +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 ManagedDatabaseAdvancedThreatProtection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvancedThreatProtectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..01d13385d0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/predicates.go @@ -0,0 +1,27 @@ +package manageddatabaseadvancedthreatprotectionsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseAdvancedThreatProtectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedDatabaseAdvancedThreatProtectionOperationPredicate) Matches(input ManagedDatabaseAdvancedThreatProtection) 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/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..ddcfafd2353 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseadvancedthreatprotectionsettings/version.go @@ -0,0 +1,10 @@ +package manageddatabaseadvancedthreatprotectionsettings + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabaseadvancedthreatprotectionsettings/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/README.md b/resource-manager/sql/2023-08-01/manageddatabasecolumns/README.md new file mode 100644 index 00000000000..8a7ad0c8249 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasecolumns` Documentation + +The `manageddatabasecolumns` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasecolumns" +``` + + +### Client Initialization + +```go +client := manageddatabasecolumns.NewManagedDatabaseColumnsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseColumnsClient.Get` + +```go +ctx := context.TODO() +id := manageddatabasecolumns.NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + +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: `ManagedDatabaseColumnsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, manageddatabasecolumns.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, manageddatabasecolumns.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedDatabaseColumnsClient.ListByTable` + +```go +ctx := context.TODO() +id := manageddatabasecolumns.NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName") + +// alternatively `client.ListByTable(ctx, id, manageddatabasecolumns.DefaultListByTableOperationOptions())` can be used to do batched pagination +items, err := client.ListByTableComplete(ctx, id, manageddatabasecolumns.DefaultListByTableOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/client.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/client.go new file mode 100644 index 00000000000..6fdc391a24c --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/client.go @@ -0,0 +1,26 @@ +package manageddatabasecolumns + +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 ManagedDatabaseColumnsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseColumnsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseColumnsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasecolumns", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseColumnsClient: %+v", err) + } + + return &ManagedDatabaseColumnsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/constants.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/constants.go new file mode 100644 index 00000000000..14c17637290 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/constants.go @@ -0,0 +1,191 @@ +package manageddatabasecolumns + +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 ColumnDataType string + +const ( + ColumnDataTypeBigint ColumnDataType = "bigint" + ColumnDataTypeBinary ColumnDataType = "binary" + ColumnDataTypeBit ColumnDataType = "bit" + ColumnDataTypeChar ColumnDataType = "char" + ColumnDataTypeDate ColumnDataType = "date" + ColumnDataTypeDatetime ColumnDataType = "datetime" + ColumnDataTypeDatetimeTwo ColumnDataType = "datetime2" + ColumnDataTypeDatetimeoffset ColumnDataType = "datetimeoffset" + ColumnDataTypeDecimal ColumnDataType = "decimal" + ColumnDataTypeFloat ColumnDataType = "float" + ColumnDataTypeGeography ColumnDataType = "geography" + ColumnDataTypeGeometry ColumnDataType = "geometry" + ColumnDataTypeHierarchyid ColumnDataType = "hierarchyid" + ColumnDataTypeImage ColumnDataType = "image" + ColumnDataTypeInt ColumnDataType = "int" + ColumnDataTypeMoney ColumnDataType = "money" + ColumnDataTypeNchar ColumnDataType = "nchar" + ColumnDataTypeNtext ColumnDataType = "ntext" + ColumnDataTypeNumeric ColumnDataType = "numeric" + ColumnDataTypeNvarchar ColumnDataType = "nvarchar" + ColumnDataTypeReal ColumnDataType = "real" + ColumnDataTypeSmalldatetime ColumnDataType = "smalldatetime" + ColumnDataTypeSmallint ColumnDataType = "smallint" + ColumnDataTypeSmallmoney ColumnDataType = "smallmoney" + ColumnDataTypeSqlVariant ColumnDataType = "sql_variant" + ColumnDataTypeSysname ColumnDataType = "sysname" + ColumnDataTypeText ColumnDataType = "text" + ColumnDataTypeTime ColumnDataType = "time" + ColumnDataTypeTimestamp ColumnDataType = "timestamp" + ColumnDataTypeTinyint ColumnDataType = "tinyint" + ColumnDataTypeUniqueidentifier ColumnDataType = "uniqueidentifier" + ColumnDataTypeVarbinary ColumnDataType = "varbinary" + ColumnDataTypeVarchar ColumnDataType = "varchar" + ColumnDataTypeXml ColumnDataType = "xml" +) + +func PossibleValuesForColumnDataType() []string { + return []string{ + string(ColumnDataTypeBigint), + string(ColumnDataTypeBinary), + string(ColumnDataTypeBit), + string(ColumnDataTypeChar), + string(ColumnDataTypeDate), + string(ColumnDataTypeDatetime), + string(ColumnDataTypeDatetimeTwo), + string(ColumnDataTypeDatetimeoffset), + string(ColumnDataTypeDecimal), + string(ColumnDataTypeFloat), + string(ColumnDataTypeGeography), + string(ColumnDataTypeGeometry), + string(ColumnDataTypeHierarchyid), + string(ColumnDataTypeImage), + string(ColumnDataTypeInt), + string(ColumnDataTypeMoney), + string(ColumnDataTypeNchar), + string(ColumnDataTypeNtext), + string(ColumnDataTypeNumeric), + string(ColumnDataTypeNvarchar), + string(ColumnDataTypeReal), + string(ColumnDataTypeSmalldatetime), + string(ColumnDataTypeSmallint), + string(ColumnDataTypeSmallmoney), + string(ColumnDataTypeSqlVariant), + string(ColumnDataTypeSysname), + string(ColumnDataTypeText), + string(ColumnDataTypeTime), + string(ColumnDataTypeTimestamp), + string(ColumnDataTypeTinyint), + string(ColumnDataTypeUniqueidentifier), + string(ColumnDataTypeVarbinary), + string(ColumnDataTypeVarchar), + string(ColumnDataTypeXml), + } +} + +func (s *ColumnDataType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseColumnDataType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseColumnDataType(input string) (*ColumnDataType, error) { + vals := map[string]ColumnDataType{ + "bigint": ColumnDataTypeBigint, + "binary": ColumnDataTypeBinary, + "bit": ColumnDataTypeBit, + "char": ColumnDataTypeChar, + "date": ColumnDataTypeDate, + "datetime": ColumnDataTypeDatetime, + "datetime2": ColumnDataTypeDatetimeTwo, + "datetimeoffset": ColumnDataTypeDatetimeoffset, + "decimal": ColumnDataTypeDecimal, + "float": ColumnDataTypeFloat, + "geography": ColumnDataTypeGeography, + "geometry": ColumnDataTypeGeometry, + "hierarchyid": ColumnDataTypeHierarchyid, + "image": ColumnDataTypeImage, + "int": ColumnDataTypeInt, + "money": ColumnDataTypeMoney, + "nchar": ColumnDataTypeNchar, + "ntext": ColumnDataTypeNtext, + "numeric": ColumnDataTypeNumeric, + "nvarchar": ColumnDataTypeNvarchar, + "real": ColumnDataTypeReal, + "smalldatetime": ColumnDataTypeSmalldatetime, + "smallint": ColumnDataTypeSmallint, + "smallmoney": ColumnDataTypeSmallmoney, + "sql_variant": ColumnDataTypeSqlVariant, + "sysname": ColumnDataTypeSysname, + "text": ColumnDataTypeText, + "time": ColumnDataTypeTime, + "timestamp": ColumnDataTypeTimestamp, + "tinyint": ColumnDataTypeTinyint, + "uniqueidentifier": ColumnDataTypeUniqueidentifier, + "varbinary": ColumnDataTypeVarbinary, + "varchar": ColumnDataTypeVarchar, + "xml": ColumnDataTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ColumnDataType(input) + return &out, nil +} + +type TableTemporalType string + +const ( + TableTemporalTypeHistoryTable TableTemporalType = "HistoryTable" + TableTemporalTypeNonTemporalTable TableTemporalType = "NonTemporalTable" + TableTemporalTypeSystemVersionedTemporalTable TableTemporalType = "SystemVersionedTemporalTable" +) + +func PossibleValuesForTableTemporalType() []string { + return []string{ + string(TableTemporalTypeHistoryTable), + string(TableTemporalTypeNonTemporalTable), + string(TableTemporalTypeSystemVersionedTemporalTable), + } +} + +func (s *TableTemporalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTableTemporalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTableTemporalType(input string) (*TableTemporalType, error) { + vals := map[string]TableTemporalType{ + "historytable": TableTemporalTypeHistoryTable, + "nontemporaltable": TableTemporalTypeNonTemporalTable, + "systemversionedtemporaltable": TableTemporalTypeSystemVersionedTemporalTable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TableTemporalType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable.go new file mode 100644 index 00000000000..89bb01d0098 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable.go @@ -0,0 +1,157 @@ +package manageddatabasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SchemaTableId{}) +} + +var _ resourceids.ResourceId = &SchemaTableId{} + +// SchemaTableId is a struct representing the Resource ID for a Schema Table +type SchemaTableId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string + TableName string +} + +// NewSchemaTableID returns a new SchemaTableId struct +func NewSchemaTableID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string, tableName string) SchemaTableId { + return SchemaTableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + } +} + +// ParseSchemaTableID parses 'input' into a SchemaTableId +func ParseSchemaTableID(input string) (*SchemaTableId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaTableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaTableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaTableIDInsensitively parses 'input' case-insensitively into a SchemaTableId +// note: this method should only be used for API response data and not user input +func ParseSchemaTableIDInsensitively(input string) (*SchemaTableId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaTableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaTableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaTableId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateSchemaTableID checks that 'input' can be parsed as a Schema Table ID +func ValidateSchemaTableID(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 := ParseSchemaTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema Table ID +func (id SchemaTableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema Table ID +func (id SchemaTableId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + } +} + +// String returns a human-readable description of this Schema Table ID +func (id SchemaTableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Schema Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable_test.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable_test.go new file mode 100644 index 00000000000..5dbcc1f7344 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_schematable_test.go @@ -0,0 +1,417 @@ +package manageddatabasecolumns + +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 = &SchemaTableId{} + +func TestNewSchemaTableID(t *testing.T) { + id := NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } +} + +func TestFormatSchemaTableID(t *testing.T) { + actual := NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaTableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaTableID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseSchemaTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaTableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaTableIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForSchemaTableId(t *testing.T) { + segments := SchemaTableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaTableId 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/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn.go new file mode 100644 index 00000000000..67a05249968 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn.go @@ -0,0 +1,166 @@ +package manageddatabasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TableColumnId{}) +} + +var _ resourceids.ResourceId = &TableColumnId{} + +// TableColumnId is a struct representing the Resource ID for a Table Column +type TableColumnId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string + TableName string + ColumnName string +} + +// NewTableColumnID returns a new TableColumnId struct +func NewTableColumnID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string, tableName string, columnName string) TableColumnId { + return TableColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseTableColumnID parses 'input' into a TableColumnId +func ParseTableColumnID(input string) (*TableColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableColumnIDInsensitively parses 'input' case-insensitively into a TableColumnId +// note: this method should only be used for API response data and not user input +func ParseTableColumnIDInsensitively(input string) (*TableColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableColumnId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateTableColumnID checks that 'input' can be parsed as a Table Column ID +func ValidateTableColumnID(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 := ParseTableColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table Column ID +func (id TableColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table Column ID +func (id TableColumnId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnName"), + } +} + +// String returns a human-readable description of this Table Column ID +func (id TableColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Table Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn_test.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn_test.go new file mode 100644 index 00000000000..6f7f6600d60 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/id_tablecolumn_test.go @@ -0,0 +1,462 @@ +package manageddatabasecolumns + +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 = &TableColumnId{} + +func TestNewTableColumnID(t *testing.T) { + id := NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } + + if id.ColumnName != "columnName" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnName") + } +} + +func TestFormatTableColumnID(t *testing.T) { + actual := NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableColumnID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseTableColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + ColumnName: "cOlUmNnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableColumnIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForTableColumnId(t *testing.T) { + segments := TableColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableColumnId 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/sql/2023-08-01/manageddatabasecolumns/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_get.go new file mode 100644 index 00000000000..1e2e25f1994 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_get.go @@ -0,0 +1,53 @@ +package manageddatabasecolumns + +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 *DatabaseColumn +} + +// Get ... +func (c ManagedDatabaseColumnsClient) Get(ctx context.Context, id TableColumnId) (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 DatabaseColumn + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbydatabase.go new file mode 100644 index 00000000000..2620f38e1cc --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbydatabase.go @@ -0,0 +1,147 @@ +package manageddatabasecolumns + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseColumn +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseColumn +} + +type ListByDatabaseOperationOptions struct { + Column *[]string + OrderBy *[]string + Schema *[]string + Table *[]string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Column != nil { + out.Append("column", fmt.Sprintf("%v", *o.Column)) + } + if o.OrderBy != nil { + out.Append("orderBy", fmt.Sprintf("%v", *o.OrderBy)) + } + if o.Schema != nil { + out.Append("schema", fmt.Sprintf("%v", *o.Schema)) + } + if o.Table != nil { + out.Append("table", fmt.Sprintf("%v", *o.Table)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseColumnsClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/columns", 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 *[]DatabaseColumn `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseColumnsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, DatabaseColumnOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseColumnsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions, predicate DatabaseColumnOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseColumn, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbytable.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbytable.go new file mode 100644 index 00000000000..d8d08906955 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/method_listbytable.go @@ -0,0 +1,134 @@ +package manageddatabasecolumns + +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 ListByTableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseColumn +} + +type ListByTableCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseColumn +} + +type ListByTableOperationOptions struct { + Filter *string +} + +func DefaultListByTableOperationOptions() ListByTableOperationOptions { + return ListByTableOperationOptions{} +} + +func (o ListByTableOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByTableOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByTableOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByTableCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTableCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByTable ... +func (c ManagedDatabaseColumnsClient) ListByTable(ctx context.Context, id SchemaTableId, options ListByTableOperationOptions) (result ListByTableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByTableCustomPager{}, + Path: fmt.Sprintf("%s/columns", 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 *[]DatabaseColumn `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTableComplete retrieves all the results into a single object +func (c ManagedDatabaseColumnsClient) ListByTableComplete(ctx context.Context, id SchemaTableId, options ListByTableOperationOptions) (ListByTableCompleteResult, error) { + return c.ListByTableCompleteMatchingPredicate(ctx, id, options, DatabaseColumnOperationPredicate{}) +} + +// ListByTableCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseColumnsClient) ListByTableCompleteMatchingPredicate(ctx context.Context, id SchemaTableId, options ListByTableOperationOptions, predicate DatabaseColumnOperationPredicate) (result ListByTableCompleteResult, err error) { + items := make([]DatabaseColumn, 0) + + resp, err := c.ListByTable(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTableCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumn.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumn.go new file mode 100644 index 00000000000..b27aedc29e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumn.go @@ -0,0 +1,11 @@ +package manageddatabasecolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseColumn struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseColumnProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumnproperties.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumnproperties.go new file mode 100644 index 00000000000..454c38c4e8e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/model_databasecolumnproperties.go @@ -0,0 +1,11 @@ +package manageddatabasecolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseColumnProperties struct { + ColumnType *ColumnDataType `json:"columnType,omitempty"` + IsComputed *bool `json:"isComputed,omitempty"` + MemoryOptimized *bool `json:"memoryOptimized,omitempty"` + TemporalType *TableTemporalType `json:"temporalType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasecolumns/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/predicates.go new file mode 100644 index 00000000000..e10d2347ca2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasecolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseColumnOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseColumnOperationPredicate) Matches(input DatabaseColumn) 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/sql/2023-08-01/manageddatabasecolumns/version.go b/resource-manager/sql/2023-08-01/manageddatabasecolumns/version.go new file mode 100644 index 00000000000..2d157577554 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasecolumns/version.go @@ -0,0 +1,10 @@ +package manageddatabasecolumns + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasecolumns/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/README.md b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/README.md new file mode 100644 index 00000000000..a5084a79b10 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasemoveoperations` Documentation + +The `manageddatabasemoveoperations` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasemoveoperations" +``` + + +### Client Initialization + +```go +client := manageddatabasemoveoperations.NewManagedDatabaseMoveOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseMoveOperationsClient.ListByLocation` + +```go +ctx := context.TODO() +id := manageddatabasemoveoperations.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +// alternatively `client.ListByLocation(ctx, id, manageddatabasemoveoperations.DefaultListByLocationOperationOptions())` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id, manageddatabasemoveoperations.DefaultListByLocationOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/client.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/client.go new file mode 100644 index 00000000000..b92d919387d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/client.go @@ -0,0 +1,26 @@ +package manageddatabasemoveoperations + +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 ManagedDatabaseMoveOperationsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseMoveOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseMoveOperationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasemoveoperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseMoveOperationsClient: %+v", err) + } + + return &ManagedDatabaseMoveOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/constants.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/constants.go new file mode 100644 index 00000000000..b275380414e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/constants.go @@ -0,0 +1,104 @@ +package manageddatabasemoveoperations + +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 ManagementOperationState string + +const ( + ManagementOperationStateCancelInProgress ManagementOperationState = "CancelInProgress" + ManagementOperationStateCancelled ManagementOperationState = "Cancelled" + ManagementOperationStateFailed ManagementOperationState = "Failed" + ManagementOperationStateInProgress ManagementOperationState = "InProgress" + ManagementOperationStatePending ManagementOperationState = "Pending" + ManagementOperationStateSucceeded ManagementOperationState = "Succeeded" +) + +func PossibleValuesForManagementOperationState() []string { + return []string{ + string(ManagementOperationStateCancelInProgress), + string(ManagementOperationStateCancelled), + string(ManagementOperationStateFailed), + string(ManagementOperationStateInProgress), + string(ManagementOperationStatePending), + string(ManagementOperationStateSucceeded), + } +} + +func (s *ManagementOperationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagementOperationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagementOperationState(input string) (*ManagementOperationState, error) { + vals := map[string]ManagementOperationState{ + "cancelinprogress": ManagementOperationStateCancelInProgress, + "cancelled": ManagementOperationStateCancelled, + "failed": ManagementOperationStateFailed, + "inprogress": ManagementOperationStateInProgress, + "pending": ManagementOperationStatePending, + "succeeded": ManagementOperationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagementOperationState(input) + return &out, nil +} + +type MoveOperationMode string + +const ( + MoveOperationModeCopy MoveOperationMode = "Copy" + MoveOperationModeMove MoveOperationMode = "Move" +) + +func PossibleValuesForMoveOperationMode() []string { + return []string{ + string(MoveOperationModeCopy), + string(MoveOperationModeMove), + } +} + +func (s *MoveOperationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMoveOperationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMoveOperationMode(input string) (*MoveOperationMode, error) { + vals := map[string]MoveOperationMode{ + "copy": MoveOperationModeCopy, + "move": MoveOperationModeMove, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MoveOperationMode(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation.go new file mode 100644 index 00000000000..2e3d98ea98b --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation.go @@ -0,0 +1,130 @@ +package manageddatabasemoveoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation_test.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation_test.go new file mode 100644 index 00000000000..25ac3991e2d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package manageddatabasemoveoperations + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/sql/2023-08-01/manageddatabasemoveoperations/method_listbylocation.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/method_listbylocation.go new file mode 100644 index 00000000000..658e4700de9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/method_listbylocation.go @@ -0,0 +1,138 @@ +package manageddatabasemoveoperations + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedDatabaseMoveOperationResult +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedDatabaseMoveOperationResult +} + +type ListByLocationOperationOptions struct { + Filter *string + OnlyLatestPerDatabase *bool +} + +func DefaultListByLocationOperationOptions() ListByLocationOperationOptions { + return ListByLocationOperationOptions{} +} + +func (o ListByLocationOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByLocationOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByLocationOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.OnlyLatestPerDatabase != nil { + out.Append("onlyLatestPerDatabase", fmt.Sprintf("%v", *o.OnlyLatestPerDatabase)) + } + return &out +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c ManagedDatabaseMoveOperationsClient) ListByLocation(ctx context.Context, id ProviderLocationId, options ListByLocationOperationOptions) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/managedDatabaseMoveOperationResults", 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 *[]ManagedDatabaseMoveOperationResult `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c ManagedDatabaseMoveOperationsClient) ListByLocationComplete(ctx context.Context, id ProviderLocationId, options ListByLocationOperationOptions) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, options, ManagedDatabaseMoveOperationResultOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseMoveOperationsClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, options ListByLocationOperationOptions, predicate ManagedDatabaseMoveOperationResultOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]ManagedDatabaseMoveOperationResult, 0) + + resp, err := c.ListByLocation(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go new file mode 100644 index 00000000000..afbabae9e90 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go @@ -0,0 +1,11 @@ +package manageddatabasemoveoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseMoveOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedDatabaseMoveOperationResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go new file mode 100644 index 00000000000..38ad3a40c51 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go @@ -0,0 +1,41 @@ +package manageddatabasemoveoperations + +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 ManagedDatabaseMoveOperationResultProperties struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorDescription *string `json:"errorDescription,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + IsCancellable *bool `json:"isCancellable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Operation *string `json:"operation,omitempty"` + OperationFriendlyName *string `json:"operationFriendlyName,omitempty"` + OperationMode *MoveOperationMode `json:"operationMode,omitempty"` + SourceDatabaseName *string `json:"sourceDatabaseName,omitempty"` + SourceManagedInstanceId *string `json:"sourceManagedInstanceId,omitempty"` + SourceManagedInstanceName *string `json:"sourceManagedInstanceName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *ManagementOperationState `json:"state,omitempty"` + TargetDatabaseName *string `json:"targetDatabaseName,omitempty"` + TargetManagedInstanceId *string `json:"targetManagedInstanceId,omitempty"` + TargetManagedInstanceName *string `json:"targetManagedInstanceName,omitempty"` +} + +func (o *ManagedDatabaseMoveOperationResultProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseMoveOperationResultProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/predicates.go new file mode 100644 index 00000000000..1682e1d3047 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasemoveoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseMoveOperationResultOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedDatabaseMoveOperationResultOperationPredicate) Matches(input ManagedDatabaseMoveOperationResult) 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/sql/2023-08-01/manageddatabasemoveoperations/version.go b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/version.go new file mode 100644 index 00000000000..f4fbaea3fa1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasemoveoperations/version.go @@ -0,0 +1,10 @@ +package manageddatabasemoveoperations + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasemoveoperations/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/README.md b/resource-manager/sql/2023-08-01/manageddatabasequeries/README.md new file mode 100644 index 00000000000..b5724836d5f --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasequeries` Documentation + +The `manageddatabasequeries` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasequeries" +``` + + +### Client Initialization + +```go +client := manageddatabasequeries.NewManagedDatabaseQueriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseQueriesClient.Get` + +```go +ctx := context.TODO() +id := manageddatabasequeries.NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "queryId") + +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: `ManagedDatabaseQueriesClient.ListByQuery` + +```go +ctx := context.TODO() +id := manageddatabasequeries.NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "queryId") + +// alternatively `client.ListByQuery(ctx, id, manageddatabasequeries.DefaultListByQueryOperationOptions())` can be used to do batched pagination +items, err := client.ListByQueryComplete(ctx, id, manageddatabasequeries.DefaultListByQueryOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/client.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/client.go new file mode 100644 index 00000000000..02f2d413407 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/client.go @@ -0,0 +1,26 @@ +package manageddatabasequeries + +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 ManagedDatabaseQueriesClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseQueriesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseQueriesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasequeries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseQueriesClient: %+v", err) + } + + return &ManagedDatabaseQueriesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/constants.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/constants.go new file mode 100644 index 00000000000..6d340d927f7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/constants.go @@ -0,0 +1,98 @@ +package manageddatabasequeries + +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 QueryMetricUnitType string + +const ( + QueryMetricUnitTypeCount QueryMetricUnitType = "count" + QueryMetricUnitTypeKB QueryMetricUnitType = "KB" + QueryMetricUnitTypeMicroseconds QueryMetricUnitType = "microseconds" + QueryMetricUnitTypePercentage QueryMetricUnitType = "percentage" +) + +func PossibleValuesForQueryMetricUnitType() []string { + return []string{ + string(QueryMetricUnitTypeCount), + string(QueryMetricUnitTypeKB), + string(QueryMetricUnitTypeMicroseconds), + string(QueryMetricUnitTypePercentage), + } +} + +func (s *QueryMetricUnitType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryMetricUnitType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryMetricUnitType(input string) (*QueryMetricUnitType, error) { + vals := map[string]QueryMetricUnitType{ + "count": QueryMetricUnitTypeCount, + "kb": QueryMetricUnitTypeKB, + "microseconds": QueryMetricUnitTypeMicroseconds, + "percentage": QueryMetricUnitTypePercentage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryMetricUnitType(input) + return &out, nil +} + +type QueryTimeGrainType string + +const ( + QueryTimeGrainTypePOneD QueryTimeGrainType = "P1D" + QueryTimeGrainTypePTOneH QueryTimeGrainType = "PT1H" +) + +func PossibleValuesForQueryTimeGrainType() []string { + return []string{ + string(QueryTimeGrainTypePOneD), + string(QueryTimeGrainTypePTOneH), + } +} + +func (s *QueryTimeGrainType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryTimeGrainType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryTimeGrainType(input string) (*QueryTimeGrainType, error) { + vals := map[string]QueryTimeGrainType{ + "p1d": QueryTimeGrainTypePOneD, + "pt1h": QueryTimeGrainTypePTOneH, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryTimeGrainType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/id_query.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/id_query.go new file mode 100644 index 00000000000..e1871cd0177 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/id_query.go @@ -0,0 +1,148 @@ +package manageddatabasequeries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&QueryId{}) +} + +var _ resourceids.ResourceId = &QueryId{} + +// QueryId is a struct representing the Resource ID for a Query +type QueryId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + QueryId string +} + +// NewQueryID returns a new QueryId struct +func NewQueryID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, queryId string) QueryId { + return QueryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + QueryId: queryId, + } +} + +// ParseQueryID parses 'input' into a QueryId +func ParseQueryID(input string) (*QueryId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseQueryIDInsensitively parses 'input' case-insensitively into a QueryId +// note: this method should only be used for API response data and not user input +func ParseQueryIDInsensitively(input string) (*QueryId, error) { + parser := resourceids.NewParserFromResourceIdType(&QueryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := QueryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *QueryId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.QueryId, ok = input.Parsed["queryId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "queryId", input) + } + + return nil +} + +// ValidateQueryID checks that 'input' can be parsed as a Query ID +func ValidateQueryID(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 := ParseQueryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Query ID +func (id QueryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/queries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.QueryId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Query ID +func (id QueryId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticQueries", "queries", "queries"), + resourceids.UserSpecifiedSegment("queryId", "queryId"), + } +} + +// String returns a human-readable description of this Query ID +func (id QueryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Query: %q", id.QueryId), + } + return fmt.Sprintf("Query (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/id_query_test.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/id_query_test.go new file mode 100644 index 00000000000..1c167f86574 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/id_query_test.go @@ -0,0 +1,372 @@ +package manageddatabasequeries + +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 = &QueryId{} + +func TestNewQueryID(t *testing.T) { + id := NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "queryId") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.QueryId != "queryId" { + t.Fatalf("Expected %q but got %q for Segment 'QueryId'", id.QueryId, "queryId") + } +} + +func TestFormatQueryID(t *testing.T) { + actual := NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "queryId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries/queryId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseQueryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries/queryId", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + QueryId: "queryId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries/queryId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.QueryId != v.Expected.QueryId { + t.Fatalf("Expected %q but got %q for QueryId", v.Expected.QueryId, actual.QueryId) + } + + } +} + +func TestParseQueryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *QueryId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/qUeRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries/queryId", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + QueryId: "queryId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/queries/queryId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/qUeRiEs/qUeRyId", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + QueryId: "qUeRyId", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/qUeRiEs/qUeRyId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseQueryIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.QueryId != v.Expected.QueryId { + t.Fatalf("Expected %q but got %q for QueryId", v.Expected.QueryId, actual.QueryId) + } + + } +} + +func TestSegmentsForQueryId(t *testing.T) { + segments := QueryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("QueryId 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/sql/2023-08-01/manageddatabasequeries/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/method_get.go new file mode 100644 index 00000000000..22ceda6679a --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/method_get.go @@ -0,0 +1,53 @@ +package manageddatabasequeries + +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 *ManagedInstanceQuery +} + +// Get ... +func (c ManagedDatabaseQueriesClient) Get(ctx context.Context, id QueryId) (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 ManagedInstanceQuery + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/method_listbyquery.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/method_listbyquery.go new file mode 100644 index 00000000000..9e1b714038e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/method_listbyquery.go @@ -0,0 +1,142 @@ +package manageddatabasequeries + +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 ListByQueryOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]QueryStatistics +} + +type ListByQueryCompleteResult struct { + LatestHttpResponse *http.Response + Items []QueryStatistics +} + +type ListByQueryOperationOptions struct { + EndTime *string + Interval *QueryTimeGrainType + StartTime *string +} + +func DefaultListByQueryOperationOptions() ListByQueryOperationOptions { + return ListByQueryOperationOptions{} +} + +func (o ListByQueryOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByQueryOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByQueryOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.EndTime != nil { + out.Append("endTime", fmt.Sprintf("%v", *o.EndTime)) + } + if o.Interval != nil { + out.Append("interval", fmt.Sprintf("%v", *o.Interval)) + } + if o.StartTime != nil { + out.Append("startTime", fmt.Sprintf("%v", *o.StartTime)) + } + return &out +} + +type ListByQueryCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByQueryCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByQuery ... +func (c ManagedDatabaseQueriesClient) ListByQuery(ctx context.Context, id QueryId, options ListByQueryOperationOptions) (result ListByQueryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByQueryCustomPager{}, + Path: fmt.Sprintf("%s/statistics", 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 *[]QueryStatistics `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByQueryComplete retrieves all the results into a single object +func (c ManagedDatabaseQueriesClient) ListByQueryComplete(ctx context.Context, id QueryId, options ListByQueryOperationOptions) (ListByQueryCompleteResult, error) { + return c.ListByQueryCompleteMatchingPredicate(ctx, id, options, QueryStatisticsOperationPredicate{}) +} + +// ListByQueryCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseQueriesClient) ListByQueryCompleteMatchingPredicate(ctx context.Context, id QueryId, options ListByQueryOperationOptions, predicate QueryStatisticsOperationPredicate) (result ListByQueryCompleteResult, err error) { + items := make([]QueryStatistics, 0) + + resp, err := c.ListByQuery(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByQueryCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/model_managedinstancequery.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_managedinstancequery.go new file mode 100644 index 00000000000..cffc6cb08e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_managedinstancequery.go @@ -0,0 +1,11 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceQuery struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *QueryProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricinterval.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricinterval.go new file mode 100644 index 00000000000..ab08cc1d0c9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricinterval.go @@ -0,0 +1,11 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryMetricInterval struct { + ExecutionCount *int64 `json:"executionCount,omitempty"` + IntervalStartTime *string `json:"intervalStartTime,omitempty"` + IntervalType *QueryTimeGrainType `json:"intervalType,omitempty"` + Metrics *[]QueryMetricProperties `json:"metrics,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricproperties.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricproperties.go new file mode 100644 index 00000000000..caa59789a77 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querymetricproperties.go @@ -0,0 +1,16 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryMetricProperties struct { + Avg *float64 `json:"avg,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Max *float64 `json:"max,omitempty"` + Min *float64 `json:"min,omitempty"` + Name *string `json:"name,omitempty"` + Stdev *float64 `json:"stdev,omitempty"` + Sum *float64 `json:"sum,omitempty"` + Unit *QueryMetricUnitType `json:"unit,omitempty"` + Value *float64 `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/model_queryproperties.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_queryproperties.go new file mode 100644 index 00000000000..298ae43a9f4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_queryproperties.go @@ -0,0 +1,8 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryProperties struct { + QueryText *string `json:"queryText,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatistics.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatistics.go new file mode 100644 index 00000000000..695bab8a5dd --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatistics.go @@ -0,0 +1,11 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryStatistics struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *QueryStatisticsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatisticsproperties.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatisticsproperties.go new file mode 100644 index 00000000000..a6e627372a5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/model_querystatisticsproperties.go @@ -0,0 +1,12 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryStatisticsProperties struct { + DatabaseName *string `json:"databaseName,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Intervals *[]QueryMetricInterval `json:"intervals,omitempty"` + QueryId *string `json:"queryId,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasequeries/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/predicates.go new file mode 100644 index 00000000000..e8225eeda46 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasequeries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryStatisticsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p QueryStatisticsOperationPredicate) Matches(input QueryStatistics) 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/sql/2023-08-01/manageddatabasequeries/version.go b/resource-manager/sql/2023-08-01/manageddatabasequeries/version.go new file mode 100644 index 00000000000..ba635784e94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasequeries/version.go @@ -0,0 +1,10 @@ +package manageddatabasequeries + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasequeries/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/README.md b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/README.md new file mode 100644 index 00000000000..433b11e6551 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaserestoredetails` Documentation + +The `manageddatabaserestoredetails` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaserestoredetails" +``` + + +### Client Initialization + +```go +client := manageddatabaserestoredetails.NewManagedDatabaseRestoreDetailsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseRestoreDetailsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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 +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/client.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/client.go new file mode 100644 index 00000000000..27cf405d0b9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/client.go @@ -0,0 +1,26 @@ +package manageddatabaserestoredetails + +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 ManagedDatabaseRestoreDetailsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseRestoreDetailsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseRestoreDetailsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabaserestoredetails", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseRestoreDetailsClient: %+v", err) + } + + return &ManagedDatabaseRestoreDetailsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/method_get.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/method_get.go new file mode 100644 index 00000000000..c20a048d179 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/method_get.go @@ -0,0 +1,55 @@ +package manageddatabaserestoredetails + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabaseRestoreDetailsResult +} + +// Get ... +func (c ManagedDatabaseRestoreDetailsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/restoreDetails/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 ManagedDatabaseRestoreDetailsResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go new file mode 100644 index 00000000000..f9636570daa --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go @@ -0,0 +1,43 @@ +package manageddatabaserestoredetails + +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 ManagedDatabaseRestoreDetailsBackupSetProperties struct { + BackupSizeMB *int64 `json:"backupSizeMB,omitempty"` + FirstStripeName *string `json:"firstStripeName,omitempty"` + NumberOfStripes *int64 `json:"numberOfStripes,omitempty"` + RestoreFinishedTimestampUtc *string `json:"restoreFinishedTimestampUtc,omitempty"` + RestoreStartedTimestampUtc *string `json:"restoreStartedTimestampUtc,omitempty"` + Status *string `json:"status,omitempty"` +} + +func (o *ManagedDatabaseRestoreDetailsBackupSetProperties) GetRestoreFinishedTimestampUtcAsTime() (*time.Time, error) { + if o.RestoreFinishedTimestampUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestoreFinishedTimestampUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseRestoreDetailsBackupSetProperties) SetRestoreFinishedTimestampUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestoreFinishedTimestampUtc = &formatted +} + +func (o *ManagedDatabaseRestoreDetailsBackupSetProperties) GetRestoreStartedTimestampUtcAsTime() (*time.Time, error) { + if o.RestoreStartedTimestampUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestoreStartedTimestampUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseRestoreDetailsBackupSetProperties) SetRestoreStartedTimestampUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestoreStartedTimestampUtc = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go new file mode 100644 index 00000000000..8eb4b726a88 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go @@ -0,0 +1,59 @@ +package manageddatabaserestoredetails + +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 ManagedDatabaseRestoreDetailsProperties struct { + BlockReason *string `json:"blockReason,omitempty"` + CurrentBackupType *string `json:"currentBackupType,omitempty"` + CurrentRestorePlanSizeMB *int64 `json:"currentRestorePlanSizeMB,omitempty"` + CurrentRestoredSizeMB *int64 `json:"currentRestoredSizeMB,omitempty"` + CurrentRestoringFileName *string `json:"currentRestoringFileName,omitempty"` + DiffBackupSets *[]ManagedDatabaseRestoreDetailsBackupSetProperties `json:"diffBackupSets,omitempty"` + FullBackupSets *[]ManagedDatabaseRestoreDetailsBackupSetProperties `json:"fullBackupSets,omitempty"` + LastRestoredFileName *string `json:"lastRestoredFileName,omitempty"` + LastRestoredFileTime *string `json:"lastRestoredFileTime,omitempty"` + LastUploadedFileName *string `json:"lastUploadedFileName,omitempty"` + LastUploadedFileTime *string `json:"lastUploadedFileTime,omitempty"` + LogBackupSets *[]ManagedDatabaseRestoreDetailsBackupSetProperties `json:"logBackupSets,omitempty"` + NumberOfFilesDetected *int64 `json:"numberOfFilesDetected,omitempty"` + NumberOfFilesQueued *int64 `json:"numberOfFilesQueued,omitempty"` + NumberOfFilesRestored *int64 `json:"numberOfFilesRestored,omitempty"` + NumberOfFilesRestoring *int64 `json:"numberOfFilesRestoring,omitempty"` + NumberOfFilesSkipped *int64 `json:"numberOfFilesSkipped,omitempty"` + NumberOfFilesUnrestorable *int64 `json:"numberOfFilesUnrestorable,omitempty"` + PercentCompleted *int64 `json:"percentCompleted,omitempty"` + Status *string `json:"status,omitempty"` + Type *string `json:"type,omitempty"` + UnrestorableFiles *[]ManagedDatabaseRestoreDetailsUnrestorableFileProperties `json:"unrestorableFiles,omitempty"` +} + +func (o *ManagedDatabaseRestoreDetailsProperties) GetLastRestoredFileTimeAsTime() (*time.Time, error) { + if o.LastRestoredFileTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRestoredFileTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseRestoreDetailsProperties) SetLastRestoredFileTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRestoredFileTime = &formatted +} + +func (o *ManagedDatabaseRestoreDetailsProperties) GetLastUploadedFileTimeAsTime() (*time.Time, error) { + if o.LastUploadedFileTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUploadedFileTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseRestoreDetailsProperties) SetLastUploadedFileTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUploadedFileTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go new file mode 100644 index 00000000000..c0aaaaf4c31 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go @@ -0,0 +1,11 @@ +package manageddatabaserestoredetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseRestoreDetailsResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedDatabaseRestoreDetailsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go new file mode 100644 index 00000000000..a23ad0e4081 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go @@ -0,0 +1,8 @@ +package manageddatabaserestoredetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseRestoreDetailsUnrestorableFileProperties struct { + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/version.go b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/version.go new file mode 100644 index 00000000000..4350f5bfa94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaserestoredetails/version.go @@ -0,0 +1,10 @@ +package manageddatabaserestoredetails + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabaserestoredetails/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/README.md b/resource-manager/sql/2023-08-01/manageddatabases/README.md new file mode 100644 index 00000000000..40d25f028d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/README.md @@ -0,0 +1,185 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabases` Documentation + +The `manageddatabases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabases" +``` + + +### Client Initialization + +```go +client := manageddatabases.NewManagedDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabasesClient.CancelMove` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabases.ManagedDatabaseMoveDefinition{ + // ... +} + + +if err := client.CancelMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.CompleteMove` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabases.ManagedDatabaseMoveDefinition{ + // ... +} + + +if err := client.CompleteMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.CompleteRestore` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabases.CompleteDatabaseRestoreDefinition{ + // ... +} + + +if err := client.CompleteRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabases.ManagedDatabase{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedDatabasesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedDatabasesClient.ListInaccessibleByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListInaccessibleByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListInaccessibleByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedDatabasesClient.StartMove` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabases.ManagedDatabaseStartMoveDefinition{ + // ... +} + + +if err := client.StartMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabases.ManagedDatabaseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabases/client.go b/resource-manager/sql/2023-08-01/manageddatabases/client.go new file mode 100644 index 00000000000..ba3a6da68af --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/client.go @@ -0,0 +1,26 @@ +package manageddatabases + +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 ManagedDatabasesClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabasesClient: %+v", err) + } + + return &ManagedDatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/constants.go b/resource-manager/sql/2023-08-01/manageddatabases/constants.go new file mode 100644 index 00000000000..9973e086db9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/constants.go @@ -0,0 +1,213 @@ +package manageddatabases + +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 CatalogCollationType string + +const ( + CatalogCollationTypeDATABASEDEFAULT CatalogCollationType = "DATABASE_DEFAULT" + CatalogCollationTypeSQLLatinOneGeneralCPOneCIAS CatalogCollationType = "SQL_Latin1_General_CP1_CI_AS" +) + +func PossibleValuesForCatalogCollationType() []string { + return []string{ + string(CatalogCollationTypeDATABASEDEFAULT), + string(CatalogCollationTypeSQLLatinOneGeneralCPOneCIAS), + } +} + +func (s *CatalogCollationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogCollationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogCollationType(input string) (*CatalogCollationType, error) { + vals := map[string]CatalogCollationType{ + "database_default": CatalogCollationTypeDATABASEDEFAULT, + "sql_latin1_general_cp1_ci_as": CatalogCollationTypeSQLLatinOneGeneralCPOneCIAS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogCollationType(input) + return &out, nil +} + +type ManagedDatabaseCreateMode string + +const ( + ManagedDatabaseCreateModeDefault ManagedDatabaseCreateMode = "Default" + ManagedDatabaseCreateModePointInTimeRestore ManagedDatabaseCreateMode = "PointInTimeRestore" + ManagedDatabaseCreateModeRecovery ManagedDatabaseCreateMode = "Recovery" + ManagedDatabaseCreateModeRestoreExternalBackup ManagedDatabaseCreateMode = "RestoreExternalBackup" + ManagedDatabaseCreateModeRestoreLongTermRetentionBackup ManagedDatabaseCreateMode = "RestoreLongTermRetentionBackup" +) + +func PossibleValuesForManagedDatabaseCreateMode() []string { + return []string{ + string(ManagedDatabaseCreateModeDefault), + string(ManagedDatabaseCreateModePointInTimeRestore), + string(ManagedDatabaseCreateModeRecovery), + string(ManagedDatabaseCreateModeRestoreExternalBackup), + string(ManagedDatabaseCreateModeRestoreLongTermRetentionBackup), + } +} + +func (s *ManagedDatabaseCreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedDatabaseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedDatabaseCreateMode(input string) (*ManagedDatabaseCreateMode, error) { + vals := map[string]ManagedDatabaseCreateMode{ + "default": ManagedDatabaseCreateModeDefault, + "pointintimerestore": ManagedDatabaseCreateModePointInTimeRestore, + "recovery": ManagedDatabaseCreateModeRecovery, + "restoreexternalbackup": ManagedDatabaseCreateModeRestoreExternalBackup, + "restorelongtermretentionbackup": ManagedDatabaseCreateModeRestoreLongTermRetentionBackup, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedDatabaseCreateMode(input) + return &out, nil +} + +type ManagedDatabaseStatus string + +const ( + ManagedDatabaseStatusCreating ManagedDatabaseStatus = "Creating" + ManagedDatabaseStatusDbCopying ManagedDatabaseStatus = "DbCopying" + ManagedDatabaseStatusDbMoving ManagedDatabaseStatus = "DbMoving" + ManagedDatabaseStatusInaccessible ManagedDatabaseStatus = "Inaccessible" + ManagedDatabaseStatusOffline ManagedDatabaseStatus = "Offline" + ManagedDatabaseStatusOnline ManagedDatabaseStatus = "Online" + ManagedDatabaseStatusRestoring ManagedDatabaseStatus = "Restoring" + ManagedDatabaseStatusShutdown ManagedDatabaseStatus = "Shutdown" + ManagedDatabaseStatusStarting ManagedDatabaseStatus = "Starting" + ManagedDatabaseStatusStopped ManagedDatabaseStatus = "Stopped" + ManagedDatabaseStatusStopping ManagedDatabaseStatus = "Stopping" + ManagedDatabaseStatusUpdating ManagedDatabaseStatus = "Updating" +) + +func PossibleValuesForManagedDatabaseStatus() []string { + return []string{ + string(ManagedDatabaseStatusCreating), + string(ManagedDatabaseStatusDbCopying), + string(ManagedDatabaseStatusDbMoving), + string(ManagedDatabaseStatusInaccessible), + string(ManagedDatabaseStatusOffline), + string(ManagedDatabaseStatusOnline), + string(ManagedDatabaseStatusRestoring), + string(ManagedDatabaseStatusShutdown), + string(ManagedDatabaseStatusStarting), + string(ManagedDatabaseStatusStopped), + string(ManagedDatabaseStatusStopping), + string(ManagedDatabaseStatusUpdating), + } +} + +func (s *ManagedDatabaseStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedDatabaseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedDatabaseStatus(input string) (*ManagedDatabaseStatus, error) { + vals := map[string]ManagedDatabaseStatus{ + "creating": ManagedDatabaseStatusCreating, + "dbcopying": ManagedDatabaseStatusDbCopying, + "dbmoving": ManagedDatabaseStatusDbMoving, + "inaccessible": ManagedDatabaseStatusInaccessible, + "offline": ManagedDatabaseStatusOffline, + "online": ManagedDatabaseStatusOnline, + "restoring": ManagedDatabaseStatusRestoring, + "shutdown": ManagedDatabaseStatusShutdown, + "starting": ManagedDatabaseStatusStarting, + "stopped": ManagedDatabaseStatusStopped, + "stopping": ManagedDatabaseStatusStopping, + "updating": ManagedDatabaseStatusUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedDatabaseStatus(input) + return &out, nil +} + +type MoveOperationMode string + +const ( + MoveOperationModeCopy MoveOperationMode = "Copy" + MoveOperationModeMove MoveOperationMode = "Move" +) + +func PossibleValuesForMoveOperationMode() []string { + return []string{ + string(MoveOperationModeCopy), + string(MoveOperationModeMove), + } +} + +func (s *MoveOperationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMoveOperationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMoveOperationMode(input string) (*MoveOperationMode, error) { + vals := map[string]MoveOperationMode{ + "copy": MoveOperationModeCopy, + "move": MoveOperationModeMove, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MoveOperationMode(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_cancelmove.go b/resource-manager/sql/2023-08-01/manageddatabases/method_cancelmove.go new file mode 100644 index 00000000000..2cc2e039670 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_cancelmove.go @@ -0,0 +1,75 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CancelMoveOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CancelMove ... +func (c ManagedDatabasesClient) CancelMove(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseMoveDefinition) (result CancelMoveOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancelMove", 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 +} + +// CancelMoveThenPoll performs CancelMove then polls until it's completed +func (c ManagedDatabasesClient) CancelMoveThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseMoveDefinition) error { + result, err := c.CancelMove(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CancelMove: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CancelMove: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_completemove.go b/resource-manager/sql/2023-08-01/manageddatabases/method_completemove.go new file mode 100644 index 00000000000..c1fd322a686 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_completemove.go @@ -0,0 +1,75 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CompleteMoveOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CompleteMove ... +func (c ManagedDatabasesClient) CompleteMove(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseMoveDefinition) (result CompleteMoveOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/completeMove", 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 +} + +// CompleteMoveThenPoll performs CompleteMove then polls until it's completed +func (c ManagedDatabasesClient) CompleteMoveThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseMoveDefinition) error { + result, err := c.CompleteMove(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CompleteMove: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CompleteMove: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_completerestore.go b/resource-manager/sql/2023-08-01/manageddatabases/method_completerestore.go new file mode 100644 index 00000000000..3117071e744 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_completerestore.go @@ -0,0 +1,75 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CompleteRestoreOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CompleteRestore ... +func (c ManagedDatabasesClient) CompleteRestore(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input CompleteDatabaseRestoreDefinition) (result CompleteRestoreOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/completeRestore", 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 +} + +// CompleteRestoreThenPoll performs CompleteRestore then polls until it's completed +func (c ManagedDatabasesClient) CompleteRestoreThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input CompleteDatabaseRestoreDefinition) error { + result, err := c.CompleteRestore(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CompleteRestore: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CompleteRestore: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabases/method_createorupdate.go new file mode 100644 index 00000000000..a5a8a9596cf --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_createorupdate.go @@ -0,0 +1,77 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabase +} + +// CreateOrUpdate ... +func (c ManagedDatabasesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabase) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ManagedDatabasesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabase) 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/sql/2023-08-01/manageddatabases/method_delete.go b/resource-manager/sql/2023-08-01/manageddatabases/method_delete.go new file mode 100644 index 00000000000..2ab242efe0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_delete.go @@ -0,0 +1,72 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedDatabasesClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (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 ManagedDatabasesClient) DeleteThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) 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/sql/2023-08-01/manageddatabases/method_get.go b/resource-manager/sql/2023-08-01/manageddatabases/method_get.go new file mode 100644 index 00000000000..66605aa1097 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_get.go @@ -0,0 +1,54 @@ +package manageddatabases + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabase +} + +// Get ... +func (c ManagedDatabasesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (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 ManagedDatabase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_listbyinstance.go b/resource-manager/sql/2023-08-01/manageddatabases/method_listbyinstance.go new file mode 100644 index 00000000000..f22159c138d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_listbyinstance.go @@ -0,0 +1,106 @@ +package manageddatabases + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedDatabase +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedDatabase +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedDatabasesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/databases", 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 *[]ManagedDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedDatabasesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedDatabaseOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabasesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedDatabaseOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedDatabase, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_listinaccessiblebyinstance.go b/resource-manager/sql/2023-08-01/manageddatabases/method_listinaccessiblebyinstance.go new file mode 100644 index 00000000000..043eeee41ce --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_listinaccessiblebyinstance.go @@ -0,0 +1,106 @@ +package manageddatabases + +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 ListInaccessibleByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedDatabase +} + +type ListInaccessibleByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedDatabase +} + +type ListInaccessibleByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListInaccessibleByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListInaccessibleByInstance ... +func (c ManagedDatabasesClient) ListInaccessibleByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListInaccessibleByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListInaccessibleByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/inaccessibleManagedDatabases", 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 *[]ManagedDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListInaccessibleByInstanceComplete retrieves all the results into a single object +func (c ManagedDatabasesClient) ListInaccessibleByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListInaccessibleByInstanceCompleteResult, error) { + return c.ListInaccessibleByInstanceCompleteMatchingPredicate(ctx, id, ManagedDatabaseOperationPredicate{}) +} + +// ListInaccessibleByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabasesClient) ListInaccessibleByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedDatabaseOperationPredicate) (result ListInaccessibleByInstanceCompleteResult, err error) { + items := make([]ManagedDatabase, 0) + + resp, err := c.ListInaccessibleByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListInaccessibleByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_startmove.go b/resource-manager/sql/2023-08-01/manageddatabases/method_startmove.go new file mode 100644 index 00000000000..2167470d7cb --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_startmove.go @@ -0,0 +1,75 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartMoveOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// StartMove ... +func (c ManagedDatabasesClient) StartMove(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseStartMoveDefinition) (result StartMoveOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/startMove", 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 +} + +// StartMoveThenPoll performs StartMove then polls until it's completed +func (c ManagedDatabasesClient) StartMoveThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseStartMoveDefinition) error { + result, err := c.StartMove(ctx, id, input) + if err != nil { + return fmt.Errorf("performing StartMove: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after StartMove: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/method_update.go b/resource-manager/sql/2023-08-01/manageddatabases/method_update.go new file mode 100644 index 00000000000..84164bc95c1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/method_update.go @@ -0,0 +1,76 @@ +package manageddatabases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabase +} + +// Update ... +func (c ManagedDatabasesClient) Update(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseUpdate) (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 ManagedDatabasesClient) UpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseUpdate) 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/sql/2023-08-01/manageddatabases/model_completedatabaserestoredefinition.go b/resource-manager/sql/2023-08-01/manageddatabases/model_completedatabaserestoredefinition.go new file mode 100644 index 00000000000..eca7c8f9814 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/model_completedatabaserestoredefinition.go @@ -0,0 +1,8 @@ +package manageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CompleteDatabaseRestoreDefinition struct { + LastBackupName string `json:"lastBackupName"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabase.go b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabase.go new file mode 100644 index 00000000000..3fcbb3a4cd2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabase.go @@ -0,0 +1,13 @@ +package manageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabase struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedDatabaseProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasemovedefinition.go b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasemovedefinition.go new file mode 100644 index 00000000000..5bd6dac7110 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasemovedefinition.go @@ -0,0 +1,8 @@ +package manageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseMoveDefinition struct { + DestinationManagedDatabaseId string `json:"destinationManagedDatabaseId"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseproperties.go b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseproperties.go new file mode 100644 index 00000000000..e6cd3d04a2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseproperties.go @@ -0,0 +1,71 @@ +package manageddatabases + +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 ManagedDatabaseProperties struct { + AutoCompleteRestore *bool `json:"autoCompleteRestore,omitempty"` + CatalogCollation *CatalogCollationType `json:"catalogCollation,omitempty"` + Collation *string `json:"collation,omitempty"` + CreateMode *ManagedDatabaseCreateMode `json:"createMode,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + CrossSubscriptionRestorableDroppedDatabaseId *string `json:"crossSubscriptionRestorableDroppedDatabaseId,omitempty"` + CrossSubscriptionSourceDatabaseId *string `json:"crossSubscriptionSourceDatabaseId,omitempty"` + CrossSubscriptionTargetManagedInstanceId *string `json:"crossSubscriptionTargetManagedInstanceId,omitempty"` + DefaultSecondaryLocation *string `json:"defaultSecondaryLocation,omitempty"` + EarliestRestorePoint *string `json:"earliestRestorePoint,omitempty"` + FailoverGroupId *string `json:"failoverGroupId,omitempty"` + IsLedgerOn *bool `json:"isLedgerOn,omitempty"` + LastBackupName *string `json:"lastBackupName,omitempty"` + LongTermRetentionBackupResourceId *string `json:"longTermRetentionBackupResourceId,omitempty"` + RecoverableDatabaseId *string `json:"recoverableDatabaseId,omitempty"` + RestorableDroppedDatabaseId *string `json:"restorableDroppedDatabaseId,omitempty"` + RestorePointInTime *string `json:"restorePointInTime,omitempty"` + SourceDatabaseId *string `json:"sourceDatabaseId,omitempty"` + Status *ManagedDatabaseStatus `json:"status,omitempty"` + StorageContainerIdentity *string `json:"storageContainerIdentity,omitempty"` + StorageContainerSasToken *string `json:"storageContainerSasToken,omitempty"` + StorageContainerUri *string `json:"storageContainerUri,omitempty"` +} + +func (o *ManagedDatabaseProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *ManagedDatabaseProperties) GetEarliestRestorePointAsTime() (*time.Time, error) { + if o.EarliestRestorePoint == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestorePoint, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseProperties) SetEarliestRestorePointAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestorePoint = &formatted +} + +func (o *ManagedDatabaseProperties) GetRestorePointInTimeAsTime() (*time.Time, error) { + if o.RestorePointInTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointInTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedDatabaseProperties) SetRestorePointInTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointInTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasestartmovedefinition.go b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasestartmovedefinition.go new file mode 100644 index 00000000000..df0652a71e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabasestartmovedefinition.go @@ -0,0 +1,9 @@ +package manageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseStartMoveDefinition struct { + DestinationManagedDatabaseId string `json:"destinationManagedDatabaseId"` + OperationMode *MoveOperationMode `json:"operationMode,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseupdate.go b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseupdate.go new file mode 100644 index 00000000000..d6281799728 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/model_manageddatabaseupdate.go @@ -0,0 +1,9 @@ +package manageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseUpdate struct { + Properties *ManagedDatabaseProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabases/predicates.go b/resource-manager/sql/2023-08-01/manageddatabases/predicates.go new file mode 100644 index 00000000000..3841529c83e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/predicates.go @@ -0,0 +1,32 @@ +package manageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedDatabaseOperationPredicate) Matches(input ManagedDatabase) 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/sql/2023-08-01/manageddatabases/version.go b/resource-manager/sql/2023-08-01/manageddatabases/version.go new file mode 100644 index 00000000000..47ad3c6f256 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabases/version.go @@ -0,0 +1,10 @@ +package manageddatabases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/README.md b/resource-manager/sql/2023-08-01/manageddatabaseschemas/README.md new file mode 100644 index 00000000000..971ca41a656 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaseschemas` Documentation + +The `manageddatabaseschemas` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabaseschemas" +``` + + +### Client Initialization + +```go +client := manageddatabaseschemas.NewManagedDatabaseSchemasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseSchemasClient.Get` + +```go +ctx := context.TODO() +id := manageddatabaseschemas.NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName") + +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: `ManagedDatabaseSchemasClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, manageddatabaseschemas.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, manageddatabaseschemas.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/client.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/client.go new file mode 100644 index 00000000000..85abf3277a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/client.go @@ -0,0 +1,26 @@ +package manageddatabaseschemas + +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 ManagedDatabaseSchemasClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseSchemasClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseSchemasClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabaseschemas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseSchemasClient: %+v", err) + } + + return &ManagedDatabaseSchemasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema.go new file mode 100644 index 00000000000..bf99c1590e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema.go @@ -0,0 +1,148 @@ +package manageddatabaseschemas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseSchemaId{}) +} + +var _ resourceids.ResourceId = &DatabaseSchemaId{} + +// DatabaseSchemaId is a struct representing the Resource ID for a Database Schema +type DatabaseSchemaId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string +} + +// NewDatabaseSchemaID returns a new DatabaseSchemaId struct +func NewDatabaseSchemaID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string) DatabaseSchemaId { + return DatabaseSchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + } +} + +// ParseDatabaseSchemaID parses 'input' into a DatabaseSchemaId +func ParseDatabaseSchemaID(input string) (*DatabaseSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseSchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseSchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseSchemaIDInsensitively parses 'input' case-insensitively into a DatabaseSchemaId +// note: this method should only be used for API response data and not user input +func ParseDatabaseSchemaIDInsensitively(input string) (*DatabaseSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseSchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseSchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseSchemaId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + return nil +} + +// ValidateDatabaseSchemaID checks that 'input' can be parsed as a Database Schema ID +func ValidateDatabaseSchemaID(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 := ParseDatabaseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database Schema ID +func (id DatabaseSchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database Schema ID +func (id DatabaseSchemaId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + } +} + +// String returns a human-readable description of this Database Schema ID +func (id DatabaseSchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + } + return fmt.Sprintf("Database Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema_test.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema_test.go new file mode 100644 index 00000000000..1e0004363ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/id_databaseschema_test.go @@ -0,0 +1,372 @@ +package manageddatabaseschemas + +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 = &DatabaseSchemaId{} + +func TestNewDatabaseSchemaID(t *testing.T) { + id := NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } +} + +func TestFormatDatabaseSchemaID(t *testing.T) { + actual := NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseSchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseSchemaID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestParseDatabaseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseSchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseSchemaIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestSegmentsForDatabaseSchemaId(t *testing.T) { + segments := DatabaseSchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseSchemaId 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/sql/2023-08-01/manageddatabaseschemas/method_get.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/method_get.go new file mode 100644 index 00000000000..078bf701b38 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/method_get.go @@ -0,0 +1,53 @@ +package manageddatabaseschemas + +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 *Resource +} + +// Get ... +func (c ManagedDatabaseSchemasClient) Get(ctx context.Context, id DatabaseSchemaId) (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 Resource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/method_listbydatabase.go new file mode 100644 index 00000000000..abc663abef3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/method_listbydatabase.go @@ -0,0 +1,135 @@ +package manageddatabaseschemas + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type ListByDatabaseOperationOptions struct { + Filter *string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseSchemasClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/schemas", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseSchemasClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseSchemasClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions, predicate ResourceOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/model_resource.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/model_resource.go new file mode 100644 index 00000000000..05ac84ae4fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/model_resource.go @@ -0,0 +1,10 @@ +package manageddatabaseschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabaseschemas/predicates.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/predicates.go new file mode 100644 index 00000000000..92d0b757757 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/predicates.go @@ -0,0 +1,27 @@ +package manageddatabaseschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.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/sql/2023-08-01/manageddatabaseschemas/version.go b/resource-manager/sql/2023-08-01/manageddatabaseschemas/version.go new file mode 100644 index 00000000000..1ae1229ab68 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabaseschemas/version.go @@ -0,0 +1,10 @@ +package manageddatabaseschemas + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabaseschemas/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/README.md b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/README.md new file mode 100644 index 00000000000..030f64e4806 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies` Documentation + +The `manageddatabasesecurityalertpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := manageddatabasesecurityalertpolicies.NewManagedDatabaseSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabasesecurityalertpolicies.ManagedDatabaseSecurityAlertPolicy{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseSecurityAlertPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedDatabaseSecurityAlertPoliciesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/client.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/client.go new file mode 100644 index 00000000000..39ea31e3f4d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/client.go @@ -0,0 +1,26 @@ +package manageddatabasesecurityalertpolicies + +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 ManagedDatabaseSecurityAlertPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseSecurityAlertPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseSecurityAlertPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasesecurityalertpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseSecurityAlertPoliciesClient: %+v", err) + } + + return &ManagedDatabaseSecurityAlertPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/constants.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/constants.go new file mode 100644 index 00000000000..42ecf5573e6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/constants.go @@ -0,0 +1,54 @@ +package manageddatabasesecurityalertpolicies + +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 SecurityAlertPolicyState string + +const ( + SecurityAlertPolicyStateDisabled SecurityAlertPolicyState = "Disabled" + SecurityAlertPolicyStateEnabled SecurityAlertPolicyState = "Enabled" + SecurityAlertPolicyStateNew SecurityAlertPolicyState = "New" +) + +func PossibleValuesForSecurityAlertPolicyState() []string { + return []string{ + string(SecurityAlertPolicyStateDisabled), + string(SecurityAlertPolicyStateEnabled), + string(SecurityAlertPolicyStateNew), + } +} + +func (s *SecurityAlertPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityAlertPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityAlertPolicyState(input string) (*SecurityAlertPolicyState, error) { + vals := map[string]SecurityAlertPolicyState{ + "disabled": SecurityAlertPolicyStateDisabled, + "enabled": SecurityAlertPolicyStateEnabled, + "new": SecurityAlertPolicyStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityAlertPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..242c1898286 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_createorupdate.go @@ -0,0 +1,60 @@ +package manageddatabasesecurityalertpolicies + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabaseSecurityAlertPolicy +} + +// CreateOrUpdate ... +func (c ManagedDatabaseSecurityAlertPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedDatabaseSecurityAlertPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 ManagedDatabaseSecurityAlertPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..edb0bda0d9f --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_get.go @@ -0,0 +1,55 @@ +package manageddatabasesecurityalertpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedDatabaseSecurityAlertPolicy +} + +// Get ... +func (c ManagedDatabaseSecurityAlertPoliciesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 ManagedDatabaseSecurityAlertPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..e09d852c08a --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/method_listbydatabase.go @@ -0,0 +1,106 @@ +package manageddatabasesecurityalertpolicies + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedDatabaseSecurityAlertPolicy +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedDatabaseSecurityAlertPolicy +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseSecurityAlertPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/securityAlertPolicies", 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 *[]ManagedDatabaseSecurityAlertPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseSecurityAlertPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ManagedDatabaseSecurityAlertPolicyOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseSecurityAlertPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate ManagedDatabaseSecurityAlertPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedDatabaseSecurityAlertPolicy, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go new file mode 100644 index 00000000000..1e00086c658 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go @@ -0,0 +1,11 @@ +package manageddatabasesecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseSecurityAlertPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityAlertPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go new file mode 100644 index 00000000000..69905459c85 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go @@ -0,0 +1,33 @@ +package manageddatabasesecurityalertpolicies + +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 SecurityAlertPolicyProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + DisabledAlerts *[]string `json:"disabledAlerts,omitempty"` + EmailAccountAdmins *bool `json:"emailAccountAdmins,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State SecurityAlertPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} + +func (o *SecurityAlertPolicyProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertPolicyProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..8cce85428fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasesecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedDatabaseSecurityAlertPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedDatabaseSecurityAlertPolicyOperationPredicate) Matches(input ManagedDatabaseSecurityAlertPolicy) 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/sql/2023-08-01/manageddatabasesecurityalertpolicies/version.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/version.go new file mode 100644 index 00000000000..d95cc969bc0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityalertpolicies/version.go @@ -0,0 +1,10 @@ +package manageddatabasesecurityalertpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasesecurityalertpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/README.md b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/README.md new file mode 100644 index 00000000000..4e1c8ad400f --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesecurityevents` Documentation + +The `manageddatabasesecurityevents` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesecurityevents" +``` + + +### Client Initialization + +```go +client := manageddatabasesecurityevents.NewManagedDatabaseSecurityEventsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseSecurityEventsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, manageddatabasesecurityevents.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, manageddatabasesecurityevents.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/client.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/client.go new file mode 100644 index 00000000000..1f36e33d9ac --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/client.go @@ -0,0 +1,26 @@ +package manageddatabasesecurityevents + +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 ManagedDatabaseSecurityEventsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseSecurityEventsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseSecurityEventsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasesecurityevents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseSecurityEventsClient: %+v", err) + } + + return &ManagedDatabaseSecurityEventsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/constants.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/constants.go new file mode 100644 index 00000000000..fcd8ceea5a6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/constants.go @@ -0,0 +1,54 @@ +package manageddatabasesecurityevents + +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 SecurityEventType string + +const ( + SecurityEventTypeSqlInjectionExploit SecurityEventType = "SqlInjectionExploit" + SecurityEventTypeSqlInjectionVulnerability SecurityEventType = "SqlInjectionVulnerability" + SecurityEventTypeUndefined SecurityEventType = "Undefined" +) + +func PossibleValuesForSecurityEventType() []string { + return []string{ + string(SecurityEventTypeSqlInjectionExploit), + string(SecurityEventTypeSqlInjectionVulnerability), + string(SecurityEventTypeUndefined), + } +} + +func (s *SecurityEventType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityEventType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityEventType(input string) (*SecurityEventType, error) { + vals := map[string]SecurityEventType{ + "sqlinjectionexploit": SecurityEventTypeSqlInjectionExploit, + "sqlinjectionvulnerability": SecurityEventTypeSqlInjectionVulnerability, + "undefined": SecurityEventTypeUndefined, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityEventType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/method_listbydatabase.go new file mode 100644 index 00000000000..97e4318326e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/method_listbydatabase.go @@ -0,0 +1,143 @@ +package manageddatabasesecurityevents + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityEvent +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityEvent +} + +type ListByDatabaseOperationOptions struct { + Filter *string + Skip *int64 + Top *int64 +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseSecurityEventsClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/securityEvents", 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 *[]SecurityEvent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseSecurityEventsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, SecurityEventOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseSecurityEventsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions, predicate SecurityEventOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]SecurityEvent, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityevent.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityevent.go new file mode 100644 index 00000000000..a611a55f9eb --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityevent.go @@ -0,0 +1,11 @@ +package manageddatabasesecurityevents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityEvent struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityEventProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventproperties.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventproperties.go new file mode 100644 index 00000000000..daff67e44e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventproperties.go @@ -0,0 +1,34 @@ +package manageddatabasesecurityevents + +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 SecurityEventProperties struct { + ApplicationName *string `json:"applicationName,omitempty"` + ClientIP *string `json:"clientIp,omitempty"` + Database *string `json:"database,omitempty"` + EventTime *string `json:"eventTime,omitempty"` + PrincipalName *string `json:"principalName,omitempty"` + SecurityEventSqlInjectionAdditionalProperties *SecurityEventSqlInjectionAdditionalProperties `json:"securityEventSqlInjectionAdditionalProperties,omitempty"` + SecurityEventType *SecurityEventType `json:"securityEventType,omitempty"` + Server *string `json:"server,omitempty"` + Subscription *string `json:"subscription,omitempty"` +} + +func (o *SecurityEventProperties) GetEventTimeAsTime() (*time.Time, error) { + if o.EventTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EventTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityEventProperties) SetEventTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EventTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go new file mode 100644 index 00000000000..e43164726b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go @@ -0,0 +1,14 @@ +package manageddatabasesecurityevents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityEventSqlInjectionAdditionalProperties struct { + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + Statement *string `json:"statement,omitempty"` + StatementHighlightLength *int64 `json:"statementHighlightLength,omitempty"` + StatementHighlightOffset *int64 `json:"statementHighlightOffset,omitempty"` + ThreatId *string `json:"threatId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/predicates.go new file mode 100644 index 00000000000..245970161e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasesecurityevents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityEventOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SecurityEventOperationPredicate) Matches(input SecurityEvent) 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/sql/2023-08-01/manageddatabasesecurityevents/version.go b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/version.go new file mode 100644 index 00000000000..6b9d25ee606 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesecurityevents/version.go @@ -0,0 +1,10 @@ +package manageddatabasesecurityevents + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasesecurityevents/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/README.md b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/README.md new file mode 100644 index 00000000000..8ebb5f170b3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/README.md @@ -0,0 +1,199 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels` Documentation + +The `manageddatabasesensitivitylabels` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels" +``` + + +### Client Initialization + +```go +client := manageddatabasesensitivitylabels.NewManagedDatabaseSensitivityLabelsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabasesensitivitylabels.NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + +payload := manageddatabasesensitivitylabels.SensitivityLabel{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.Delete` + +```go +ctx := context.TODO() +id := manageddatabasesensitivitylabels.NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.DisableRecommendation` + +```go +ctx := context.TODO() +id := manageddatabasesensitivitylabels.NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + +read, err := client.DisableRecommendation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.EnableRecommendation` + +```go +ctx := context.TODO() +id := manageddatabasesensitivitylabels.NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + +read, err := client.EnableRecommendation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.Get` + +```go +ctx := context.TODO() +id := manageddatabasesensitivitylabels.NewSensitivityLabelSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName", "current") + +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: `ManagedDatabaseSensitivityLabelsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, manageddatabasesensitivitylabels.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, manageddatabasesensitivitylabels.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.ListCurrentByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListCurrentByDatabase(ctx, id, manageddatabasesensitivitylabels.DefaultListCurrentByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListCurrentByDatabaseComplete(ctx, id, manageddatabasesensitivitylabels.DefaultListCurrentByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.ListRecommendedByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListRecommendedByDatabase(ctx, id, manageddatabasesensitivitylabels.DefaultListRecommendedByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListRecommendedByDatabaseComplete(ctx, id, manageddatabasesensitivitylabels.DefaultListRecommendedByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.ManagedDatabaseRecommendedSensitivityLabelsUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabasesensitivitylabels.RecommendedSensitivityLabelUpdateList{ + // ... +} + + +read, err := client.ManagedDatabaseRecommendedSensitivityLabelsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseSensitivityLabelsClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabasesensitivitylabels.SensitivityLabelUpdateList{ + // ... +} + + +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/sql/2023-08-01/manageddatabasesensitivitylabels/client.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/client.go new file mode 100644 index 00000000000..5f1ce307e35 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/client.go @@ -0,0 +1,26 @@ +package manageddatabasesensitivitylabels + +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 ManagedDatabaseSensitivityLabelsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseSensitivityLabelsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseSensitivityLabelsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasesensitivitylabels", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseSensitivityLabelsClient: %+v", err) + } + + return &ManagedDatabaseSensitivityLabelsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/constants.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/constants.go new file mode 100644 index 00000000000..0f2c8c7f281 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/constants.go @@ -0,0 +1,230 @@ +package manageddatabasesensitivitylabels + +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 ClientClassificationSource string + +const ( + ClientClassificationSourceMIP ClientClassificationSource = "MIP" + ClientClassificationSourceNative ClientClassificationSource = "Native" + ClientClassificationSourceNone ClientClassificationSource = "None" + ClientClassificationSourceRecommended ClientClassificationSource = "Recommended" +) + +func PossibleValuesForClientClassificationSource() []string { + return []string{ + string(ClientClassificationSourceMIP), + string(ClientClassificationSourceNative), + string(ClientClassificationSourceNone), + string(ClientClassificationSourceRecommended), + } +} + +func (s *ClientClassificationSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientClassificationSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientClassificationSource(input string) (*ClientClassificationSource, error) { + vals := map[string]ClientClassificationSource{ + "mip": ClientClassificationSourceMIP, + "native": ClientClassificationSourceNative, + "none": ClientClassificationSourceNone, + "recommended": ClientClassificationSourceRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientClassificationSource(input) + return &out, nil +} + +type RecommendedSensitivityLabelUpdateKind string + +const ( + RecommendedSensitivityLabelUpdateKindDisable RecommendedSensitivityLabelUpdateKind = "disable" + RecommendedSensitivityLabelUpdateKindEnable RecommendedSensitivityLabelUpdateKind = "enable" +) + +func PossibleValuesForRecommendedSensitivityLabelUpdateKind() []string { + return []string{ + string(RecommendedSensitivityLabelUpdateKindDisable), + string(RecommendedSensitivityLabelUpdateKindEnable), + } +} + +func (s *RecommendedSensitivityLabelUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedSensitivityLabelUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedSensitivityLabelUpdateKind(input string) (*RecommendedSensitivityLabelUpdateKind, error) { + vals := map[string]RecommendedSensitivityLabelUpdateKind{ + "disable": RecommendedSensitivityLabelUpdateKindDisable, + "enable": RecommendedSensitivityLabelUpdateKindEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedSensitivityLabelUpdateKind(input) + return &out, nil +} + +type SensitivityLabelRank string + +const ( + SensitivityLabelRankCritical SensitivityLabelRank = "Critical" + SensitivityLabelRankHigh SensitivityLabelRank = "High" + SensitivityLabelRankLow SensitivityLabelRank = "Low" + SensitivityLabelRankMedium SensitivityLabelRank = "Medium" + SensitivityLabelRankNone SensitivityLabelRank = "None" +) + +func PossibleValuesForSensitivityLabelRank() []string { + return []string{ + string(SensitivityLabelRankCritical), + string(SensitivityLabelRankHigh), + string(SensitivityLabelRankLow), + string(SensitivityLabelRankMedium), + string(SensitivityLabelRankNone), + } +} + +func (s *SensitivityLabelRank) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelRank(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelRank(input string) (*SensitivityLabelRank, error) { + vals := map[string]SensitivityLabelRank{ + "critical": SensitivityLabelRankCritical, + "high": SensitivityLabelRankHigh, + "low": SensitivityLabelRankLow, + "medium": SensitivityLabelRankMedium, + "none": SensitivityLabelRankNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelRank(input) + return &out, nil +} + +type SensitivityLabelSource string + +const ( + SensitivityLabelSourceCurrent SensitivityLabelSource = "current" + SensitivityLabelSourceRecommended SensitivityLabelSource = "recommended" +) + +func PossibleValuesForSensitivityLabelSource() []string { + return []string{ + string(SensitivityLabelSourceCurrent), + string(SensitivityLabelSourceRecommended), + } +} + +func (s *SensitivityLabelSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelSource(input string) (*SensitivityLabelSource, error) { + vals := map[string]SensitivityLabelSource{ + "current": SensitivityLabelSourceCurrent, + "recommended": SensitivityLabelSourceRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelSource(input) + return &out, nil +} + +type SensitivityLabelUpdateKind string + +const ( + SensitivityLabelUpdateKindRemove SensitivityLabelUpdateKind = "remove" + SensitivityLabelUpdateKindSet SensitivityLabelUpdateKind = "set" +) + +func PossibleValuesForSensitivityLabelUpdateKind() []string { + return []string{ + string(SensitivityLabelUpdateKindRemove), + string(SensitivityLabelUpdateKindSet), + } +} + +func (s *SensitivityLabelUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelUpdateKind(input string) (*SensitivityLabelUpdateKind, error) { + vals := map[string]SensitivityLabelUpdateKind{ + "remove": SensitivityLabelUpdateKindRemove, + "set": SensitivityLabelUpdateKindSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelUpdateKind(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go new file mode 100644 index 00000000000..40db73a9e73 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go @@ -0,0 +1,183 @@ +package manageddatabasesensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SensitivityLabelSensitivityLabelSourceId{}) +} + +var _ resourceids.ResourceId = &SensitivityLabelSensitivityLabelSourceId{} + +// SensitivityLabelSensitivityLabelSourceId is a struct representing the Resource ID for a Sensitivity Label Sensitivity Label Source +type SensitivityLabelSensitivityLabelSourceId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string + TableName string + ColumnName string + SensitivityLabelSource SensitivityLabelSource +} + +// NewSensitivityLabelSensitivityLabelSourceID returns a new SensitivityLabelSensitivityLabelSourceId struct +func NewSensitivityLabelSensitivityLabelSourceID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string, tableName string, columnName string, sensitivityLabelSource SensitivityLabelSource) SensitivityLabelSensitivityLabelSourceId { + return SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + SensitivityLabelSource: sensitivityLabelSource, + } +} + +// ParseSensitivityLabelSensitivityLabelSourceID parses 'input' into a SensitivityLabelSensitivityLabelSourceId +func ParseSensitivityLabelSensitivityLabelSourceID(input string) (*SensitivityLabelSensitivityLabelSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&SensitivityLabelSensitivityLabelSourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SensitivityLabelSensitivityLabelSourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSensitivityLabelSensitivityLabelSourceIDInsensitively parses 'input' case-insensitively into a SensitivityLabelSensitivityLabelSourceId +// note: this method should only be used for API response data and not user input +func ParseSensitivityLabelSensitivityLabelSourceIDInsensitively(input string) (*SensitivityLabelSensitivityLabelSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&SensitivityLabelSensitivityLabelSourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SensitivityLabelSensitivityLabelSourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SensitivityLabelSensitivityLabelSourceId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + if v, ok := input.Parsed["sensitivityLabelSource"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sensitivityLabelSource", input) + } + + sensitivityLabelSource, err := parseSensitivityLabelSource(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.SensitivityLabelSource = *sensitivityLabelSource + } + + return nil +} + +// ValidateSensitivityLabelSensitivityLabelSourceID checks that 'input' can be parsed as a Sensitivity Label Sensitivity Label Source ID +func ValidateSensitivityLabelSensitivityLabelSourceID(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 := ParseSensitivityLabelSensitivityLabelSourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sensitivity Label Sensitivity Label Source ID +func (id SensitivityLabelSensitivityLabelSourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s/tables/%s/columns/%s/sensitivityLabels/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName, id.TableName, id.ColumnName, string(id.SensitivityLabelSource)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sensitivity Label Sensitivity Label Source ID +func (id SensitivityLabelSensitivityLabelSourceId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnName"), + resourceids.StaticSegment("staticSensitivityLabels", "sensitivityLabels", "sensitivityLabels"), + resourceids.ConstantSegment("sensitivityLabelSource", PossibleValuesForSensitivityLabelSource(), "current"), + } +} + +// String returns a human-readable description of this Sensitivity Label Sensitivity Label Source ID +func (id SensitivityLabelSensitivityLabelSourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + fmt.Sprintf("Sensitivity Label Source: %q", string(id.SensitivityLabelSource)), + } + return fmt.Sprintf("Sensitivity Label Sensitivity Label Source (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go new file mode 100644 index 00000000000..88bf67d6b81 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go @@ -0,0 +1,507 @@ +package manageddatabasesensitivitylabels + +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 = &SensitivityLabelSensitivityLabelSourceId{} + +func TestNewSensitivityLabelSensitivityLabelSourceID(t *testing.T) { + id := NewSensitivityLabelSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName", "current") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } + + if id.ColumnName != "columnName" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnName") + } + + if id.SensitivityLabelSource != "current" { + t.Fatalf("Expected %q but got %q for Segment 'SensitivityLabelSource'", id.SensitivityLabelSource, "current") + } +} + +func TestFormatSensitivityLabelSensitivityLabelSourceID(t *testing.T) { + actual := NewSensitivityLabelSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName", "current").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSensitivityLabelSensitivityLabelSourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SensitivityLabelSensitivityLabelSourceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current", + Expected: &SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSensitivityLabelSensitivityLabelSourceID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + if actual.SensitivityLabelSource != v.Expected.SensitivityLabelSource { + t.Fatalf("Expected %q but got %q for SensitivityLabelSource", v.Expected.SensitivityLabelSource, actual.SensitivityLabelSource) + } + + } +} + +func TestParseSensitivityLabelSensitivityLabelSourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SensitivityLabelSensitivityLabelSourceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/sEnSiTiViTyLaBeLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current", + Expected: &SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/sEnSiTiViTyLaBeLs/cUrReNt", + Expected: &SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + ColumnName: "cOlUmNnAmE", + SensitivityLabelSource: "current", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/sEnSiTiViTyLaBeLs/cUrReNt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSensitivityLabelSensitivityLabelSourceIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + if actual.SensitivityLabelSource != v.Expected.SensitivityLabelSource { + t.Fatalf("Expected %q but got %q for SensitivityLabelSource", v.Expected.SensitivityLabelSource, actual.SensitivityLabelSource) + } + + } +} + +func TestSegmentsForSensitivityLabelSensitivityLabelSourceId(t *testing.T) { + segments := SensitivityLabelSensitivityLabelSourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SensitivityLabelSensitivityLabelSourceId 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/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn.go new file mode 100644 index 00000000000..5005ccdb5b9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn.go @@ -0,0 +1,166 @@ +package manageddatabasesensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TableColumnId{}) +} + +var _ resourceids.ResourceId = &TableColumnId{} + +// TableColumnId is a struct representing the Resource ID for a Table Column +type TableColumnId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string + TableName string + ColumnName string +} + +// NewTableColumnID returns a new TableColumnId struct +func NewTableColumnID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string, tableName string, columnName string) TableColumnId { + return TableColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseTableColumnID parses 'input' into a TableColumnId +func ParseTableColumnID(input string) (*TableColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableColumnIDInsensitively parses 'input' case-insensitively into a TableColumnId +// note: this method should only be used for API response data and not user input +func ParseTableColumnIDInsensitively(input string) (*TableColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableColumnId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateTableColumnID checks that 'input' can be parsed as a Table Column ID +func ValidateTableColumnID(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 := ParseTableColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table Column ID +func (id TableColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table Column ID +func (id TableColumnId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnName"), + } +} + +// String returns a human-readable description of this Table Column ID +func (id TableColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Table Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn_test.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn_test.go new file mode 100644 index 00000000000..916665f5ce8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/id_tablecolumn_test.go @@ -0,0 +1,462 @@ +package manageddatabasesensitivitylabels + +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 = &TableColumnId{} + +func TestNewTableColumnID(t *testing.T) { + id := NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } + + if id.ColumnName != "columnName" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnName") + } +} + +func TestFormatTableColumnID(t *testing.T) { + actual := NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName", "columnName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableColumnID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseTableColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + ColumnName: "cOlUmNnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableColumnIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForTableColumnId(t *testing.T) { + segments := TableColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableColumnId 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/sql/2023-08-01/manageddatabasesensitivitylabels/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_createorupdate.go new file mode 100644 index 00000000000..9cbc8f10e77 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_createorupdate.go @@ -0,0 +1,59 @@ +package manageddatabasesensitivitylabels + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SensitivityLabel +} + +// CreateOrUpdate ... +func (c ManagedDatabaseSensitivityLabelsClient) CreateOrUpdate(ctx context.Context, id TableColumnId, input SensitivityLabel) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sensitivityLabels/current", 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 SensitivityLabel + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_delete.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_delete.go new file mode 100644 index 00000000000..39876f8a2fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_delete.go @@ -0,0 +1,47 @@ +package manageddatabasesensitivitylabels + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedDatabaseSensitivityLabelsClient) Delete(ctx context.Context, id TableColumnId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/sensitivityLabels/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_disablerecommendation.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_disablerecommendation.go new file mode 100644 index 00000000000..9a4b4ee3dea --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_disablerecommendation.go @@ -0,0 +1,47 @@ +package manageddatabasesensitivitylabels + +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 DisableRecommendationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DisableRecommendation ... +func (c ManagedDatabaseSensitivityLabelsClient) DisableRecommendation(ctx context.Context, id TableColumnId) (result DisableRecommendationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sensitivityLabels/recommended/disable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_enablerecommendation.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_enablerecommendation.go new file mode 100644 index 00000000000..6d4b3fd85db --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_enablerecommendation.go @@ -0,0 +1,47 @@ +package manageddatabasesensitivitylabels + +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 EnableRecommendationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// EnableRecommendation ... +func (c ManagedDatabaseSensitivityLabelsClient) EnableRecommendation(ctx context.Context, id TableColumnId) (result EnableRecommendationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sensitivityLabels/recommended/enable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_get.go new file mode 100644 index 00000000000..1fd0579b104 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_get.go @@ -0,0 +1,53 @@ +package manageddatabasesensitivitylabels + +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 *SensitivityLabel +} + +// Get ... +func (c ManagedDatabaseSensitivityLabelsClient) Get(ctx context.Context, id SensitivityLabelSensitivityLabelSourceId) (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 SensitivityLabel + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listbydatabase.go new file mode 100644 index 00000000000..b1519531487 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listbydatabase.go @@ -0,0 +1,135 @@ +package manageddatabasesensitivitylabels + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type ListByDatabaseOperationOptions struct { + Filter *string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseSensitivityLabelsClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/sensitivityLabels", 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 *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseSensitivityLabelsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseSensitivityLabelsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListByDatabaseOperationOptions, predicate SensitivityLabelOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go new file mode 100644 index 00000000000..5dd91867ecc --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go @@ -0,0 +1,139 @@ +package manageddatabasesensitivitylabels + +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 ListCurrentByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type ListCurrentByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type ListCurrentByDatabaseOperationOptions struct { + Count *bool + Filter *string +} + +func DefaultListCurrentByDatabaseOperationOptions() ListCurrentByDatabaseOperationOptions { + return ListCurrentByDatabaseOperationOptions{} +} + +func (o ListCurrentByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListCurrentByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListCurrentByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCurrentByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCurrentByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListCurrentByDatabase ... +func (c ManagedDatabaseSensitivityLabelsClient) ListCurrentByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListCurrentByDatabaseOperationOptions) (result ListCurrentByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCurrentByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/currentSensitivityLabels", 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 *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListCurrentByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseSensitivityLabelsClient) ListCurrentByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListCurrentByDatabaseOperationOptions) (ListCurrentByDatabaseCompleteResult, error) { + return c.ListCurrentByDatabaseCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// ListCurrentByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseSensitivityLabelsClient) ListCurrentByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListCurrentByDatabaseOperationOptions, predicate SensitivityLabelOperationPredicate) (result ListCurrentByDatabaseCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.ListCurrentByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCurrentByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go new file mode 100644 index 00000000000..43c4c7959b5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go @@ -0,0 +1,139 @@ +package manageddatabasesensitivitylabels + +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 ListRecommendedByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type ListRecommendedByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type ListRecommendedByDatabaseOperationOptions struct { + Filter *string + IncludeDisabledRecommendations *bool +} + +func DefaultListRecommendedByDatabaseOperationOptions() ListRecommendedByDatabaseOperationOptions { + return ListRecommendedByDatabaseOperationOptions{} +} + +func (o ListRecommendedByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRecommendedByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListRecommendedByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IncludeDisabledRecommendations != nil { + out.Append("includeDisabledRecommendations", fmt.Sprintf("%v", *o.IncludeDisabledRecommendations)) + } + return &out +} + +type ListRecommendedByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListRecommendedByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListRecommendedByDatabase ... +func (c ManagedDatabaseSensitivityLabelsClient) ListRecommendedByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListRecommendedByDatabaseOperationOptions) (result ListRecommendedByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListRecommendedByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", 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 *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRecommendedByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseSensitivityLabelsClient) ListRecommendedByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListRecommendedByDatabaseOperationOptions) (ListRecommendedByDatabaseCompleteResult, error) { + return c.ListRecommendedByDatabaseCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// ListRecommendedByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseSensitivityLabelsClient) ListRecommendedByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, options ListRecommendedByDatabaseOperationOptions, predicate SensitivityLabelOperationPredicate) (result ListRecommendedByDatabaseCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.ListRecommendedByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRecommendedByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go new file mode 100644 index 00000000000..4b0b21a0c6c --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go @@ -0,0 +1,52 @@ +package manageddatabasesensitivitylabels + +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 ManagedDatabaseRecommendedSensitivityLabelsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ManagedDatabaseRecommendedSensitivityLabelsUpdate ... +func (c ManagedDatabaseSensitivityLabelsClient) ManagedDatabaseRecommendedSensitivityLabelsUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input RecommendedSensitivityLabelUpdateList) (result ManagedDatabaseRecommendedSensitivityLabelsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_update.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_update.go new file mode 100644 index 00000000000..e05e41cd4b4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/method_update.go @@ -0,0 +1,52 @@ +package manageddatabasesensitivitylabels + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Update ... +func (c ManagedDatabaseSensitivityLabelsClient) Update(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input SensitivityLabelUpdateList) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/currentSensitivityLabels", 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go new file mode 100644 index 00000000000..de3bbca3fa5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go @@ -0,0 +1,11 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendedSensitivityLabelUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go new file mode 100644 index 00000000000..5ef8d232110 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go @@ -0,0 +1,8 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateList struct { + Operations *[]RecommendedSensitivityLabelUpdate `json:"operations,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..79e968928f3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go @@ -0,0 +1,11 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateProperties struct { + Column string `json:"column"` + Op RecommendedSensitivityLabelUpdateKind `json:"op"` + Schema string `json:"schema"` + Table string `json:"table"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabel.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabel.go new file mode 100644 index 00000000000..25e5d68fab1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabel.go @@ -0,0 +1,12 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabel struct { + Id *string `json:"id,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SensitivityLabelProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go new file mode 100644 index 00000000000..657fbbdbd99 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go @@ -0,0 +1,17 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelProperties struct { + ClientClassificationSource *ClientClassificationSource `json:"clientClassificationSource,omitempty"` + ColumnName *string `json:"columnName,omitempty"` + InformationType *string `json:"informationType,omitempty"` + InformationTypeId *string `json:"informationTypeId,omitempty"` + IsDisabled *bool `json:"isDisabled,omitempty"` + LabelId *string `json:"labelId,omitempty"` + LabelName *string `json:"labelName,omitempty"` + Rank *SensitivityLabelRank `json:"rank,omitempty"` + SchemaName *string `json:"schemaName,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go new file mode 100644 index 00000000000..a70b6792b6b --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go @@ -0,0 +1,11 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SensitivityLabelUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go new file mode 100644 index 00000000000..a3cde4f4d85 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go @@ -0,0 +1,8 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdateList struct { + Operations *[]SensitivityLabelUpdate `json:"operations,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..810032aa3fb --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go @@ -0,0 +1,12 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdateProperties struct { + Column string `json:"column"` + Op SensitivityLabelUpdateKind `json:"op"` + Schema string `json:"schema"` + SensitivityLabel *SensitivityLabel `json:"sensitivityLabel,omitempty"` + Table string `json:"table"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/predicates.go new file mode 100644 index 00000000000..12545dcc919 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/predicates.go @@ -0,0 +1,32 @@ +package manageddatabasesensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelOperationPredicate struct { + Id *string + ManagedBy *string + Name *string + Type *string +} + +func (p SensitivityLabelOperationPredicate) Matches(input SensitivityLabel) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + 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/sql/2023-08-01/manageddatabasesensitivitylabels/version.go b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/version.go new file mode 100644 index 00000000000..5ecba2740ad --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasesensitivitylabels/version.go @@ -0,0 +1,10 @@ +package manageddatabasesensitivitylabels + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasesensitivitylabels/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/README.md b/resource-manager/sql/2023-08-01/manageddatabasetables/README.md new file mode 100644 index 00000000000..969220aac76 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasetables` Documentation + +The `manageddatabasetables` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasetables" +``` + + +### Client Initialization + +```go +client := manageddatabasetables.NewManagedDatabaseTablesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseTablesClient.Get` + +```go +ctx := context.TODO() +id := manageddatabasetables.NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName") + +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: `ManagedDatabaseTablesClient.ListBySchema` + +```go +ctx := context.TODO() +id := manageddatabasetables.NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName") + +// alternatively `client.ListBySchema(ctx, id, manageddatabasetables.DefaultListBySchemaOperationOptions())` can be used to do batched pagination +items, err := client.ListBySchemaComplete(ctx, id, manageddatabasetables.DefaultListBySchemaOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/client.go b/resource-manager/sql/2023-08-01/manageddatabasetables/client.go new file mode 100644 index 00000000000..96587bb312b --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/client.go @@ -0,0 +1,26 @@ +package manageddatabasetables + +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 ManagedDatabaseTablesClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseTablesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseTablesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasetables", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseTablesClient: %+v", err) + } + + return &ManagedDatabaseTablesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/constants.go b/resource-manager/sql/2023-08-01/manageddatabasetables/constants.go new file mode 100644 index 00000000000..b3e65c8da59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/constants.go @@ -0,0 +1,54 @@ +package manageddatabasetables + +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 TableTemporalType string + +const ( + TableTemporalTypeHistoryTable TableTemporalType = "HistoryTable" + TableTemporalTypeNonTemporalTable TableTemporalType = "NonTemporalTable" + TableTemporalTypeSystemVersionedTemporalTable TableTemporalType = "SystemVersionedTemporalTable" +) + +func PossibleValuesForTableTemporalType() []string { + return []string{ + string(TableTemporalTypeHistoryTable), + string(TableTemporalTypeNonTemporalTable), + string(TableTemporalTypeSystemVersionedTemporalTable), + } +} + +func (s *TableTemporalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTableTemporalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTableTemporalType(input string) (*TableTemporalType, error) { + vals := map[string]TableTemporalType{ + "historytable": TableTemporalTypeHistoryTable, + "nontemporaltable": TableTemporalTypeNonTemporalTable, + "systemversionedtemporaltable": TableTemporalTypeSystemVersionedTemporalTable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TableTemporalType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema.go b/resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema.go new file mode 100644 index 00000000000..401f0fb97bb --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema.go @@ -0,0 +1,148 @@ +package manageddatabasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseSchemaId{}) +} + +var _ resourceids.ResourceId = &DatabaseSchemaId{} + +// DatabaseSchemaId is a struct representing the Resource ID for a Database Schema +type DatabaseSchemaId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string +} + +// NewDatabaseSchemaID returns a new DatabaseSchemaId struct +func NewDatabaseSchemaID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string) DatabaseSchemaId { + return DatabaseSchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + } +} + +// ParseDatabaseSchemaID parses 'input' into a DatabaseSchemaId +func ParseDatabaseSchemaID(input string) (*DatabaseSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseSchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseSchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseSchemaIDInsensitively parses 'input' case-insensitively into a DatabaseSchemaId +// note: this method should only be used for API response data and not user input +func ParseDatabaseSchemaIDInsensitively(input string) (*DatabaseSchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseSchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseSchemaId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseSchemaId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + return nil +} + +// ValidateDatabaseSchemaID checks that 'input' can be parsed as a Database Schema ID +func ValidateDatabaseSchemaID(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 := ParseDatabaseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database Schema ID +func (id DatabaseSchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database Schema ID +func (id DatabaseSchemaId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + } +} + +// String returns a human-readable description of this Database Schema ID +func (id DatabaseSchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + } + return fmt.Sprintf("Database Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema_test.go b/resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema_test.go new file mode 100644 index 00000000000..37baf02a006 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/id_databaseschema_test.go @@ -0,0 +1,372 @@ +package manageddatabasetables + +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 = &DatabaseSchemaId{} + +func TestNewDatabaseSchemaID(t *testing.T) { + id := NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } +} + +func TestFormatDatabaseSchemaID(t *testing.T) { + actual := NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseSchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseSchemaID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestParseDatabaseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseSchemaId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseSchemaIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestSegmentsForDatabaseSchemaId(t *testing.T) { + segments := DatabaseSchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseSchemaId 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/sql/2023-08-01/manageddatabasetables/id_schematable.go b/resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable.go new file mode 100644 index 00000000000..4da2ce649bf --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable.go @@ -0,0 +1,157 @@ +package manageddatabasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SchemaTableId{}) +} + +var _ resourceids.ResourceId = &SchemaTableId{} + +// SchemaTableId is a struct representing the Resource ID for a Schema Table +type SchemaTableId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + SchemaName string + TableName string +} + +// NewSchemaTableID returns a new SchemaTableId struct +func NewSchemaTableID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, schemaName string, tableName string) SchemaTableId { + return SchemaTableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + } +} + +// ParseSchemaTableID parses 'input' into a SchemaTableId +func ParseSchemaTableID(input string) (*SchemaTableId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaTableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaTableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaTableIDInsensitively parses 'input' case-insensitively into a SchemaTableId +// note: this method should only be used for API response data and not user input +func ParseSchemaTableIDInsensitively(input string) (*SchemaTableId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaTableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaTableId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaTableId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateSchemaTableID checks that 'input' can be parsed as a Schema Table ID +func ValidateSchemaTableID(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 := ParseSchemaTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema Table ID +func (id SchemaTableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/schemas/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.SchemaName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema Table ID +func (id SchemaTableId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + } +} + +// String returns a human-readable description of this Schema Table ID +func (id SchemaTableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Schema Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable_test.go b/resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable_test.go new file mode 100644 index 00000000000..75c0d54383c --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/id_schematable_test.go @@ -0,0 +1,417 @@ +package manageddatabasetables + +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 = &SchemaTableId{} + +func TestNewSchemaTableID(t *testing.T) { + id := NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } +} + +func TestFormatSchemaTableID(t *testing.T) { + actual := NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "schemaName", "tableName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaTableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaTableID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseSchemaTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaTableId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/schemas/schemaName/tables/tableName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaTableIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForSchemaTableId(t *testing.T) { + segments := SchemaTableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaTableId 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/sql/2023-08-01/manageddatabasetables/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasetables/method_get.go new file mode 100644 index 00000000000..02d4e056c9d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/method_get.go @@ -0,0 +1,53 @@ +package manageddatabasetables + +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 *DatabaseTable +} + +// Get ... +func (c ManagedDatabaseTablesClient) Get(ctx context.Context, id SchemaTableId) (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 DatabaseTable + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/method_listbyschema.go b/resource-manager/sql/2023-08-01/manageddatabasetables/method_listbyschema.go new file mode 100644 index 00000000000..257f3642fc0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/method_listbyschema.go @@ -0,0 +1,134 @@ +package manageddatabasetables + +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 ListBySchemaOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseTable +} + +type ListBySchemaCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseTable +} + +type ListBySchemaOperationOptions struct { + Filter *string +} + +func DefaultListBySchemaOperationOptions() ListBySchemaOperationOptions { + return ListBySchemaOperationOptions{} +} + +func (o ListBySchemaOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySchemaOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySchemaOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListBySchemaCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySchemaCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySchema ... +func (c ManagedDatabaseTablesClient) ListBySchema(ctx context.Context, id DatabaseSchemaId, options ListBySchemaOperationOptions) (result ListBySchemaOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySchemaCustomPager{}, + Path: fmt.Sprintf("%s/tables", 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 *[]DatabaseTable `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySchemaComplete retrieves all the results into a single object +func (c ManagedDatabaseTablesClient) ListBySchemaComplete(ctx context.Context, id DatabaseSchemaId, options ListBySchemaOperationOptions) (ListBySchemaCompleteResult, error) { + return c.ListBySchemaCompleteMatchingPredicate(ctx, id, options, DatabaseTableOperationPredicate{}) +} + +// ListBySchemaCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseTablesClient) ListBySchemaCompleteMatchingPredicate(ctx context.Context, id DatabaseSchemaId, options ListBySchemaOperationOptions, predicate DatabaseTableOperationPredicate) (result ListBySchemaCompleteResult, err error) { + items := make([]DatabaseTable, 0) + + resp, err := c.ListBySchema(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySchemaCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetable.go b/resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetable.go new file mode 100644 index 00000000000..1bdff393e57 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetable.go @@ -0,0 +1,11 @@ +package manageddatabasetables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseTable struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseTableProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetableproperties.go b/resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetableproperties.go new file mode 100644 index 00000000000..0e618ebbe5a --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/model_databasetableproperties.go @@ -0,0 +1,9 @@ +package manageddatabasetables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseTableProperties struct { + MemoryOptimized *bool `json:"memoryOptimized,omitempty"` + TemporalType *TableTemporalType `json:"temporalType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetables/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasetables/predicates.go new file mode 100644 index 00000000000..e9eb18274d2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasetables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseTableOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseTableOperationPredicate) Matches(input DatabaseTable) 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/sql/2023-08-01/manageddatabasetables/version.go b/resource-manager/sql/2023-08-01/manageddatabasetables/version.go new file mode 100644 index 00000000000..661bf68a1ba --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetables/version.go @@ -0,0 +1,10 @@ +package manageddatabasetables + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasetables/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/README.md b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/README.md new file mode 100644 index 00000000000..d16a8d59ab0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption` Documentation + +The `manageddatabasetransparentdataencryption` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption" +``` + + +### Client Initialization + +```go +client := manageddatabasetransparentdataencryption.NewManagedDatabaseTransparentDataEncryptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseTransparentDataEncryptionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabasetransparentdataencryption.ManagedTransparentDataEncryption{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseTransparentDataEncryptionClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedDatabaseTransparentDataEncryptionClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/client.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/client.go new file mode 100644 index 00000000000..31ad96ae97b --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/client.go @@ -0,0 +1,26 @@ +package manageddatabasetransparentdataencryption + +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 ManagedDatabaseTransparentDataEncryptionClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseTransparentDataEncryptionClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseTransparentDataEncryptionClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasetransparentdataencryption", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseTransparentDataEncryptionClient: %+v", err) + } + + return &ManagedDatabaseTransparentDataEncryptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/constants.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/constants.go new file mode 100644 index 00000000000..9464da32a72 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/constants.go @@ -0,0 +1,51 @@ +package manageddatabasetransparentdataencryption + +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 TransparentDataEncryptionState string + +const ( + TransparentDataEncryptionStateDisabled TransparentDataEncryptionState = "Disabled" + TransparentDataEncryptionStateEnabled TransparentDataEncryptionState = "Enabled" +) + +func PossibleValuesForTransparentDataEncryptionState() []string { + return []string{ + string(TransparentDataEncryptionStateDisabled), + string(TransparentDataEncryptionStateEnabled), + } +} + +func (s *TransparentDataEncryptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTransparentDataEncryptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTransparentDataEncryptionState(input string) (*TransparentDataEncryptionState, error) { + vals := map[string]TransparentDataEncryptionState{ + "disabled": TransparentDataEncryptionStateDisabled, + "enabled": TransparentDataEncryptionStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TransparentDataEncryptionState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_createorupdate.go new file mode 100644 index 00000000000..60b433a559a --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_createorupdate.go @@ -0,0 +1,60 @@ +package manageddatabasetransparentdataencryption + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedTransparentDataEncryption +} + +// CreateOrUpdate ... +func (c ManagedDatabaseTransparentDataEncryptionClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedTransparentDataEncryption) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/transparentDataEncryption/current", 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 ManagedTransparentDataEncryption + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_get.go new file mode 100644 index 00000000000..b404946cca2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_get.go @@ -0,0 +1,55 @@ +package manageddatabasetransparentdataencryption + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedTransparentDataEncryption +} + +// Get ... +func (c ManagedDatabaseTransparentDataEncryptionClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/transparentDataEncryption/current", 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 ManagedTransparentDataEncryption + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_listbydatabase.go new file mode 100644 index 00000000000..aa31fc6e3a5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/method_listbydatabase.go @@ -0,0 +1,106 @@ +package manageddatabasetransparentdataencryption + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedTransparentDataEncryption +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedTransparentDataEncryption +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseTransparentDataEncryptionClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/transparentDataEncryption", 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 *[]ManagedTransparentDataEncryption `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseTransparentDataEncryptionClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ManagedTransparentDataEncryptionOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseTransparentDataEncryptionClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate ManagedTransparentDataEncryptionOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedTransparentDataEncryption, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go new file mode 100644 index 00000000000..91f6cf19c63 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go @@ -0,0 +1,11 @@ +package manageddatabasetransparentdataencryption + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedTransparentDataEncryption struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedTransparentDataEncryptionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go new file mode 100644 index 00000000000..413692ccbd2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go @@ -0,0 +1,8 @@ +package manageddatabasetransparentdataencryption + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedTransparentDataEncryptionProperties struct { + State TransparentDataEncryptionState `json:"state"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/predicates.go new file mode 100644 index 00000000000..18ed9b33301 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasetransparentdataencryption + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedTransparentDataEncryptionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedTransparentDataEncryptionOperationPredicate) Matches(input ManagedTransparentDataEncryption) 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/sql/2023-08-01/manageddatabasetransparentdataencryption/version.go b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/version.go new file mode 100644 index 00000000000..2b24d0c6063 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasetransparentdataencryption/version.go @@ -0,0 +1,10 @@ +package manageddatabasetransparentdataencryption + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasetransparentdataencryption/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/README.md b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/README.md new file mode 100644 index 00000000000..029f7eba96a --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines` Documentation + +The `manageddatabasevulnerabilityassessmentrulebaselines` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines" +``` + + +### Client Initialization + +```go +client := manageddatabasevulnerabilityassessmentrulebaselines.NewManagedDatabaseVulnerabilityAssessmentRuleBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentrulebaselines.NewBaselineBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "ruleId", "default") + +payload := manageddatabasevulnerabilityassessmentrulebaselines.DatabaseVulnerabilityAssessmentRuleBaseline{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient.Delete` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentrulebaselines.NewBaselineBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "ruleId", "default") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient.Get` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentrulebaselines.NewBaselineBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "ruleId", "default") + +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 +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/client.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/client.go new file mode 100644 index 00000000000..8868cfd2b70 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/client.go @@ -0,0 +1,26 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +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 ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseVulnerabilityAssessmentRuleBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasevulnerabilityassessmentrulebaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient: %+v", err) + } + + return &ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/constants.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/constants.go new file mode 100644 index 00000000000..b021b0f9a42 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/constants.go @@ -0,0 +1,51 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +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 VulnerabilityAssessmentPolicyBaselineName string + +const ( + VulnerabilityAssessmentPolicyBaselineNameDefault VulnerabilityAssessmentPolicyBaselineName = "default" + VulnerabilityAssessmentPolicyBaselineNameMaster VulnerabilityAssessmentPolicyBaselineName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentPolicyBaselineName() []string { + return []string{ + string(VulnerabilityAssessmentPolicyBaselineNameDefault), + string(VulnerabilityAssessmentPolicyBaselineNameMaster), + } +} + +func (s *VulnerabilityAssessmentPolicyBaselineName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentPolicyBaselineName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentPolicyBaselineName(input string) (*VulnerabilityAssessmentPolicyBaselineName, error) { + vals := map[string]VulnerabilityAssessmentPolicyBaselineName{ + "default": VulnerabilityAssessmentPolicyBaselineNameDefault, + "master": VulnerabilityAssessmentPolicyBaselineNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentPolicyBaselineName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go new file mode 100644 index 00000000000..1dc3951b60c --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go @@ -0,0 +1,167 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BaselineBaselineId{}) +} + +var _ resourceids.ResourceId = &BaselineBaselineId{} + +// BaselineBaselineId is a struct representing the Resource ID for a Baseline Baseline +type BaselineBaselineId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + RuleId string + BaselineName VulnerabilityAssessmentPolicyBaselineName +} + +// NewBaselineBaselineID returns a new BaselineBaselineId struct +func NewBaselineBaselineID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, ruleId string, baselineName VulnerabilityAssessmentPolicyBaselineName) BaselineBaselineId { + return BaselineBaselineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + RuleId: ruleId, + BaselineName: baselineName, + } +} + +// ParseBaselineBaselineID parses 'input' into a BaselineBaselineId +func ParseBaselineBaselineID(input string) (*BaselineBaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineBaselineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineBaselineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBaselineBaselineIDInsensitively parses 'input' case-insensitively into a BaselineBaselineId +// note: this method should only be used for API response data and not user input +func ParseBaselineBaselineIDInsensitively(input string) (*BaselineBaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineBaselineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineBaselineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BaselineBaselineId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + if v, ok := input.Parsed["baselineName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "baselineName", input) + } + + baselineName, err := parseVulnerabilityAssessmentPolicyBaselineName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.BaselineName = *baselineName + } + + return nil +} + +// ValidateBaselineBaselineID checks that 'input' can be parsed as a Baseline Baseline ID +func ValidateBaselineBaselineID(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 := ParseBaselineBaselineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Baseline Baseline ID +func (id BaselineBaselineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/vulnerabilityAssessments/default/rules/%s/baselines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.RuleId, string(id.BaselineName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Baseline Baseline ID +func (id BaselineBaselineId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleId"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.ConstantSegment("baselineName", PossibleValuesForVulnerabilityAssessmentPolicyBaselineName(), "default"), + } +} + +// String returns a human-readable description of this Baseline Baseline ID +func (id BaselineBaselineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Rule: %q", id.RuleId), + fmt.Sprintf("Baseline Name: %q", string(id.BaselineName)), + } + return fmt.Sprintf("Baseline Baseline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go new file mode 100644 index 00000000000..9b52f2116df --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go @@ -0,0 +1,447 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +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 = &BaselineBaselineId{} + +func TestNewBaselineBaselineID(t *testing.T) { + id := NewBaselineBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "ruleId", "default") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.RuleId != "ruleId" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleId") + } + + if id.BaselineName != "default" { + t.Fatalf("Expected %q but got %q for Segment 'BaselineName'", id.BaselineName, "default") + } +} + +func TestFormatBaselineBaselineID(t *testing.T) { + actual := NewBaselineBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "ruleId", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBaselineBaselineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineBaselineId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default", + Expected: &BaselineBaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + RuleId: "ruleId", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineBaselineID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestParseBaselineBaselineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineBaselineId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default", + Expected: &BaselineBaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + RuleId: "ruleId", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/rules/ruleId/baselines/default/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD/bAsElInEs/dEfAuLt", + Expected: &BaselineBaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + RuleId: "rUlEiD", + BaselineName: "default", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiD/bAsElInEs/dEfAuLt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineBaselineIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestSegmentsForBaselineBaselineId(t *testing.T) { + segments := BaselineBaselineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BaselineBaselineId 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/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go new file mode 100644 index 00000000000..699b0560bb2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go @@ -0,0 +1,57 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessmentRuleBaseline +} + +// CreateOrUpdate ... +func (c ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient) CreateOrUpdate(ctx context.Context, id BaselineBaselineId, input DatabaseVulnerabilityAssessmentRuleBaseline) (result CreateOrUpdateOperationResponse, 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 DatabaseVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go new file mode 100644 index 00000000000..8152c098329 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go @@ -0,0 +1,46 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient) Delete(ctx context.Context, id BaselineBaselineId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go new file mode 100644 index 00000000000..de5a6f52a37 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go @@ -0,0 +1,53 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +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 *DatabaseVulnerabilityAssessmentRuleBaseline +} + +// Get ... +func (c ManagedDatabaseVulnerabilityAssessmentRuleBaselinesClient) Get(ctx context.Context, id BaselineBaselineId) (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 DatabaseVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..51520aebbc0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go @@ -0,0 +1,11 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentRuleBaseline struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseVulnerabilityAssessmentRuleBaselineProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go new file mode 100644 index 00000000000..02894891d26 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go @@ -0,0 +1,8 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentRuleBaselineItem struct { + Result []string `json:"result"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..2b95162f928 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go @@ -0,0 +1,8 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentRuleBaselineProperties struct { + BaselineResults []DatabaseVulnerabilityAssessmentRuleBaselineItem `json:"baselineResults"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/version.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/version.go new file mode 100644 index 00000000000..c04cd4a1f15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentrulebaselines/version.go @@ -0,0 +1,10 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasevulnerabilityassessmentrulebaselines/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/README.md b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/README.md new file mode 100644 index 00000000000..a447ecca689 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments` Documentation + +The `manageddatabasevulnerabilityassessments` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := manageddatabasevulnerabilityassessments.NewManagedDatabaseVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := manageddatabasevulnerabilityassessments.DatabaseVulnerabilityAssessment{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedDatabaseVulnerabilityAssessmentsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/client.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/client.go new file mode 100644 index 00000000000..5b498f34f62 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/client.go @@ -0,0 +1,26 @@ +package manageddatabasevulnerabilityassessments + +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 ManagedDatabaseVulnerabilityAssessmentsClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseVulnerabilityAssessmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseVulnerabilityAssessmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasevulnerabilityassessments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseVulnerabilityAssessmentsClient: %+v", err) + } + + return &ManagedDatabaseVulnerabilityAssessmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..62d505f7a76 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,60 @@ +package manageddatabasevulnerabilityassessments + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessment +} + +// CreateOrUpdate ... +func (c ManagedDatabaseVulnerabilityAssessmentsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input DatabaseVulnerabilityAssessment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 DatabaseVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..8adcc72438d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_delete.go @@ -0,0 +1,48 @@ +package manageddatabasevulnerabilityassessments + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedDatabaseVulnerabilityAssessmentsClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..d3c051996fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_get.go @@ -0,0 +1,55 @@ +package manageddatabasevulnerabilityassessments + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessment +} + +// Get ... +func (c ManagedDatabaseVulnerabilityAssessmentsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 DatabaseVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_listbydatabase.go new file mode 100644 index 00000000000..0bb5ed97468 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/method_listbydatabase.go @@ -0,0 +1,106 @@ +package manageddatabasevulnerabilityassessments + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseVulnerabilityAssessment +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseVulnerabilityAssessment +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/vulnerabilityAssessments", 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 *[]DatabaseVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, DatabaseVulnerabilityAssessmentOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate DatabaseVulnerabilityAssessmentOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]DatabaseVulnerabilityAssessment, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go new file mode 100644 index 00000000000..55cd527d47e --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go @@ -0,0 +1,11 @@ +package manageddatabasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..7dffabda560 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package manageddatabasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..775925c306d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package manageddatabasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..5254e2baffc --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseVulnerabilityAssessmentOperationPredicate) Matches(input DatabaseVulnerabilityAssessment) 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/sql/2023-08-01/manageddatabasevulnerabilityassessments/version.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/version.go new file mode 100644 index 00000000000..b94622a35a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessments/version.go @@ -0,0 +1,10 @@ +package manageddatabasevulnerabilityassessments + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasevulnerabilityassessments/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..675d99c0c36 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans` Documentation + +The `manageddatabasevulnerabilityassessmentscans` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans" +``` + + +### Client Initialization + +```go +client := manageddatabasevulnerabilityassessmentscans.NewManagedDatabaseVulnerabilityAssessmentScansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentScansClient.Export` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentscans.NewVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "scanId") + +read, err := client.Export(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentScansClient.Get` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentscans.NewVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "scanId") + +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: `ManagedDatabaseVulnerabilityAssessmentScansClient.InitiateScan` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentscans.NewVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "scanId") + +if err := client.InitiateScanThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentScansClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..95d6cefb6bf --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/client.go @@ -0,0 +1,26 @@ +package manageddatabasevulnerabilityassessmentscans + +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 ManagedDatabaseVulnerabilityAssessmentScansClient struct { + Client *resourcemanager.Client +} + +func NewManagedDatabaseVulnerabilityAssessmentScansClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedDatabaseVulnerabilityAssessmentScansClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "manageddatabasevulnerabilityassessmentscans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedDatabaseVulnerabilityAssessmentScansClient: %+v", err) + } + + return &ManagedDatabaseVulnerabilityAssessmentScansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..2dd8be01b0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/constants.go @@ -0,0 +1,98 @@ +package manageddatabasevulnerabilityassessmentscans + +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 VulnerabilityAssessmentScanState string + +const ( + VulnerabilityAssessmentScanStateFailed VulnerabilityAssessmentScanState = "Failed" + VulnerabilityAssessmentScanStateFailedToRun VulnerabilityAssessmentScanState = "FailedToRun" + VulnerabilityAssessmentScanStateInProgress VulnerabilityAssessmentScanState = "InProgress" + VulnerabilityAssessmentScanStatePassed VulnerabilityAssessmentScanState = "Passed" +) + +func PossibleValuesForVulnerabilityAssessmentScanState() []string { + return []string{ + string(VulnerabilityAssessmentScanStateFailed), + string(VulnerabilityAssessmentScanStateFailedToRun), + string(VulnerabilityAssessmentScanStateInProgress), + string(VulnerabilityAssessmentScanStatePassed), + } +} + +func (s *VulnerabilityAssessmentScanState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanState(input string) (*VulnerabilityAssessmentScanState, error) { + vals := map[string]VulnerabilityAssessmentScanState{ + "failed": VulnerabilityAssessmentScanStateFailed, + "failedtorun": VulnerabilityAssessmentScanStateFailedToRun, + "inprogress": VulnerabilityAssessmentScanStateInProgress, + "passed": VulnerabilityAssessmentScanStatePassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanState(input) + return &out, nil +} + +type VulnerabilityAssessmentScanTriggerType string + +const ( + VulnerabilityAssessmentScanTriggerTypeOnDemand VulnerabilityAssessmentScanTriggerType = "OnDemand" + VulnerabilityAssessmentScanTriggerTypeRecurring VulnerabilityAssessmentScanTriggerType = "Recurring" +) + +func PossibleValuesForVulnerabilityAssessmentScanTriggerType() []string { + return []string{ + string(VulnerabilityAssessmentScanTriggerTypeOnDemand), + string(VulnerabilityAssessmentScanTriggerTypeRecurring), + } +} + +func (s *VulnerabilityAssessmentScanTriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanTriggerType(input string) (*VulnerabilityAssessmentScanTriggerType, error) { + vals := map[string]VulnerabilityAssessmentScanTriggerType{ + "ondemand": VulnerabilityAssessmentScanTriggerTypeOnDemand, + "recurring": VulnerabilityAssessmentScanTriggerTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanTriggerType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go new file mode 100644 index 00000000000..7181bfe4278 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go @@ -0,0 +1,150 @@ +package manageddatabasevulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VulnerabilityAssessmentVulnerabilityAssessmentScanId{}) +} + +var _ resourceids.ResourceId = &VulnerabilityAssessmentVulnerabilityAssessmentScanId{} + +// VulnerabilityAssessmentVulnerabilityAssessmentScanId is a struct representing the Resource ID for a Vulnerability Assessment Vulnerability Assessment Scan +type VulnerabilityAssessmentVulnerabilityAssessmentScanId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DatabaseName string + ScanId string +} + +// NewVulnerabilityAssessmentVulnerabilityAssessmentScanID returns a new VulnerabilityAssessmentVulnerabilityAssessmentScanId struct +func NewVulnerabilityAssessmentVulnerabilityAssessmentScanID(subscriptionId string, resourceGroupName string, managedInstanceName string, databaseName string, scanId string) VulnerabilityAssessmentVulnerabilityAssessmentScanId { + return VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DatabaseName: databaseName, + ScanId: scanId, + } +} + +// ParseVulnerabilityAssessmentVulnerabilityAssessmentScanID parses 'input' into a VulnerabilityAssessmentVulnerabilityAssessmentScanId +func ParseVulnerabilityAssessmentVulnerabilityAssessmentScanID(input string) (*VulnerabilityAssessmentVulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&VulnerabilityAssessmentVulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VulnerabilityAssessmentVulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively parses 'input' case-insensitively into a VulnerabilityAssessmentVulnerabilityAssessmentScanId +// note: this method should only be used for API response data and not user input +func ParseVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(input string) (*VulnerabilityAssessmentVulnerabilityAssessmentScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&VulnerabilityAssessmentVulnerabilityAssessmentScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VulnerabilityAssessmentVulnerabilityAssessmentScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VulnerabilityAssessmentVulnerabilityAssessmentScanId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateVulnerabilityAssessmentVulnerabilityAssessmentScanID checks that 'input' can be parsed as a Vulnerability Assessment Vulnerability Assessment Scan ID +func ValidateVulnerabilityAssessmentVulnerabilityAssessmentScanID(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 := ParseVulnerabilityAssessmentVulnerabilityAssessmentScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Vulnerability Assessment Vulnerability Assessment Scan ID +func (id VulnerabilityAssessmentVulnerabilityAssessmentScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/databases/%s/vulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DatabaseName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Vulnerability Assessment Vulnerability Assessment Scan ID +func (id VulnerabilityAssessmentVulnerabilityAssessmentScanId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + } +} + +// String returns a human-readable description of this Vulnerability Assessment Vulnerability Assessment Scan ID +func (id VulnerabilityAssessmentVulnerabilityAssessmentScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Vulnerability Assessment Vulnerability Assessment Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..4348942eade --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go @@ -0,0 +1,402 @@ +package manageddatabasevulnerabilityassessmentscans + +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 = &VulnerabilityAssessmentVulnerabilityAssessmentScanId{} + +func TestNewVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + id := NewVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "scanId") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } +} + +func TestFormatVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName", "scanId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VulnerabilityAssessmentVulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId", + Expected: &VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVulnerabilityAssessmentVulnerabilityAssessmentScanID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VulnerabilityAssessmentVulnerabilityAssessmentScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId", + Expected: &VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DatabaseName: "databaseName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/databases/databaseName/vulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiD", + Expected: &VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DatabaseName: "dAtAbAsEnAmE", + ScanId: "sCaNiD", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dAtAbAsEs/dAtAbAsEnAmE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVulnerabilityAssessmentVulnerabilityAssessmentScanIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForVulnerabilityAssessmentVulnerabilityAssessmentScanId(t *testing.T) { + segments := VulnerabilityAssessmentVulnerabilityAssessmentScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VulnerabilityAssessmentVulnerabilityAssessmentScanId 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/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_export.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_export.go new file mode 100644 index 00000000000..c8fef962b10 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_export.go @@ -0,0 +1,54 @@ +package manageddatabasevulnerabilityassessmentscans + +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 ExportOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseVulnerabilityAssessmentScansExport +} + +// Export ... +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) Export(ctx context.Context, id VulnerabilityAssessmentVulnerabilityAssessmentScanId) (result ExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", 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 DatabaseVulnerabilityAssessmentScansExport + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..4de075471df --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_get.go @@ -0,0 +1,53 @@ +package manageddatabasevulnerabilityassessmentscans + +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 *VulnerabilityAssessmentScanRecord +} + +// Get ... +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) Get(ctx context.Context, id VulnerabilityAssessmentVulnerabilityAssessmentScanId) (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 VulnerabilityAssessmentScanRecord + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go new file mode 100644 index 00000000000..051858dda7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go @@ -0,0 +1,70 @@ +package manageddatabasevulnerabilityassessmentscans + +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 InitiateScanOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// InitiateScan ... +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) InitiateScan(ctx context.Context, id VulnerabilityAssessmentVulnerabilityAssessmentScanId) (result InitiateScanOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/initiateScan", 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 +} + +// InitiateScanThenPoll performs InitiateScan then polls until it's completed +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) InitiateScanThenPoll(ctx context.Context, id VulnerabilityAssessmentVulnerabilityAssessmentScanId) error { + result, err := c.InitiateScan(ctx, id) + if err != nil { + return fmt.Errorf("performing InitiateScan: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after InitiateScan: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go new file mode 100644 index 00000000000..b494431be17 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go @@ -0,0 +1,106 @@ +package manageddatabasevulnerabilityassessmentscans + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VulnerabilityAssessmentScanRecord +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []VulnerabilityAssessmentScanRecord +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default/scans", 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 *[]VulnerabilityAssessmentScanRecord `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, VulnerabilityAssessmentScanRecordOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedDatabaseVulnerabilityAssessmentScansClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate VulnerabilityAssessmentScanRecordOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]VulnerabilityAssessmentScanRecord, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go new file mode 100644 index 00000000000..2365479151f --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go @@ -0,0 +1,8 @@ +package manageddatabasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentScanExportProperties struct { + ExportedReportLocation *string `json:"exportedReportLocation,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go new file mode 100644 index 00000000000..6297231472b --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go @@ -0,0 +1,11 @@ +package manageddatabasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssessmentScansExport struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseVulnerabilityAssessmentScanExportProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..cdd00897ede --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go @@ -0,0 +1,9 @@ +package manageddatabasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..5c6b78cee88 --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go @@ -0,0 +1,11 @@ +package manageddatabasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecord struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VulnerabilityAssessmentScanRecordProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..f7b4e65fdca --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go @@ -0,0 +1,45 @@ +package manageddatabasevulnerabilityassessmentscans + +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 VulnerabilityAssessmentScanRecordProperties struct { + EndTime *string `json:"endTime,omitempty"` + Errors *[]VulnerabilityAssessmentScanError `json:"errors,omitempty"` + NumberOfFailedSecurityChecks *int64 `json:"numberOfFailedSecurityChecks,omitempty"` + ScanId *string `json:"scanId,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *VulnerabilityAssessmentScanState `json:"state,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + TriggerType *VulnerabilityAssessmentScanTriggerType `json:"triggerType,omitempty"` +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..5f80e6070ce --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/predicates.go @@ -0,0 +1,27 @@ +package manageddatabasevulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecordOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VulnerabilityAssessmentScanRecordOperationPredicate) Matches(input VulnerabilityAssessmentScanRecord) 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/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..2854986497d --- /dev/null +++ b/resource-manager/sql/2023-08-01/manageddatabasevulnerabilityassessmentscans/version.go @@ -0,0 +1,10 @@ +package manageddatabasevulnerabilityassessmentscans + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/manageddatabasevulnerabilityassessmentscans/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/README.md b/resource-manager/sql/2023-08-01/managedinstanceadministrators/README.md new file mode 100644 index 00000000000..bb64c35d52e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceadministrators` Documentation + +The `managedinstanceadministrators` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceadministrators" +``` + + +### Client Initialization + +```go +client := managedinstanceadministrators.NewManagedInstanceAdministratorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceAdministratorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstanceadministrators.ManagedInstanceAdministrator{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAdministratorsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAdministratorsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedInstanceAdministratorsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/client.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/client.go new file mode 100644 index 00000000000..a7a2aabd80b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/client.go @@ -0,0 +1,26 @@ +package managedinstanceadministrators + +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 ManagedInstanceAdministratorsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceAdministratorsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceAdministratorsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceadministrators", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceAdministratorsClient: %+v", err) + } + + return &ManagedInstanceAdministratorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/constants.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/constants.go new file mode 100644 index 00000000000..fe42a066758 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/constants.go @@ -0,0 +1,48 @@ +package managedinstanceadministrators + +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 ManagedInstanceAdministratorType string + +const ( + ManagedInstanceAdministratorTypeActiveDirectory ManagedInstanceAdministratorType = "ActiveDirectory" +) + +func PossibleValuesForManagedInstanceAdministratorType() []string { + return []string{ + string(ManagedInstanceAdministratorTypeActiveDirectory), + } +} + +func (s *ManagedInstanceAdministratorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedInstanceAdministratorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedInstanceAdministratorType(input string) (*ManagedInstanceAdministratorType, error) { + vals := map[string]ManagedInstanceAdministratorType{ + "activedirectory": ManagedInstanceAdministratorTypeActiveDirectory, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedInstanceAdministratorType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_createorupdate.go new file mode 100644 index 00000000000..9badd8f01f1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_createorupdate.go @@ -0,0 +1,77 @@ +package managedinstanceadministrators + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceAdministrator +} + +// CreateOrUpdate ... +func (c ManagedInstanceAdministratorsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceAdministrator) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/administrators/ActiveDirectory", 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 ManagedInstanceAdministratorsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceAdministrator) 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/sql/2023-08-01/managedinstanceadministrators/method_delete.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_delete.go new file mode 100644 index 00000000000..361291d6638 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_delete.go @@ -0,0 +1,71 @@ +package managedinstanceadministrators + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedInstanceAdministratorsClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/administrators/ActiveDirectory", 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 ManagedInstanceAdministratorsClient) DeleteThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) 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/sql/2023-08-01/managedinstanceadministrators/method_get.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_get.go new file mode 100644 index 00000000000..c4397fcdc5d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_get.go @@ -0,0 +1,55 @@ +package managedinstanceadministrators + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceAdministrator +} + +// Get ... +func (c ManagedInstanceAdministratorsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/administrators/ActiveDirectory", 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 ManagedInstanceAdministrator + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_listbyinstance.go new file mode 100644 index 00000000000..9bef3057cbd --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/method_listbyinstance.go @@ -0,0 +1,106 @@ +package managedinstanceadministrators + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceAdministrator +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceAdministrator +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedInstanceAdministratorsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/administrators", 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 *[]ManagedInstanceAdministrator `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceAdministratorsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceAdministratorOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceAdministratorsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceAdministratorOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceAdministrator, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministrator.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministrator.go new file mode 100644 index 00000000000..a77cf4a72e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministrator.go @@ -0,0 +1,11 @@ +package managedinstanceadministrators + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAdministrator struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceAdministratorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministratorproperties.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministratorproperties.go new file mode 100644 index 00000000000..062aab44bde --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/model_managedinstanceadministratorproperties.go @@ -0,0 +1,11 @@ +package managedinstanceadministrators + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAdministratorProperties struct { + AdministratorType ManagedInstanceAdministratorType `json:"administratorType"` + Login string `json:"login"` + Sid string `json:"sid"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadministrators/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/predicates.go new file mode 100644 index 00000000000..d8dcbcc98be --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/predicates.go @@ -0,0 +1,27 @@ +package managedinstanceadministrators + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAdministratorOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceAdministratorOperationPredicate) Matches(input ManagedInstanceAdministrator) 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/sql/2023-08-01/managedinstanceadministrators/version.go b/resource-manager/sql/2023-08-01/managedinstanceadministrators/version.go new file mode 100644 index 00000000000..c40ef11595b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadministrators/version.go @@ -0,0 +1,10 @@ +package managedinstanceadministrators + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceadministrators/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..8f047ad51d8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings` Documentation + +The `managedinstanceadvancedthreatprotectionsettings` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := managedinstanceadvancedthreatprotectionsettings.NewManagedInstanceAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstanceadvancedthreatprotectionsettings.ManagedInstanceAdvancedThreatProtection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAdvancedThreatProtectionSettingsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedInstanceAdvancedThreatProtectionSettingsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..6d5512300a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/client.go @@ -0,0 +1,26 @@ +package managedinstanceadvancedthreatprotectionsettings + +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 ManagedInstanceAdvancedThreatProtectionSettingsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceAdvancedThreatProtectionSettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceadvancedthreatprotectionsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceAdvancedThreatProtectionSettingsClient: %+v", err) + } + + return &ManagedInstanceAdvancedThreatProtectionSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..a5c225ee109 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/constants.go @@ -0,0 +1,54 @@ +package managedinstanceadvancedthreatprotectionsettings + +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 AdvancedThreatProtectionState string + +const ( + AdvancedThreatProtectionStateDisabled AdvancedThreatProtectionState = "Disabled" + AdvancedThreatProtectionStateEnabled AdvancedThreatProtectionState = "Enabled" + AdvancedThreatProtectionStateNew AdvancedThreatProtectionState = "New" +) + +func PossibleValuesForAdvancedThreatProtectionState() []string { + return []string{ + string(AdvancedThreatProtectionStateDisabled), + string(AdvancedThreatProtectionStateEnabled), + string(AdvancedThreatProtectionStateNew), + } +} + +func (s *AdvancedThreatProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvancedThreatProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvancedThreatProtectionState(input string) (*AdvancedThreatProtectionState, error) { + vals := map[string]AdvancedThreatProtectionState{ + "disabled": AdvancedThreatProtectionStateDisabled, + "enabled": AdvancedThreatProtectionStateEnabled, + "new": AdvancedThreatProtectionStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvancedThreatProtectionState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..d247ff982a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedinstanceadvancedthreatprotectionsettings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceAdvancedThreatProtection +} + +// CreateOrUpdate ... +func (c ManagedInstanceAdvancedThreatProtectionSettingsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceAdvancedThreatProtection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedInstanceAdvancedThreatProtectionSettingsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceAdvancedThreatProtection) 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/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..fc9c442e4b6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,55 @@ +package managedinstanceadvancedthreatprotectionsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceAdvancedThreatProtection +} + +// Get ... +func (c ManagedInstanceAdvancedThreatProtectionSettingsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 ManagedInstanceAdvancedThreatProtection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go new file mode 100644 index 00000000000..25fe1f3b75d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go @@ -0,0 +1,106 @@ +package managedinstanceadvancedthreatprotectionsettings + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceAdvancedThreatProtection +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceAdvancedThreatProtection +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedInstanceAdvancedThreatProtectionSettingsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings", 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 *[]ManagedInstanceAdvancedThreatProtection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceAdvancedThreatProtectionSettingsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceAdvancedThreatProtectionOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceAdvancedThreatProtectionSettingsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceAdvancedThreatProtectionOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceAdvancedThreatProtection, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..309b1f0c85a --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go @@ -0,0 +1,27 @@ +package managedinstanceadvancedthreatprotectionsettings + +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 AdvancedThreatProtectionProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + State AdvancedThreatProtectionState `json:"state"` +} + +func (o *AdvancedThreatProtectionProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AdvancedThreatProtectionProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go new file mode 100644 index 00000000000..9649b76e1ed --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go @@ -0,0 +1,16 @@ +package managedinstanceadvancedthreatprotectionsettings + +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 ManagedInstanceAdvancedThreatProtection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvancedThreatProtectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..d926de0e8c8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/predicates.go @@ -0,0 +1,27 @@ +package managedinstanceadvancedthreatprotectionsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAdvancedThreatProtectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceAdvancedThreatProtectionOperationPredicate) Matches(input ManagedInstanceAdvancedThreatProtection) 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/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..a159cc67399 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceadvancedthreatprotectionsettings/version.go @@ -0,0 +1,10 @@ +package managedinstanceadvancedthreatprotectionsettings + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceadvancedthreatprotectionsettings/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/README.md b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/README.md new file mode 100644 index 00000000000..065bbb5ba9d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications` Documentation + +The `managedinstanceazureadonlyauthentications` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications" +``` + + +### Client Initialization + +```go +client := managedinstanceazureadonlyauthentications.NewManagedInstanceAzureADOnlyAuthenticationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceAzureADOnlyAuthenticationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstanceazureadonlyauthentications.ManagedInstanceAzureADOnlyAuthentication{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAzureADOnlyAuthenticationsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAzureADOnlyAuthenticationsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedInstanceAzureADOnlyAuthenticationsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/client.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/client.go new file mode 100644 index 00000000000..b6f667aa0f1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/client.go @@ -0,0 +1,26 @@ +package managedinstanceazureadonlyauthentications + +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 ManagedInstanceAzureADOnlyAuthenticationsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceAzureADOnlyAuthenticationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceAzureADOnlyAuthenticationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceazureadonlyauthentications", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceAzureADOnlyAuthenticationsClient: %+v", err) + } + + return &ManagedInstanceAzureADOnlyAuthenticationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_createorupdate.go new file mode 100644 index 00000000000..f19f00fc10c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_createorupdate.go @@ -0,0 +1,77 @@ +package managedinstanceazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceAzureADOnlyAuthentication +} + +// CreateOrUpdate ... +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceAzureADOnlyAuthentication) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceAzureADOnlyAuthentication) 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/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_delete.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_delete.go new file mode 100644 index 00000000000..d2e4dfa73c2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_delete.go @@ -0,0 +1,72 @@ +package managedinstanceazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceId) (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/azureADOnlyAuthentications/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 ManagedInstanceAzureADOnlyAuthenticationsClient) DeleteThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) 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/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_get.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_get.go new file mode 100644 index 00000000000..5b42ddb7ce2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_get.go @@ -0,0 +1,55 @@ +package managedinstanceazureadonlyauthentications + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceAzureADOnlyAuthentication +} + +// Get ... +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications/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 ManagedInstanceAzureADOnlyAuthentication + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_listbyinstance.go new file mode 100644 index 00000000000..4cd27d8d271 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/method_listbyinstance.go @@ -0,0 +1,106 @@ +package managedinstanceazureadonlyauthentications + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceAzureADOnlyAuthentication +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceAzureADOnlyAuthentication +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications", 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 *[]ManagedInstanceAzureADOnlyAuthentication `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceAzureADOnlyAuthenticationOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceAzureADOnlyAuthenticationsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceAzureADOnlyAuthenticationOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceAzureADOnlyAuthentication, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go new file mode 100644 index 00000000000..9ad59f4b07c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go @@ -0,0 +1,11 @@ +package managedinstanceazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAzureADOnlyAuthentication struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceAzureADOnlyAuthProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go new file mode 100644 index 00000000000..ffd1c383c02 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go @@ -0,0 +1,8 @@ +package managedinstanceazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAzureADOnlyAuthProperties struct { + AzureADOnlyAuthentication bool `json:"azureADOnlyAuthentication"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/predicates.go new file mode 100644 index 00000000000..26056826c21 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/predicates.go @@ -0,0 +1,27 @@ +package managedinstanceazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceAzureADOnlyAuthenticationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceAzureADOnlyAuthenticationOperationPredicate) Matches(input ManagedInstanceAzureADOnlyAuthentication) 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/sql/2023-08-01/managedinstanceazureadonlyauthentications/version.go b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/version.go new file mode 100644 index 00000000000..ad3f684f9e4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceazureadonlyauthentications/version.go @@ -0,0 +1,10 @@ +package managedinstanceazureadonlyauthentications + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceazureadonlyauthentications/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/README.md b/resource-manager/sql/2023-08-01/managedinstancedtcs/README.md new file mode 100644 index 00000000000..4060b6040eb --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancedtcs` Documentation + +The `managedinstancedtcs` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancedtcs" +``` + + +### Client Initialization + +```go +client := managedinstancedtcs.NewManagedInstanceDtcsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceDtcsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstancedtcs.ManagedInstanceDtc{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceDtcsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedInstanceDtcsClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/client.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/client.go new file mode 100644 index 00000000000..4fba23c94a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/client.go @@ -0,0 +1,26 @@ +package managedinstancedtcs + +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 ManagedInstanceDtcsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceDtcsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceDtcsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstancedtcs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceDtcsClient: %+v", err) + } + + return &ManagedInstanceDtcsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/constants.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/constants.go new file mode 100644 index 00000000000..1973c9e2fe2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/constants.go @@ -0,0 +1,60 @@ +package managedinstancedtcs + +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 ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + 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{ + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/method_createorupdate.go new file mode 100644 index 00000000000..eaa0a64ba0f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/method_createorupdate.go @@ -0,0 +1,75 @@ +package managedinstancedtcs + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceDtc +} + +// CreateOrUpdate ... +func (c ManagedInstanceDtcsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceDtc) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/dtc/current", 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 ManagedInstanceDtcsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceDtc) 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/sql/2023-08-01/managedinstancedtcs/method_get.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/method_get.go new file mode 100644 index 00000000000..39f964596b4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/method_get.go @@ -0,0 +1,55 @@ +package managedinstancedtcs + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceDtc +} + +// Get ... +func (c ManagedInstanceDtcsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dtc/current", 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 ManagedInstanceDtc + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/method_listbymanagedinstance.go new file mode 100644 index 00000000000..a3186adf70c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/method_listbymanagedinstance.go @@ -0,0 +1,106 @@ +package managedinstancedtcs + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceDtc +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceDtc +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ManagedInstanceDtcsClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/dtc", 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 *[]ManagedInstanceDtc `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceDtcsClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceDtcOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceDtcsClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceDtcOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]ManagedInstanceDtc, 0) + + resp, err := c.ListByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtc.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtc.go new file mode 100644 index 00000000000..8d676dec3ca --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtc.go @@ -0,0 +1,11 @@ +package managedinstancedtcs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceDtc struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceDtcProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcproperties.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcproperties.go new file mode 100644 index 00000000000..3789640f1dd --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcproperties.go @@ -0,0 +1,12 @@ +package managedinstancedtcs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceDtcProperties struct { + DtcEnabled *bool `json:"dtcEnabled,omitempty"` + DtcHostNameDnsSuffix *string `json:"dtcHostNameDnsSuffix,omitempty"` + ExternalDnsSuffixSearchList *[]string `json:"externalDnsSuffixSearchList,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SecuritySettings *ManagedInstanceDtcSecuritySettings `json:"securitySettings,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go new file mode 100644 index 00000000000..303ae208da2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go @@ -0,0 +1,12 @@ +package managedinstancedtcs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceDtcSecuritySettings struct { + SnaLu6point2TransactionsEnabled *bool `json:"snaLu6point2TransactionsEnabled,omitempty"` + TransactionManagerCommunicationSettings *ManagedInstanceDtcTransactionManagerCommunicationSettings `json:"transactionManagerCommunicationSettings,omitempty"` + XaTransactionsDefaultTimeout *int64 `json:"xaTransactionsDefaultTimeout,omitempty"` + XaTransactionsEnabled *bool `json:"xaTransactionsEnabled,omitempty"` + XaTransactionsMaximumTimeout *int64 `json:"xaTransactionsMaximumTimeout,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go new file mode 100644 index 00000000000..a60433ea852 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go @@ -0,0 +1,10 @@ +package managedinstancedtcs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceDtcTransactionManagerCommunicationSettings struct { + AllowInboundEnabled *bool `json:"allowInboundEnabled,omitempty"` + AllowOutboundEnabled *bool `json:"allowOutboundEnabled,omitempty"` + Authentication *string `json:"authentication,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancedtcs/predicates.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/predicates.go new file mode 100644 index 00000000000..4ebde0c6a52 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/predicates.go @@ -0,0 +1,27 @@ +package managedinstancedtcs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceDtcOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceDtcOperationPredicate) Matches(input ManagedInstanceDtc) 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/sql/2023-08-01/managedinstancedtcs/version.go b/resource-manager/sql/2023-08-01/managedinstancedtcs/version.go new file mode 100644 index 00000000000..458f63ca53f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancedtcs/version.go @@ -0,0 +1,10 @@ +package managedinstancedtcs + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstancedtcs/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/README.md b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/README.md new file mode 100644 index 00000000000..5e6e0928f05 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors` Documentation + +The `managedinstanceencryptionprotectors` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors" +``` + + +### Client Initialization + +```go +client := managedinstanceencryptionprotectors.NewManagedInstanceEncryptionProtectorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceEncryptionProtectorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstanceencryptionprotectors.ManagedInstanceEncryptionProtector{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceEncryptionProtectorsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedInstanceEncryptionProtectorsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedInstanceEncryptionProtectorsClient.Revalidate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.RevalidateThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/client.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/client.go new file mode 100644 index 00000000000..37d9140cc63 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/client.go @@ -0,0 +1,26 @@ +package managedinstanceencryptionprotectors + +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 ManagedInstanceEncryptionProtectorsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceEncryptionProtectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceEncryptionProtectorsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceencryptionprotectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceEncryptionProtectorsClient: %+v", err) + } + + return &ManagedInstanceEncryptionProtectorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/constants.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/constants.go new file mode 100644 index 00000000000..334a5ec41af --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/constants.go @@ -0,0 +1,51 @@ +package managedinstanceencryptionprotectors + +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 ServerKeyType string + +const ( + ServerKeyTypeAzureKeyVault ServerKeyType = "AzureKeyVault" + ServerKeyTypeServiceManaged ServerKeyType = "ServiceManaged" +) + +func PossibleValuesForServerKeyType() []string { + return []string{ + string(ServerKeyTypeAzureKeyVault), + string(ServerKeyTypeServiceManaged), + } +} + +func (s *ServerKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerKeyType(input string) (*ServerKeyType, error) { + vals := map[string]ServerKeyType{ + "azurekeyvault": ServerKeyTypeAzureKeyVault, + "servicemanaged": ServerKeyTypeServiceManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_createorupdate.go new file mode 100644 index 00000000000..27e82bc12a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedinstanceencryptionprotectors + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceEncryptionProtector +} + +// CreateOrUpdate ... +func (c ManagedInstanceEncryptionProtectorsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceEncryptionProtector) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/encryptionProtector/current", 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 ManagedInstanceEncryptionProtectorsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceEncryptionProtector) 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/sql/2023-08-01/managedinstanceencryptionprotectors/method_get.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_get.go new file mode 100644 index 00000000000..d999fb817fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_get.go @@ -0,0 +1,55 @@ +package managedinstanceencryptionprotectors + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceEncryptionProtector +} + +// Get ... +func (c ManagedInstanceEncryptionProtectorsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/encryptionProtector/current", 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 ManagedInstanceEncryptionProtector + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_listbyinstance.go new file mode 100644 index 00000000000..92441270ccc --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_listbyinstance.go @@ -0,0 +1,106 @@ +package managedinstanceencryptionprotectors + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceEncryptionProtector +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceEncryptionProtector +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedInstanceEncryptionProtectorsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/encryptionProtector", 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 *[]ManagedInstanceEncryptionProtector `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceEncryptionProtectorsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceEncryptionProtectorOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceEncryptionProtectorsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceEncryptionProtectorOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceEncryptionProtector, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_revalidate.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_revalidate.go new file mode 100644 index 00000000000..e51f2c2c415 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/method_revalidate.go @@ -0,0 +1,71 @@ +package managedinstanceencryptionprotectors + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RevalidateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Revalidate ... +func (c ManagedInstanceEncryptionProtectorsClient) Revalidate(ctx context.Context, id commonids.SqlManagedInstanceId) (result RevalidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/encryptionProtector/current/revalidate", 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 +} + +// RevalidateThenPoll performs Revalidate then polls until it's completed +func (c ManagedInstanceEncryptionProtectorsClient) RevalidateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) error { + result, err := c.Revalidate(ctx, id) + if err != nil { + return fmt.Errorf("performing Revalidate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Revalidate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go new file mode 100644 index 00000000000..6dbec21f08d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go @@ -0,0 +1,12 @@ +package managedinstanceencryptionprotectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceEncryptionProtector struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceEncryptionProtectorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go new file mode 100644 index 00000000000..0b78a822cea --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go @@ -0,0 +1,12 @@ +package managedinstanceencryptionprotectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceEncryptionProtectorProperties struct { + AutoRotationEnabled *bool `json:"autoRotationEnabled,omitempty"` + ServerKeyName *string `json:"serverKeyName,omitempty"` + ServerKeyType ServerKeyType `json:"serverKeyType"` + Thumbprint *string `json:"thumbprint,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/predicates.go new file mode 100644 index 00000000000..3d36552bf7f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/predicates.go @@ -0,0 +1,32 @@ +package managedinstanceencryptionprotectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceEncryptionProtectorOperationPredicate struct { + Id *string + Kind *string + Name *string + Type *string +} + +func (p ManagedInstanceEncryptionProtectorOperationPredicate) Matches(input ManagedInstanceEncryptionProtector) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/managedinstanceencryptionprotectors/version.go b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/version.go new file mode 100644 index 00000000000..b9806e1396f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceencryptionprotectors/version.go @@ -0,0 +1,10 @@ +package managedinstanceencryptionprotectors + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceencryptionprotectors/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/README.md b/resource-manager/sql/2023-08-01/managedinstancekeys/README.md new file mode 100644 index 00000000000..2a15237dd5d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancekeys` Documentation + +The `managedinstancekeys` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancekeys" +``` + + +### Client Initialization + +```go +client := managedinstancekeys.NewManagedInstanceKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceKeysClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstancekeys.NewManagedInstanceKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "keyName") + +payload := managedinstancekeys.ManagedInstanceKey{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceKeysClient.Delete` + +```go +ctx := context.TODO() +id := managedinstancekeys.NewManagedInstanceKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "keyName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceKeysClient.Get` + +```go +ctx := context.TODO() +id := managedinstancekeys.NewManagedInstanceKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "keyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedInstanceKeysClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id, managedinstancekeys.DefaultListByInstanceOperationOptions())` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id, managedinstancekeys.DefaultListByInstanceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/client.go b/resource-manager/sql/2023-08-01/managedinstancekeys/client.go new file mode 100644 index 00000000000..10eda0b8020 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/client.go @@ -0,0 +1,26 @@ +package managedinstancekeys + +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 ManagedInstanceKeysClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceKeysClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstancekeys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceKeysClient: %+v", err) + } + + return &ManagedInstanceKeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/constants.go b/resource-manager/sql/2023-08-01/managedinstancekeys/constants.go new file mode 100644 index 00000000000..cb6c195b1a5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/constants.go @@ -0,0 +1,51 @@ +package managedinstancekeys + +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 ServerKeyType string + +const ( + ServerKeyTypeAzureKeyVault ServerKeyType = "AzureKeyVault" + ServerKeyTypeServiceManaged ServerKeyType = "ServiceManaged" +) + +func PossibleValuesForServerKeyType() []string { + return []string{ + string(ServerKeyTypeAzureKeyVault), + string(ServerKeyTypeServiceManaged), + } +} + +func (s *ServerKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerKeyType(input string) (*ServerKeyType, error) { + vals := map[string]ServerKeyType{ + "azurekeyvault": ServerKeyTypeAzureKeyVault, + "servicemanaged": ServerKeyTypeServiceManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey.go b/resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey.go new file mode 100644 index 00000000000..7d07c1ee926 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey.go @@ -0,0 +1,139 @@ +package managedinstancekeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstanceKeyId{}) +} + +var _ resourceids.ResourceId = &ManagedInstanceKeyId{} + +// ManagedInstanceKeyId is a struct representing the Resource ID for a Managed Instance Key +type ManagedInstanceKeyId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + KeyName string +} + +// NewManagedInstanceKeyID returns a new ManagedInstanceKeyId struct +func NewManagedInstanceKeyID(subscriptionId string, resourceGroupName string, managedInstanceName string, keyName string) ManagedInstanceKeyId { + return ManagedInstanceKeyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + KeyName: keyName, + } +} + +// ParseManagedInstanceKeyID parses 'input' into a ManagedInstanceKeyId +func ParseManagedInstanceKeyID(input string) (*ManagedInstanceKeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceKeyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceKeyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstanceKeyIDInsensitively parses 'input' case-insensitively into a ManagedInstanceKeyId +// note: this method should only be used for API response data and not user input +func ParseManagedInstanceKeyIDInsensitively(input string) (*ManagedInstanceKeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceKeyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceKeyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstanceKeyId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.KeyName, ok = input.Parsed["keyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "keyName", input) + } + + return nil +} + +// ValidateManagedInstanceKeyID checks that 'input' can be parsed as a Managed Instance Key ID +func ValidateManagedInstanceKeyID(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 := ParseManagedInstanceKeyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Key ID +func (id ManagedInstanceKeyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/keys/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.KeyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Key ID +func (id ManagedInstanceKeyId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyName"), + } +} + +// String returns a human-readable description of this Managed Instance Key ID +func (id ManagedInstanceKeyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Key Name: %q", id.KeyName), + } + return fmt.Sprintf("Managed Instance Key (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey_test.go b/resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey_test.go new file mode 100644 index 00000000000..0ec6d7e65fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/id_managedinstancekey_test.go @@ -0,0 +1,327 @@ +package managedinstancekeys + +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 = &ManagedInstanceKeyId{} + +func TestNewManagedInstanceKeyID(t *testing.T) { + id := NewManagedInstanceKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "keyName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.KeyName != "keyName" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyName") + } +} + +func TestFormatManagedInstanceKeyID(t *testing.T) { + actual := NewManagedInstanceKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "keyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys/keyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstanceKeyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceKeyId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys/keyName", + Expected: &ManagedInstanceKeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + KeyName: "keyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys/keyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceKeyID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestParseManagedInstanceKeyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceKeyId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys/keyName", + Expected: &ManagedInstanceKeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + KeyName: "keyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/keys/keyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/kEyS/kEyNaMe", + Expected: &ManagedInstanceKeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + KeyName: "kEyNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/kEyS/kEyNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceKeyIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestSegmentsForManagedInstanceKeyId(t *testing.T) { + segments := ManagedInstanceKeyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstanceKeyId 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/sql/2023-08-01/managedinstancekeys/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstancekeys/method_createorupdate.go new file mode 100644 index 00000000000..6e098cfdd6e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedinstancekeys + +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 *ManagedInstanceKey +} + +// CreateOrUpdate ... +func (c ManagedInstanceKeysClient) CreateOrUpdate(ctx context.Context, id ManagedInstanceKeyId, input ManagedInstanceKey) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ManagedInstanceKeysClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedInstanceKeyId, input ManagedInstanceKey) 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/sql/2023-08-01/managedinstancekeys/method_delete.go b/resource-manager/sql/2023-08-01/managedinstancekeys/method_delete.go new file mode 100644 index 00000000000..5c7df47721e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/method_delete.go @@ -0,0 +1,71 @@ +package managedinstancekeys + +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 ManagedInstanceKeysClient) Delete(ctx context.Context, id ManagedInstanceKeyId) (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 ManagedInstanceKeysClient) DeleteThenPoll(ctx context.Context, id ManagedInstanceKeyId) 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/sql/2023-08-01/managedinstancekeys/method_get.go b/resource-manager/sql/2023-08-01/managedinstancekeys/method_get.go new file mode 100644 index 00000000000..a7b6c034e21 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/method_get.go @@ -0,0 +1,53 @@ +package managedinstancekeys + +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 *ManagedInstanceKey +} + +// Get ... +func (c ManagedInstanceKeysClient) Get(ctx context.Context, id ManagedInstanceKeyId) (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 ManagedInstanceKey + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedinstancekeys/method_listbyinstance.go new file mode 100644 index 00000000000..ccdcd5aba24 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/method_listbyinstance.go @@ -0,0 +1,135 @@ +package managedinstancekeys + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceKey +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceKey +} + +type ListByInstanceOperationOptions struct { + Filter *string +} + +func DefaultListByInstanceOperationOptions() ListByInstanceOperationOptions { + return ListByInstanceOperationOptions{} +} + +func (o ListByInstanceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByInstanceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByInstanceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedInstanceKeysClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId, options ListByInstanceOperationOptions) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/keys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedInstanceKey `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceKeysClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId, options ListByInstanceOperationOptions) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, options, ManagedInstanceKeyOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceKeysClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, options ListByInstanceOperationOptions, predicate ManagedInstanceKeyOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceKey, 0) + + resp, err := c.ListByInstance(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekey.go b/resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekey.go new file mode 100644 index 00000000000..9be285e7e16 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekey.go @@ -0,0 +1,12 @@ +package managedinstancekeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceKey struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceKeyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekeyproperties.go b/resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekeyproperties.go new file mode 100644 index 00000000000..3c2e62946d0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/model_managedinstancekeyproperties.go @@ -0,0 +1,30 @@ +package managedinstancekeys + +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 ManagedInstanceKeyProperties struct { + AutoRotationEnabled *bool `json:"autoRotationEnabled,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + ServerKeyType ServerKeyType `json:"serverKeyType"` + Thumbprint *string `json:"thumbprint,omitempty"` + Uri *string `json:"uri,omitempty"` +} + +func (o *ManagedInstanceKeyProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceKeyProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/managedinstancekeys/predicates.go b/resource-manager/sql/2023-08-01/managedinstancekeys/predicates.go new file mode 100644 index 00000000000..9d02a4bfacd --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/predicates.go @@ -0,0 +1,32 @@ +package managedinstancekeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceKeyOperationPredicate struct { + Id *string + Kind *string + Name *string + Type *string +} + +func (p ManagedInstanceKeyOperationPredicate) Matches(input ManagedInstanceKey) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/managedinstancekeys/version.go b/resource-manager/sql/2023-08-01/managedinstancekeys/version.go new file mode 100644 index 00000000000..382afa5b163 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancekeys/version.go @@ -0,0 +1,10 @@ +package managedinstancekeys + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstancekeys/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/README.md b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/README.md new file mode 100644 index 00000000000..3259bbbf653 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies` Documentation + +The `managedinstancelongtermretentionpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies" +``` + + +### Client Initialization + +```go +client := managedinstancelongtermretentionpolicies.NewManagedInstanceLongTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceLongTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := managedinstancelongtermretentionpolicies.ManagedInstanceLongTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceLongTermRetentionPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceLongTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedInstanceLongTermRetentionPoliciesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/client.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/client.go new file mode 100644 index 00000000000..ed08dffdc43 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/client.go @@ -0,0 +1,26 @@ +package managedinstancelongtermretentionpolicies + +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 ManagedInstanceLongTermRetentionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceLongTermRetentionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceLongTermRetentionPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstancelongtermretentionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceLongTermRetentionPoliciesClient: %+v", err) + } + + return &ManagedInstanceLongTermRetentionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/constants.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/constants.go new file mode 100644 index 00000000000..2b0562bc53c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/constants.go @@ -0,0 +1,51 @@ +package managedinstancelongtermretentionpolicies + +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 BackupStorageAccessTier string + +const ( + BackupStorageAccessTierArchive BackupStorageAccessTier = "Archive" + BackupStorageAccessTierHot BackupStorageAccessTier = "Hot" +) + +func PossibleValuesForBackupStorageAccessTier() []string { + return []string{ + string(BackupStorageAccessTierArchive), + string(BackupStorageAccessTierHot), + } +} + +func (s *BackupStorageAccessTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageAccessTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageAccessTier(input string) (*BackupStorageAccessTier, error) { + vals := map[string]BackupStorageAccessTier{ + "archive": BackupStorageAccessTierArchive, + "hot": BackupStorageAccessTierHot, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageAccessTier(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..4ffac25baa3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedinstancelongtermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceLongTermRetentionPolicy +} + +// CreateOrUpdate ... +func (c ManagedInstanceLongTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedInstanceLongTermRetentionPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedInstanceLongTermRetentionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedInstanceLongTermRetentionPolicy) 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/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_delete.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_delete.go new file mode 100644 index 00000000000..a4296652f90 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_delete.go @@ -0,0 +1,72 @@ +package managedinstancelongtermretentionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceLongTermRetentionPolicy +} + +// Delete ... +func (c ManagedInstanceLongTermRetentionPoliciesClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies/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 ManagedInstanceLongTermRetentionPoliciesClient) DeleteThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) 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/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_get.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_get.go new file mode 100644 index 00000000000..17bc6f25917 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_get.go @@ -0,0 +1,55 @@ +package managedinstancelongtermretentionpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceLongTermRetentionPolicy +} + +// Get ... +func (c ManagedInstanceLongTermRetentionPoliciesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies/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 ManagedInstanceLongTermRetentionPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..cf4ace85962 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,106 @@ +package managedinstancelongtermretentionpolicies + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceLongTermRetentionPolicy +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceLongTermRetentionPolicy +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedInstanceLongTermRetentionPoliciesClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/backupLongTermRetentionPolicies", 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 *[]ManagedInstanceLongTermRetentionPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedInstanceLongTermRetentionPoliciesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ManagedInstanceLongTermRetentionPolicyOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceLongTermRetentionPoliciesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate ManagedInstanceLongTermRetentionPolicyOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedInstanceLongTermRetentionPolicy, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go new file mode 100644 index 00000000000..130b2849778 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go @@ -0,0 +1,11 @@ +package managedinstancelongtermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceLongTermRetentionPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceLongTermRetentionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go new file mode 100644 index 00000000000..1014c370908 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go @@ -0,0 +1,12 @@ +package managedinstancelongtermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceLongTermRetentionPolicyProperties struct { + BackupStorageAccessTier *BackupStorageAccessTier `json:"backupStorageAccessTier,omitempty"` + MonthlyRetention *string `json:"monthlyRetention,omitempty"` + WeekOfYear *int64 `json:"weekOfYear,omitempty"` + WeeklyRetention *string `json:"weeklyRetention,omitempty"` + YearlyRetention *string `json:"yearlyRetention,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/predicates.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/predicates.go new file mode 100644 index 00000000000..8ab8e0bab1f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/predicates.go @@ -0,0 +1,27 @@ +package managedinstancelongtermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceLongTermRetentionPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceLongTermRetentionPolicyOperationPredicate) Matches(input ManagedInstanceLongTermRetentionPolicy) 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/sql/2023-08-01/managedinstancelongtermretentionpolicies/version.go b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/version.go new file mode 100644 index 00000000000..644a0da5eb0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancelongtermretentionpolicies/version.go @@ -0,0 +1,10 @@ +package managedinstancelongtermretentionpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstancelongtermretentionpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/README.md b/resource-manager/sql/2023-08-01/managedinstanceoperations/README.md new file mode 100644 index 00000000000..5bc5c363d47 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceoperations` Documentation + +The `managedinstanceoperations` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceoperations" +``` + + +### Client Initialization + +```go +client := managedinstanceoperations.NewManagedInstanceOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceOperationsClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/client.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/client.go new file mode 100644 index 00000000000..8ae66bef970 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/client.go @@ -0,0 +1,26 @@ +package managedinstanceoperations + +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 ManagedInstanceOperationsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceOperationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceoperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceOperationsClient: %+v", err) + } + + return &ManagedInstanceOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/constants.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/constants.go new file mode 100644 index 00000000000..fee8783d566 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/constants.go @@ -0,0 +1,116 @@ +package managedinstanceoperations + +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 ManagementOperationState string + +const ( + ManagementOperationStateCancelInProgress ManagementOperationState = "CancelInProgress" + ManagementOperationStateCancelled ManagementOperationState = "Cancelled" + ManagementOperationStateFailed ManagementOperationState = "Failed" + ManagementOperationStateInProgress ManagementOperationState = "InProgress" + ManagementOperationStatePending ManagementOperationState = "Pending" + ManagementOperationStateSucceeded ManagementOperationState = "Succeeded" +) + +func PossibleValuesForManagementOperationState() []string { + return []string{ + string(ManagementOperationStateCancelInProgress), + string(ManagementOperationStateCancelled), + string(ManagementOperationStateFailed), + string(ManagementOperationStateInProgress), + string(ManagementOperationStatePending), + string(ManagementOperationStateSucceeded), + } +} + +func (s *ManagementOperationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagementOperationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagementOperationState(input string) (*ManagementOperationState, error) { + vals := map[string]ManagementOperationState{ + "cancelinprogress": ManagementOperationStateCancelInProgress, + "cancelled": ManagementOperationStateCancelled, + "failed": ManagementOperationStateFailed, + "inprogress": ManagementOperationStateInProgress, + "pending": ManagementOperationStatePending, + "succeeded": ManagementOperationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagementOperationState(input) + return &out, nil +} + +type ManagementOperationStepState string + +const ( + ManagementOperationStepStateCanceled ManagementOperationStepState = "Canceled" + ManagementOperationStepStateCompleted ManagementOperationStepState = "Completed" + ManagementOperationStepStateFailed ManagementOperationStepState = "Failed" + ManagementOperationStepStateInProgress ManagementOperationStepState = "InProgress" + ManagementOperationStepStateNotStarted ManagementOperationStepState = "NotStarted" + ManagementOperationStepStateSlowedDown ManagementOperationStepState = "SlowedDown" +) + +func PossibleValuesForManagementOperationStepState() []string { + return []string{ + string(ManagementOperationStepStateCanceled), + string(ManagementOperationStepStateCompleted), + string(ManagementOperationStepStateFailed), + string(ManagementOperationStepStateInProgress), + string(ManagementOperationStepStateNotStarted), + string(ManagementOperationStepStateSlowedDown), + } +} + +func (s *ManagementOperationStepState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagementOperationStepState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagementOperationStepState(input string) (*ManagementOperationStepState, error) { + vals := map[string]ManagementOperationStepState{ + "canceled": ManagementOperationStepStateCanceled, + "completed": ManagementOperationStepStateCompleted, + "failed": ManagementOperationStepStateFailed, + "inprogress": ManagementOperationStepStateInProgress, + "notstarted": ManagementOperationStepStateNotStarted, + "sloweddown": ManagementOperationStepStateSlowedDown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagementOperationStepState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/method_listbymanagedinstance.go new file mode 100644 index 00000000000..1cfeccbb360 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/method_listbymanagedinstance.go @@ -0,0 +1,106 @@ +package managedinstanceoperations + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceOperation +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceOperation +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ManagedInstanceOperationsClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]ManagedInstanceOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceOperationsClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceOperationOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceOperationsClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceOperationOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]ManagedInstanceOperation, 0) + + resp, err := c.ListByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperation.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperation.go new file mode 100644 index 00000000000..7907eabc53f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperation.go @@ -0,0 +1,11 @@ +package managedinstanceoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceOperation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceOperationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationparameterspair.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationparameterspair.go new file mode 100644 index 00000000000..ef4c437650d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationparameterspair.go @@ -0,0 +1,9 @@ +package managedinstanceoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceOperationParametersPair struct { + CurrentParameters *UpsertManagedServerOperationParameters `json:"currentParameters,omitempty"` + RequestedParameters *UpsertManagedServerOperationParameters `json:"requestedParameters,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationproperties.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationproperties.go new file mode 100644 index 00000000000..35a978fdbb3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationproperties.go @@ -0,0 +1,52 @@ +package managedinstanceoperations + +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 ManagedInstanceOperationProperties struct { + Description *string `json:"description,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorDescription *string `json:"errorDescription,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + EstimatedCompletionTime *string `json:"estimatedCompletionTime,omitempty"` + IsCancellable *bool `json:"isCancellable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + ManagedInstanceName *string `json:"managedInstanceName,omitempty"` + Operation *string `json:"operation,omitempty"` + OperationFriendlyName *string `json:"operationFriendlyName,omitempty"` + OperationParameters *ManagedInstanceOperationParametersPair `json:"operationParameters,omitempty"` + OperationSteps *ManagedInstanceOperationSteps `json:"operationSteps,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *ManagementOperationState `json:"state,omitempty"` +} + +func (o *ManagedInstanceOperationProperties) GetEstimatedCompletionTimeAsTime() (*time.Time, error) { + if o.EstimatedCompletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EstimatedCompletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceOperationProperties) SetEstimatedCompletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EstimatedCompletionTime = &formatted +} + +func (o *ManagedInstanceOperationProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceOperationProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationsteps.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationsteps.go new file mode 100644 index 00000000000..271313a0c44 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_managedinstanceoperationsteps.go @@ -0,0 +1,10 @@ +package managedinstanceoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceOperationSteps struct { + CurrentStep *int64 `json:"currentStep,omitempty"` + StepsList *[]UpsertManagedServerOperationStepWithEstimatesAndDuration `json:"stepsList,omitempty"` + TotalSteps *string `json:"totalSteps,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go new file mode 100644 index 00000000000..9e389a2d2cf --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go @@ -0,0 +1,11 @@ +package managedinstanceoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpsertManagedServerOperationParameters struct { + Family *string `json:"family,omitempty"` + StorageSizeInGB *int64 `json:"storageSizeInGB,omitempty"` + Tier *string `json:"tier,omitempty"` + VCores *int64 `json:"vCores,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go new file mode 100644 index 00000000000..3515f63bb54 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go @@ -0,0 +1,43 @@ +package managedinstanceoperations + +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 UpsertManagedServerOperationStepWithEstimatesAndDuration struct { + Name *string `json:"name,omitempty"` + Order *int64 `json:"order,omitempty"` + Status *ManagementOperationStepState `json:"status,omitempty"` + StepEndTime *string `json:"stepEndTime,omitempty"` + StepStartTime *string `json:"stepStartTime,omitempty"` + TimeElapsed *string `json:"timeElapsed,omitempty"` +} + +func (o *UpsertManagedServerOperationStepWithEstimatesAndDuration) GetStepEndTimeAsTime() (*time.Time, error) { + if o.StepEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StepEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpsertManagedServerOperationStepWithEstimatesAndDuration) SetStepEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StepEndTime = &formatted +} + +func (o *UpsertManagedServerOperationStepWithEstimatesAndDuration) GetStepStartTimeAsTime() (*time.Time, error) { + if o.StepStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StepStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpsertManagedServerOperationStepWithEstimatesAndDuration) SetStepStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StepStartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceoperations/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/predicates.go new file mode 100644 index 00000000000..58a7ff1293e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/predicates.go @@ -0,0 +1,27 @@ +package managedinstanceoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceOperationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceOperationOperationPredicate) Matches(input ManagedInstanceOperation) 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/sql/2023-08-01/managedinstanceoperations/version.go b/resource-manager/sql/2023-08-01/managedinstanceoperations/version.go new file mode 100644 index 00000000000..351dd12a489 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceoperations/version.go @@ -0,0 +1,10 @@ +package managedinstanceoperations + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceoperations/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/README.md b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/README.md new file mode 100644 index 00000000000..4c23482578d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections` Documentation + +The `managedinstanceprivateendpointconnections` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections" +``` + + +### Client Initialization + +```go +client := managedinstanceprivateendpointconnections.NewManagedInstancePrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstancePrivateEndpointConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstanceprivateendpointconnections.NewManagedInstancePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateEndpointConnectionName") + +payload := managedinstanceprivateendpointconnections.ManagedInstancePrivateEndpointConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancePrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := managedinstanceprivateendpointconnections.NewManagedInstancePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancePrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := managedinstanceprivateendpointconnections.NewManagedInstancePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedInstancePrivateEndpointConnectionsClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/client.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/client.go new file mode 100644 index 00000000000..b52a5ea4cf4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/client.go @@ -0,0 +1,26 @@ +package managedinstanceprivateendpointconnections + +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 ManagedInstancePrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstancePrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstancePrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceprivateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstancePrivateEndpointConnectionsClient: %+v", err) + } + + return &ManagedInstancePrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go new file mode 100644 index 00000000000..85fcdb31578 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go @@ -0,0 +1,139 @@ +package managedinstanceprivateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstancePrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &ManagedInstancePrivateEndpointConnectionId{} + +// ManagedInstancePrivateEndpointConnectionId is a struct representing the Resource ID for a Managed Instance Private Endpoint Connection +type ManagedInstancePrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + PrivateEndpointConnectionName string +} + +// NewManagedInstancePrivateEndpointConnectionID returns a new ManagedInstancePrivateEndpointConnectionId struct +func NewManagedInstancePrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, managedInstanceName string, privateEndpointConnectionName string) ManagedInstancePrivateEndpointConnectionId { + return ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParseManagedInstancePrivateEndpointConnectionID parses 'input' into a ManagedInstancePrivateEndpointConnectionId +func ParseManagedInstancePrivateEndpointConnectionID(input string) (*ManagedInstancePrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstancePrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstancePrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstancePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a ManagedInstancePrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParseManagedInstancePrivateEndpointConnectionIDInsensitively(input string) (*ManagedInstancePrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstancePrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstancePrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstancePrivateEndpointConnectionId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidateManagedInstancePrivateEndpointConnectionID checks that 'input' can be parsed as a Managed Instance Private Endpoint Connection ID +func ValidateManagedInstancePrivateEndpointConnectionID(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 := ParseManagedInstancePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Private Endpoint Connection ID +func (id ManagedInstancePrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Private Endpoint Connection ID +func (id ManagedInstancePrivateEndpointConnectionId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Managed Instance Private Endpoint Connection ID +func (id ManagedInstancePrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Managed Instance Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go new file mode 100644 index 00000000000..86348e26ea4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go @@ -0,0 +1,327 @@ +package managedinstanceprivateendpointconnections + +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 = &ManagedInstancePrivateEndpointConnectionId{} + +func TestNewManagedInstancePrivateEndpointConnectionID(t *testing.T) { + id := NewManagedInstancePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatManagedInstancePrivateEndpointConnectionID(t *testing.T) { + actual := NewManagedInstancePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstancePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstancePrivateEndpointConnectionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstancePrivateEndpointConnectionID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParseManagedInstancePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstancePrivateEndpointConnectionId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstancePrivateEndpointConnectionIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForManagedInstancePrivateEndpointConnectionId(t *testing.T) { + segments := ManagedInstancePrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstancePrivateEndpointConnectionId 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/sql/2023-08-01/managedinstanceprivateendpointconnections/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..16991eef49c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_createorupdate.go @@ -0,0 +1,75 @@ +package managedinstanceprivateendpointconnections + +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 *ManagedInstancePrivateEndpointConnection +} + +// CreateOrUpdate ... +func (c ManagedInstancePrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, id ManagedInstancePrivateEndpointConnectionId, input ManagedInstancePrivateEndpointConnection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedInstancePrivateEndpointConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedInstancePrivateEndpointConnectionId, input ManagedInstancePrivateEndpointConnection) 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/sql/2023-08-01/managedinstanceprivateendpointconnections/method_delete.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_delete.go new file mode 100644 index 00000000000..100cc94d931 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package managedinstanceprivateendpointconnections + +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 ManagedInstancePrivateEndpointConnectionsClient) Delete(ctx context.Context, id ManagedInstancePrivateEndpointConnectionId) (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 ManagedInstancePrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id ManagedInstancePrivateEndpointConnectionId) 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/sql/2023-08-01/managedinstanceprivateendpointconnections/method_get.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_get.go new file mode 100644 index 00000000000..8de7930b31b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package managedinstanceprivateendpointconnections + +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 *ManagedInstancePrivateEndpointConnection +} + +// Get ... +func (c ManagedInstancePrivateEndpointConnectionsClient) Get(ctx context.Context, id ManagedInstancePrivateEndpointConnectionId) (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 ManagedInstancePrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go new file mode 100644 index 00000000000..73ea470009a --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go @@ -0,0 +1,106 @@ +package managedinstanceprivateendpointconnections + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstancePrivateEndpointConnection +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstancePrivateEndpointConnection +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ManagedInstancePrivateEndpointConnectionsClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedInstancePrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedInstancePrivateEndpointConnectionsClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, ManagedInstancePrivateEndpointConnectionOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancePrivateEndpointConnectionsClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstancePrivateEndpointConnectionOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]ManagedInstancePrivateEndpointConnection, 0) + + resp, err := c.ListByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go new file mode 100644 index 00000000000..6fead3abbd5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go @@ -0,0 +1,11 @@ +package managedinstanceprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstancePrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..f13e94db51c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package managedinstanceprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateEndpointConnectionProperties struct { + PrivateEndpoint *ManagedInstancePrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *ManagedInstancePrivateLinkServiceConnectionStateProperty `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go new file mode 100644 index 00000000000..a9ef174e014 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go @@ -0,0 +1,8 @@ +package managedinstanceprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..877f249e56b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go @@ -0,0 +1,10 @@ +package managedinstanceprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateLinkServiceConnectionStateProperty struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status string `json:"status"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/predicates.go new file mode 100644 index 00000000000..9487375b565 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/predicates.go @@ -0,0 +1,27 @@ +package managedinstanceprivateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstancePrivateEndpointConnectionOperationPredicate) Matches(input ManagedInstancePrivateEndpointConnection) 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/sql/2023-08-01/managedinstanceprivateendpointconnections/version.go b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/version.go new file mode 100644 index 00000000000..4d52d84edc4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivateendpointconnections/version.go @@ -0,0 +1,10 @@ +package managedinstanceprivateendpointconnections + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceprivateendpointconnections/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/README.md b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/README.md new file mode 100644 index 00000000000..166a4b277cf --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources` Documentation + +The `managedinstanceprivatelinkresources` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources" +``` + + +### Client Initialization + +```go +client := managedinstanceprivatelinkresources.NewManagedInstancePrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstancePrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := managedinstanceprivatelinkresources.NewManagedInstancePrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateLinkResourceName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedInstancePrivateLinkResourcesClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/client.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/client.go new file mode 100644 index 00000000000..baa13de3973 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/client.go @@ -0,0 +1,26 @@ +package managedinstanceprivatelinkresources + +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 ManagedInstancePrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstancePrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstancePrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstanceprivatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstancePrivateLinkResourcesClient: %+v", err) + } + + return &ManagedInstancePrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go new file mode 100644 index 00000000000..b901a21e3b5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go @@ -0,0 +1,139 @@ +package managedinstanceprivatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstancePrivateLinkResourceId{}) +} + +var _ resourceids.ResourceId = &ManagedInstancePrivateLinkResourceId{} + +// ManagedInstancePrivateLinkResourceId is a struct representing the Resource ID for a Managed Instance Private Link Resource +type ManagedInstancePrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + PrivateLinkResourceName string +} + +// NewManagedInstancePrivateLinkResourceID returns a new ManagedInstancePrivateLinkResourceId struct +func NewManagedInstancePrivateLinkResourceID(subscriptionId string, resourceGroupName string, managedInstanceName string, privateLinkResourceName string) ManagedInstancePrivateLinkResourceId { + return ManagedInstancePrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParseManagedInstancePrivateLinkResourceID parses 'input' into a ManagedInstancePrivateLinkResourceId +func ParseManagedInstancePrivateLinkResourceID(input string) (*ManagedInstancePrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstancePrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstancePrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstancePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a ManagedInstancePrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParseManagedInstancePrivateLinkResourceIDInsensitively(input string) (*ManagedInstancePrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstancePrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstancePrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstancePrivateLinkResourceId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidateManagedInstancePrivateLinkResourceID checks that 'input' can be parsed as a Managed Instance Private Link Resource ID +func ValidateManagedInstancePrivateLinkResourceID(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 := ParseManagedInstancePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Private Link Resource ID +func (id ManagedInstancePrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Private Link Resource ID +func (id ManagedInstancePrivateLinkResourceId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceName"), + } +} + +// String returns a human-readable description of this Managed Instance Private Link Resource ID +func (id ManagedInstancePrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Managed Instance Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go new file mode 100644 index 00000000000..5ef154ab568 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go @@ -0,0 +1,327 @@ +package managedinstanceprivatelinkresources + +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 = &ManagedInstancePrivateLinkResourceId{} + +func TestNewManagedInstancePrivateLinkResourceID(t *testing.T) { + id := NewManagedInstancePrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateLinkResourceName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.PrivateLinkResourceName != "privateLinkResourceName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceName") + } +} + +func TestFormatManagedInstancePrivateLinkResourceID(t *testing.T) { + actual := NewManagedInstancePrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "privateLinkResourceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources/privateLinkResourceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstancePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstancePrivateLinkResourceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources/privateLinkResourceName", + Expected: &ManagedInstancePrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstancePrivateLinkResourceID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParseManagedInstancePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstancePrivateLinkResourceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources/privateLinkResourceName", + Expected: &ManagedInstancePrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe", + Expected: &ManagedInstancePrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstancePrivateLinkResourceIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForManagedInstancePrivateLinkResourceId(t *testing.T) { + segments := ManagedInstancePrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstancePrivateLinkResourceId 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/sql/2023-08-01/managedinstanceprivatelinkresources/method_get.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_get.go new file mode 100644 index 00000000000..0bfbfeddc21 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_get.go @@ -0,0 +1,53 @@ +package managedinstanceprivatelinkresources + +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 *ManagedInstancePrivateLink +} + +// Get ... +func (c ManagedInstancePrivateLinkResourcesClient) Get(ctx context.Context, id ManagedInstancePrivateLinkResourceId) (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 ManagedInstancePrivateLink + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_listbymanagedinstance.go new file mode 100644 index 00000000000..99eb0ef7a33 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/method_listbymanagedinstance.go @@ -0,0 +1,106 @@ +package managedinstanceprivatelinkresources + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstancePrivateLink +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstancePrivateLink +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ManagedInstancePrivateLinkResourcesClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedInstancePrivateLink `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedInstancePrivateLinkResourcesClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, ManagedInstancePrivateLinkOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancePrivateLinkResourcesClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstancePrivateLinkOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]ManagedInstancePrivateLink, 0) + + resp, err := c.ListByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go new file mode 100644 index 00000000000..7c9a6958b0a --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go @@ -0,0 +1,11 @@ +package managedinstanceprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateLink struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstancePrivateLinkProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go new file mode 100644 index 00000000000..e95bf2547a8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go @@ -0,0 +1,10 @@ +package managedinstanceprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateLinkProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/predicates.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/predicates.go new file mode 100644 index 00000000000..f17642eb3dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/predicates.go @@ -0,0 +1,27 @@ +package managedinstanceprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateLinkOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstancePrivateLinkOperationPredicate) Matches(input ManagedInstancePrivateLink) 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/sql/2023-08-01/managedinstanceprivatelinkresources/version.go b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/version.go new file mode 100644 index 00000000000..c33dbf021e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstanceprivatelinkresources/version.go @@ -0,0 +1,10 @@ +package managedinstanceprivatelinkresources + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstanceprivatelinkresources/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/README.md b/resource-manager/sql/2023-08-01/managedinstances/README.md new file mode 100644 index 00000000000..1e1ab3e244e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/README.md @@ -0,0 +1,216 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstances` Documentation + +The `managedinstances` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstances" +``` + + +### Client Initialization + +```go +client := managedinstances.NewManagedInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstancesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstances.ManagedInstance{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Failover` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.FailoverThenPoll(ctx, id, managedinstances.DefaultFailoverOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +read, err := client.Get(ctx, id, managedinstances.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedInstancesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, managedinstances.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, managedinstances.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedInstancesClient.ListByInstancePool` + +```go +ctx := context.TODO() +id := managedinstances.NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + +// alternatively `client.ListByInstancePool(ctx, id, managedinstances.DefaultListByInstancePoolOperationOptions())` can be used to do batched pagination +items, err := client.ListByInstancePoolComplete(ctx, id, managedinstances.DefaultListByInstancePoolOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedInstancesClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id, managedinstances.DefaultListByManagedInstanceOperationOptions())` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id, managedinstances.DefaultListByManagedInstanceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedInstancesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, managedinstances.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, managedinstances.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedInstancesClient.ListOutboundNetworkDependenciesByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListOutboundNetworkDependenciesByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListOutboundNetworkDependenciesByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedInstancesClient.RefreshStatus` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.RefreshStatusThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Start` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.StartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Stop` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +if err := client.StopThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstances.ManagedInstanceUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstances/client.go b/resource-manager/sql/2023-08-01/managedinstances/client.go new file mode 100644 index 00000000000..e894127c1fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/client.go @@ -0,0 +1,26 @@ +package managedinstances + +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 ManagedInstancesClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstancesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstancesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstances", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstancesClient: %+v", err) + } + + return &ManagedInstancesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/constants.go b/resource-manager/sql/2023-08-01/managedinstances/constants.go new file mode 100644 index 00000000000..acc64324335 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/constants.go @@ -0,0 +1,834 @@ +package managedinstances + +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 AdministratorType string + +const ( + AdministratorTypeActiveDirectory AdministratorType = "ActiveDirectory" +) + +func PossibleValuesForAdministratorType() []string { + return []string{ + string(AdministratorTypeActiveDirectory), + } +} + +func (s *AdministratorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdministratorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdministratorType(input string) (*AdministratorType, error) { + vals := map[string]AdministratorType{ + "activedirectory": AdministratorTypeActiveDirectory, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdministratorType(input) + return &out, nil +} + +type AggregationFunctionType string + +const ( + AggregationFunctionTypeAvg AggregationFunctionType = "avg" + AggregationFunctionTypeMax AggregationFunctionType = "max" + AggregationFunctionTypeMin AggregationFunctionType = "min" + AggregationFunctionTypeStdev AggregationFunctionType = "stdev" + AggregationFunctionTypeSum AggregationFunctionType = "sum" +) + +func PossibleValuesForAggregationFunctionType() []string { + return []string{ + string(AggregationFunctionTypeAvg), + string(AggregationFunctionTypeMax), + string(AggregationFunctionTypeMin), + string(AggregationFunctionTypeStdev), + string(AggregationFunctionTypeSum), + } +} + +func (s *AggregationFunctionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAggregationFunctionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAggregationFunctionType(input string) (*AggregationFunctionType, error) { + vals := map[string]AggregationFunctionType{ + "avg": AggregationFunctionTypeAvg, + "max": AggregationFunctionTypeMax, + "min": AggregationFunctionTypeMin, + "stdev": AggregationFunctionTypeStdev, + "sum": AggregationFunctionTypeSum, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AggregationFunctionType(input) + return &out, nil +} + +type AuthMetadataLookupModes string + +const ( + AuthMetadataLookupModesAzureAD AuthMetadataLookupModes = "AzureAD" + AuthMetadataLookupModesPaired AuthMetadataLookupModes = "Paired" + AuthMetadataLookupModesWindows AuthMetadataLookupModes = "Windows" +) + +func PossibleValuesForAuthMetadataLookupModes() []string { + return []string{ + string(AuthMetadataLookupModesAzureAD), + string(AuthMetadataLookupModesPaired), + string(AuthMetadataLookupModesWindows), + } +} + +func (s *AuthMetadataLookupModes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthMetadataLookupModes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAuthMetadataLookupModes(input string) (*AuthMetadataLookupModes, error) { + vals := map[string]AuthMetadataLookupModes{ + "azuread": AuthMetadataLookupModesAzureAD, + "paired": AuthMetadataLookupModesPaired, + "windows": AuthMetadataLookupModesWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuthMetadataLookupModes(input) + return &out, nil +} + +type BackupStorageRedundancy string + +const ( + BackupStorageRedundancyGeo BackupStorageRedundancy = "Geo" + BackupStorageRedundancyGeoZone BackupStorageRedundancy = "GeoZone" + BackupStorageRedundancyLocal BackupStorageRedundancy = "Local" + BackupStorageRedundancyZone BackupStorageRedundancy = "Zone" +) + +func PossibleValuesForBackupStorageRedundancy() []string { + return []string{ + string(BackupStorageRedundancyGeo), + string(BackupStorageRedundancyGeoZone), + string(BackupStorageRedundancyLocal), + string(BackupStorageRedundancyZone), + } +} + +func (s *BackupStorageRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageRedundancy(input string) (*BackupStorageRedundancy, error) { + vals := map[string]BackupStorageRedundancy{ + "geo": BackupStorageRedundancyGeo, + "geozone": BackupStorageRedundancyGeoZone, + "local": BackupStorageRedundancyLocal, + "zone": BackupStorageRedundancyZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageRedundancy(input) + return &out, nil +} + +type ExternalGovernanceStatus string + +const ( + ExternalGovernanceStatusDisabled ExternalGovernanceStatus = "Disabled" + ExternalGovernanceStatusEnabled ExternalGovernanceStatus = "Enabled" +) + +func PossibleValuesForExternalGovernanceStatus() []string { + return []string{ + string(ExternalGovernanceStatusDisabled), + string(ExternalGovernanceStatusEnabled), + } +} + +func (s *ExternalGovernanceStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExternalGovernanceStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExternalGovernanceStatus(input string) (*ExternalGovernanceStatus, error) { + vals := map[string]ExternalGovernanceStatus{ + "disabled": ExternalGovernanceStatusDisabled, + "enabled": ExternalGovernanceStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExternalGovernanceStatus(input) + return &out, nil +} + +type HybridSecondaryUsage string + +const ( + HybridSecondaryUsageActive HybridSecondaryUsage = "Active" + HybridSecondaryUsagePassive HybridSecondaryUsage = "Passive" +) + +func PossibleValuesForHybridSecondaryUsage() []string { + return []string{ + string(HybridSecondaryUsageActive), + string(HybridSecondaryUsagePassive), + } +} + +func (s *HybridSecondaryUsage) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHybridSecondaryUsage(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHybridSecondaryUsage(input string) (*HybridSecondaryUsage, error) { + vals := map[string]HybridSecondaryUsage{ + "active": HybridSecondaryUsageActive, + "passive": HybridSecondaryUsagePassive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HybridSecondaryUsage(input) + return &out, nil +} + +type HybridSecondaryUsageDetected string + +const ( + HybridSecondaryUsageDetectedActive HybridSecondaryUsageDetected = "Active" + HybridSecondaryUsageDetectedPassive HybridSecondaryUsageDetected = "Passive" +) + +func PossibleValuesForHybridSecondaryUsageDetected() []string { + return []string{ + string(HybridSecondaryUsageDetectedActive), + string(HybridSecondaryUsageDetectedPassive), + } +} + +func (s *HybridSecondaryUsageDetected) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHybridSecondaryUsageDetected(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHybridSecondaryUsageDetected(input string) (*HybridSecondaryUsageDetected, error) { + vals := map[string]HybridSecondaryUsageDetected{ + "active": HybridSecondaryUsageDetectedActive, + "passive": HybridSecondaryUsageDetectedPassive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HybridSecondaryUsageDetected(input) + return &out, nil +} + +type ManagedInstanceDatabaseFormat string + +const ( + ManagedInstanceDatabaseFormatAlwaysUpToDate ManagedInstanceDatabaseFormat = "AlwaysUpToDate" + ManagedInstanceDatabaseFormatSQLServerTwoZeroTwoTwo ManagedInstanceDatabaseFormat = "SQLServer2022" +) + +func PossibleValuesForManagedInstanceDatabaseFormat() []string { + return []string{ + string(ManagedInstanceDatabaseFormatAlwaysUpToDate), + string(ManagedInstanceDatabaseFormatSQLServerTwoZeroTwoTwo), + } +} + +func (s *ManagedInstanceDatabaseFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedInstanceDatabaseFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedInstanceDatabaseFormat(input string) (*ManagedInstanceDatabaseFormat, error) { + vals := map[string]ManagedInstanceDatabaseFormat{ + "alwaysuptodate": ManagedInstanceDatabaseFormatAlwaysUpToDate, + "sqlserver2022": ManagedInstanceDatabaseFormatSQLServerTwoZeroTwoTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedInstanceDatabaseFormat(input) + return &out, nil +} + +type ManagedInstanceLicenseType string + +const ( + ManagedInstanceLicenseTypeBasePrice ManagedInstanceLicenseType = "BasePrice" + ManagedInstanceLicenseTypeLicenseIncluded ManagedInstanceLicenseType = "LicenseIncluded" +) + +func PossibleValuesForManagedInstanceLicenseType() []string { + return []string{ + string(ManagedInstanceLicenseTypeBasePrice), + string(ManagedInstanceLicenseTypeLicenseIncluded), + } +} + +func (s *ManagedInstanceLicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedInstanceLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedInstanceLicenseType(input string) (*ManagedInstanceLicenseType, error) { + vals := map[string]ManagedInstanceLicenseType{ + "baseprice": ManagedInstanceLicenseTypeBasePrice, + "licenseincluded": ManagedInstanceLicenseTypeLicenseIncluded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedInstanceLicenseType(input) + return &out, nil +} + +type ManagedInstanceProxyOverride string + +const ( + ManagedInstanceProxyOverrideDefault ManagedInstanceProxyOverride = "Default" + ManagedInstanceProxyOverrideProxy ManagedInstanceProxyOverride = "Proxy" + ManagedInstanceProxyOverrideRedirect ManagedInstanceProxyOverride = "Redirect" +) + +func PossibleValuesForManagedInstanceProxyOverride() []string { + return []string{ + string(ManagedInstanceProxyOverrideDefault), + string(ManagedInstanceProxyOverrideProxy), + string(ManagedInstanceProxyOverrideRedirect), + } +} + +func (s *ManagedInstanceProxyOverride) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedInstanceProxyOverride(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedInstanceProxyOverride(input string) (*ManagedInstanceProxyOverride, error) { + vals := map[string]ManagedInstanceProxyOverride{ + "default": ManagedInstanceProxyOverrideDefault, + "proxy": ManagedInstanceProxyOverrideProxy, + "redirect": ManagedInstanceProxyOverrideRedirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedInstanceProxyOverride(input) + return &out, nil +} + +type ManagedServerCreateMode string + +const ( + ManagedServerCreateModeDefault ManagedServerCreateMode = "Default" + ManagedServerCreateModePointInTimeRestore ManagedServerCreateMode = "PointInTimeRestore" +) + +func PossibleValuesForManagedServerCreateMode() []string { + return []string{ + string(ManagedServerCreateModeDefault), + string(ManagedServerCreateModePointInTimeRestore), + } +} + +func (s *ManagedServerCreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedServerCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedServerCreateMode(input string) (*ManagedServerCreateMode, error) { + vals := map[string]ManagedServerCreateMode{ + "default": ManagedServerCreateModeDefault, + "pointintimerestore": ManagedServerCreateModePointInTimeRestore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedServerCreateMode(input) + return &out, nil +} + +type MetricType string + +const ( + MetricTypeCpu MetricType = "cpu" + MetricTypeDtu MetricType = "dtu" + MetricTypeDuration MetricType = "duration" + MetricTypeIo MetricType = "io" + MetricTypeLogIo MetricType = "logIo" +) + +func PossibleValuesForMetricType() []string { + return []string{ + string(MetricTypeCpu), + string(MetricTypeDtu), + string(MetricTypeDuration), + string(MetricTypeIo), + string(MetricTypeLogIo), + } +} + +func (s *MetricType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMetricType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMetricType(input string) (*MetricType, error) { + vals := map[string]MetricType{ + "cpu": MetricTypeCpu, + "dtu": MetricTypeDtu, + "duration": MetricTypeDuration, + "io": MetricTypeIo, + "logio": MetricTypeLogIo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MetricType(input) + return &out, nil +} + +type PricingModel string + +const ( + PricingModelFreemium PricingModel = "Freemium" + PricingModelRegular PricingModel = "Regular" +) + +func PossibleValuesForPricingModel() []string { + return []string{ + string(PricingModelFreemium), + string(PricingModelRegular), + } +} + +func (s *PricingModel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePricingModel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePricingModel(input string) (*PricingModel, error) { + vals := map[string]PricingModel{ + "freemium": PricingModelFreemium, + "regular": PricingModelRegular, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PricingModel(input) + return &out, nil +} + +type PrincipalType string + +const ( + PrincipalTypeApplication PrincipalType = "Application" + PrincipalTypeGroup PrincipalType = "Group" + PrincipalTypeUser PrincipalType = "User" +) + +func PossibleValuesForPrincipalType() []string { + return []string{ + string(PrincipalTypeApplication), + string(PrincipalTypeGroup), + string(PrincipalTypeUser), + } +} + +func (s *PrincipalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrincipalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrincipalType(input string) (*PrincipalType, error) { + vals := map[string]PrincipalType{ + "application": PrincipalTypeApplication, + "group": PrincipalTypeGroup, + "user": PrincipalTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrincipalType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + 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{ + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 QueryMetricUnitType string + +const ( + QueryMetricUnitTypeCount QueryMetricUnitType = "count" + QueryMetricUnitTypeKB QueryMetricUnitType = "KB" + QueryMetricUnitTypeMicroseconds QueryMetricUnitType = "microseconds" + QueryMetricUnitTypePercentage QueryMetricUnitType = "percentage" +) + +func PossibleValuesForQueryMetricUnitType() []string { + return []string{ + string(QueryMetricUnitTypeCount), + string(QueryMetricUnitTypeKB), + string(QueryMetricUnitTypeMicroseconds), + string(QueryMetricUnitTypePercentage), + } +} + +func (s *QueryMetricUnitType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryMetricUnitType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryMetricUnitType(input string) (*QueryMetricUnitType, error) { + vals := map[string]QueryMetricUnitType{ + "count": QueryMetricUnitTypeCount, + "kb": QueryMetricUnitTypeKB, + "microseconds": QueryMetricUnitTypeMicroseconds, + "percentage": QueryMetricUnitTypePercentage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryMetricUnitType(input) + return &out, nil +} + +type QueryTimeGrainType string + +const ( + QueryTimeGrainTypePOneD QueryTimeGrainType = "P1D" + QueryTimeGrainTypePTOneH QueryTimeGrainType = "PT1H" +) + +func PossibleValuesForQueryTimeGrainType() []string { + return []string{ + string(QueryTimeGrainTypePOneD), + string(QueryTimeGrainTypePTOneH), + } +} + +func (s *QueryTimeGrainType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryTimeGrainType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryTimeGrainType(input string) (*QueryTimeGrainType, error) { + vals := map[string]QueryTimeGrainType{ + "p1d": QueryTimeGrainTypePOneD, + "pt1h": QueryTimeGrainTypePTOneH, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryTimeGrainType(input) + return &out, nil +} + +type ReplicaType string + +const ( + ReplicaTypePrimary ReplicaType = "Primary" + ReplicaTypeReadableSecondary ReplicaType = "ReadableSecondary" +) + +func PossibleValuesForReplicaType() []string { + return []string{ + string(ReplicaTypePrimary), + string(ReplicaTypeReadableSecondary), + } +} + +func (s *ReplicaType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicaType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicaType(input string) (*ReplicaType, error) { + vals := map[string]ReplicaType{ + "primary": ReplicaTypePrimary, + "readablesecondary": ReplicaTypeReadableSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicaType(input) + return &out, nil +} + +type ServicePrincipalType string + +const ( + ServicePrincipalTypeNone ServicePrincipalType = "None" + ServicePrincipalTypeSystemAssigned ServicePrincipalType = "SystemAssigned" +) + +func PossibleValuesForServicePrincipalType() []string { + return []string{ + string(ServicePrincipalTypeNone), + string(ServicePrincipalTypeSystemAssigned), + } +} + +func (s *ServicePrincipalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServicePrincipalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServicePrincipalType(input string) (*ServicePrincipalType, error) { + vals := map[string]ServicePrincipalType{ + "none": ServicePrincipalTypeNone, + "systemassigned": ServicePrincipalTypeSystemAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServicePrincipalType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/id_instancepool.go b/resource-manager/sql/2023-08-01/managedinstances/id_instancepool.go new file mode 100644 index 00000000000..a25635e8b21 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/id_instancepool.go @@ -0,0 +1,130 @@ +package managedinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&InstancePoolId{}) +} + +var _ resourceids.ResourceId = &InstancePoolId{} + +// InstancePoolId is a struct representing the Resource ID for a Instance Pool +type InstancePoolId struct { + SubscriptionId string + ResourceGroupName string + InstancePoolName string +} + +// NewInstancePoolID returns a new InstancePoolId struct +func NewInstancePoolID(subscriptionId string, resourceGroupName string, instancePoolName string) InstancePoolId { + return InstancePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + InstancePoolName: instancePoolName, + } +} + +// ParseInstancePoolID parses 'input' into a InstancePoolId +func ParseInstancePoolID(input string) (*InstancePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstancePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstancePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseInstancePoolIDInsensitively parses 'input' case-insensitively into a InstancePoolId +// note: this method should only be used for API response data and not user input +func ParseInstancePoolIDInsensitively(input string) (*InstancePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstancePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstancePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *InstancePoolId) 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.InstancePoolName, ok = input.Parsed["instancePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "instancePoolName", input) + } + + return nil +} + +// ValidateInstancePoolID checks that 'input' can be parsed as a Instance Pool ID +func ValidateInstancePoolID(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 := ParseInstancePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Instance Pool ID +func (id InstancePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/instancePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.InstancePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Instance Pool ID +func (id InstancePoolId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticInstancePools", "instancePools", "instancePools"), + resourceids.UserSpecifiedSegment("instancePoolName", "instancePoolName"), + } +} + +// String returns a human-readable description of this Instance Pool ID +func (id InstancePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Instance Pool Name: %q", id.InstancePoolName), + } + return fmt.Sprintf("Instance Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/id_instancepool_test.go b/resource-manager/sql/2023-08-01/managedinstances/id_instancepool_test.go new file mode 100644 index 00000000000..6516a512ce8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/id_instancepool_test.go @@ -0,0 +1,282 @@ +package managedinstances + +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 = &InstancePoolId{} + +func TestNewInstancePoolID(t *testing.T) { + id := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + + 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.InstancePoolName != "instancePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'InstancePoolName'", id.InstancePoolName, "instancePoolName") + } +} + +func TestFormatInstancePoolID(t *testing.T) { + actual := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseInstancePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstancePoolId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstancePoolID(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.InstancePoolName != v.Expected.InstancePoolName { + t.Fatalf("Expected %q but got %q for InstancePoolName", v.Expected.InstancePoolName, actual.InstancePoolName) + } + + } +} + +func TestParseInstancePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstancePoolId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/iNsTaNcEpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/iNsTaNcEpOoLs/iNsTaNcEpOoLnAmE", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + InstancePoolName: "iNsTaNcEpOoLnAmE", + }, + }, + { + // 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.sQl/iNsTaNcEpOoLs/iNsTaNcEpOoLnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstancePoolIDInsensitively(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.InstancePoolName != v.Expected.InstancePoolName { + t.Fatalf("Expected %q but got %q for InstancePoolName", v.Expected.InstancePoolName, actual.InstancePoolName) + } + + } +} + +func TestSegmentsForInstancePoolId(t *testing.T) { + segments := InstancePoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("InstancePoolId 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/sql/2023-08-01/managedinstances/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstances/method_createorupdate.go new file mode 100644 index 00000000000..64419f9cc8b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_createorupdate.go @@ -0,0 +1,77 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstance +} + +// CreateOrUpdate ... +func (c ManagedInstancesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstance) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ManagedInstancesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstance) 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/sql/2023-08-01/managedinstances/method_delete.go b/resource-manager/sql/2023-08-01/managedinstances/method_delete.go new file mode 100644 index 00000000000..71a0c4e1c3d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_delete.go @@ -0,0 +1,72 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedInstancesClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceId) (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 ManagedInstancesClient) DeleteThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) 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/sql/2023-08-01/managedinstances/method_failover.go b/resource-manager/sql/2023-08-01/managedinstances/method_failover.go new file mode 100644 index 00000000000..d4650489f17 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_failover.go @@ -0,0 +1,100 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type FailoverOperationOptions struct { + ReplicaType *ReplicaType +} + +func DefaultFailoverOperationOptions() FailoverOperationOptions { + return FailoverOperationOptions{} +} + +func (o FailoverOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o FailoverOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o FailoverOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ReplicaType != nil { + out.Append("replicaType", fmt.Sprintf("%v", *o.ReplicaType)) + } + return &out +} + +// Failover ... +func (c ManagedInstancesClient) Failover(ctx context.Context, id commonids.SqlManagedInstanceId, options FailoverOperationOptions) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c ManagedInstancesClient) FailoverThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, options FailoverOperationOptions) error { + result, err := c.Failover(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_get.go b/resource-manager/sql/2023-08-01/managedinstances/method_get.go new file mode 100644 index 00000000000..21e7a5561c7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_get.go @@ -0,0 +1,84 @@ +package managedinstances + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstance +} + +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 ManagedInstancesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 ManagedInstance + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_list.go b/resource-manager/sql/2023-08-01/managedinstances/method_list.go new file mode 100644 index 00000000000..685fc7f9a70 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_list.go @@ -0,0 +1,135 @@ +package managedinstances + +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 *[]ManagedInstance +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstance +} + +type ListOperationOptions struct { + Expand *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ManagedInstancesClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/managedInstances", 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 *[]ManagedInstance `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 ManagedInstancesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ManagedInstanceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ManagedInstanceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ManagedInstance, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_listbyinstancepool.go b/resource-manager/sql/2023-08-01/managedinstances/method_listbyinstancepool.go new file mode 100644 index 00000000000..8ff253cace4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_listbyinstancepool.go @@ -0,0 +1,134 @@ +package managedinstances + +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 ListByInstancePoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstance +} + +type ListByInstancePoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstance +} + +type ListByInstancePoolOperationOptions struct { + Expand *string +} + +func DefaultListByInstancePoolOperationOptions() ListByInstancePoolOperationOptions { + return ListByInstancePoolOperationOptions{} +} + +func (o ListByInstancePoolOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByInstancePoolOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByInstancePoolOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListByInstancePoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstancePoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstancePool ... +func (c ManagedInstancesClient) ListByInstancePool(ctx context.Context, id InstancePoolId, options ListByInstancePoolOperationOptions) (result ListByInstancePoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByInstancePoolCustomPager{}, + Path: fmt.Sprintf("%s/managedInstances", 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 *[]ManagedInstance `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstancePoolComplete retrieves all the results into a single object +func (c ManagedInstancesClient) ListByInstancePoolComplete(ctx context.Context, id InstancePoolId, options ListByInstancePoolOperationOptions) (ListByInstancePoolCompleteResult, error) { + return c.ListByInstancePoolCompleteMatchingPredicate(ctx, id, options, ManagedInstanceOperationPredicate{}) +} + +// ListByInstancePoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancesClient) ListByInstancePoolCompleteMatchingPredicate(ctx context.Context, id InstancePoolId, options ListByInstancePoolOperationOptions, predicate ManagedInstanceOperationPredicate) (result ListByInstancePoolCompleteResult, err error) { + items := make([]ManagedInstance, 0) + + resp, err := c.ListByInstancePool(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstancePoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedinstances/method_listbymanagedinstance.go new file mode 100644 index 00000000000..61e9c8e3192 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_listbymanagedinstance.go @@ -0,0 +1,159 @@ +package managedinstances + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TopQueries +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []TopQueries +} + +type ListByManagedInstanceOperationOptions struct { + AggregationFunction *AggregationFunctionType + Databases *string + EndTime *string + Interval *QueryTimeGrainType + NumberOfQueries *int64 + ObservationMetric *MetricType + StartTime *string +} + +func DefaultListByManagedInstanceOperationOptions() ListByManagedInstanceOperationOptions { + return ListByManagedInstanceOperationOptions{} +} + +func (o ListByManagedInstanceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByManagedInstanceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByManagedInstanceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.AggregationFunction != nil { + out.Append("aggregationFunction", fmt.Sprintf("%v", *o.AggregationFunction)) + } + if o.Databases != nil { + out.Append("databases", fmt.Sprintf("%v", *o.Databases)) + } + if o.EndTime != nil { + out.Append("endTime", fmt.Sprintf("%v", *o.EndTime)) + } + if o.Interval != nil { + out.Append("interval", fmt.Sprintf("%v", *o.Interval)) + } + if o.NumberOfQueries != nil { + out.Append("numberOfQueries", fmt.Sprintf("%v", *o.NumberOfQueries)) + } + if o.ObservationMetric != nil { + out.Append("observationMetric", fmt.Sprintf("%v", *o.ObservationMetric)) + } + if o.StartTime != nil { + out.Append("startTime", fmt.Sprintf("%v", *o.StartTime)) + } + return &out +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ManagedInstancesClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId, options ListByManagedInstanceOperationOptions) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/topqueries", 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 *[]TopQueries `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedInstancesClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId, options ListByManagedInstanceOperationOptions) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, options, TopQueriesOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancesClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, options ListByManagedInstanceOperationOptions, predicate TopQueriesOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]TopQueries, 0) + + resp, err := c.ListByManagedInstance(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_listbyresourcegroup.go b/resource-manager/sql/2023-08-01/managedinstances/method_listbyresourcegroup.go new file mode 100644 index 00000000000..adbecb68c73 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_listbyresourcegroup.go @@ -0,0 +1,135 @@ +package managedinstances + +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 *[]ManagedInstance +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstance +} + +type ListByResourceGroupOperationOptions struct { + Expand *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ManagedInstancesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/managedInstances", 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 *[]ManagedInstance `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 ManagedInstancesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, ManagedInstanceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate ManagedInstanceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]ManagedInstance, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go new file mode 100644 index 00000000000..e2bcb4e0daa --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go @@ -0,0 +1,106 @@ +package managedinstances + +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 ListOutboundNetworkDependenciesByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OutboundEnvironmentEndpoint +} + +type ListOutboundNetworkDependenciesByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []OutboundEnvironmentEndpoint +} + +type ListOutboundNetworkDependenciesByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListOutboundNetworkDependenciesByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListOutboundNetworkDependenciesByManagedInstance ... +func (c ManagedInstancesClient) ListOutboundNetworkDependenciesByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListOutboundNetworkDependenciesByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListOutboundNetworkDependenciesByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/outboundNetworkDependenciesEndpoints", 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 *[]OutboundEnvironmentEndpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListOutboundNetworkDependenciesByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedInstancesClient) ListOutboundNetworkDependenciesByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListOutboundNetworkDependenciesByManagedInstanceCompleteResult, error) { + return c.ListOutboundNetworkDependenciesByManagedInstanceCompleteMatchingPredicate(ctx, id, OutboundEnvironmentEndpointOperationPredicate{}) +} + +// ListOutboundNetworkDependenciesByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstancesClient) ListOutboundNetworkDependenciesByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate OutboundEnvironmentEndpointOperationPredicate) (result ListOutboundNetworkDependenciesByManagedInstanceCompleteResult, err error) { + items := make([]OutboundEnvironmentEndpoint, 0) + + resp, err := c.ListOutboundNetworkDependenciesByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListOutboundNetworkDependenciesByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_refreshstatus.go b/resource-manager/sql/2023-08-01/managedinstances/method_refreshstatus.go new file mode 100644 index 00000000000..77b456fd23e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_refreshstatus.go @@ -0,0 +1,72 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshStatusOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RefreshExternalGovernanceStatusOperationResultMI +} + +// RefreshStatus ... +func (c ManagedInstancesClient) RefreshStatus(ctx context.Context, id commonids.SqlManagedInstanceId) (result RefreshStatusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshExternalGovernanceStatus", 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 +} + +// RefreshStatusThenPoll performs RefreshStatus then polls until it's completed +func (c ManagedInstancesClient) RefreshStatusThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) error { + result, err := c.RefreshStatus(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshStatus: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RefreshStatus: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_start.go b/resource-manager/sql/2023-08-01/managedinstances/method_start.go new file mode 100644 index 00000000000..0f9420be74c --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_start.go @@ -0,0 +1,72 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstance +} + +// Start ... +func (c ManagedInstancesClient) Start(ctx context.Context, id commonids.SqlManagedInstanceId) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 +} + +// StartThenPoll performs Start then polls until it's completed +func (c ManagedInstancesClient) StartThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) error { + result, err := c.Start(ctx, id) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_stop.go b/resource-manager/sql/2023-08-01/managedinstances/method_stop.go new file mode 100644 index 00000000000..d9c3c3ae52d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_stop.go @@ -0,0 +1,72 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StopOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstance +} + +// Stop ... +func (c ManagedInstancesClient) Stop(ctx context.Context, id commonids.SqlManagedInstanceId) (result StopOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", 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 +} + +// StopThenPoll performs Stop then polls until it's completed +func (c ManagedInstancesClient) StopThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId) error { + result, err := c.Stop(ctx, id) + if err != nil { + return fmt.Errorf("performing Stop: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Stop: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/method_update.go b/resource-manager/sql/2023-08-01/managedinstances/method_update.go new file mode 100644 index 00000000000..f2ebe4da4fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/method_update.go @@ -0,0 +1,76 @@ +package managedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstance +} + +// Update ... +func (c ManagedInstancesClient) Update(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceUpdate) (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 ManagedInstancesClient) UpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceUpdate) 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/sql/2023-08-01/managedinstances/model_endpointdependency.go b/resource-manager/sql/2023-08-01/managedinstances/model_endpointdependency.go new file mode 100644 index 00000000000..6536aa85d3f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_endpointdependency.go @@ -0,0 +1,9 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointDependency struct { + DomainName *string `json:"domainName,omitempty"` + EndpointDetails *[]EndpointDetail `json:"endpointDetails,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_endpointdetail.go b/resource-manager/sql/2023-08-01/managedinstances/model_endpointdetail.go new file mode 100644 index 00000000000..54168cb31ca --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_endpointdetail.go @@ -0,0 +1,8 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointDetail struct { + Port *int64 `json:"port,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstance.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstance.go new file mode 100644 index 00000000000..c14c46bf1ff --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstance.go @@ -0,0 +1,19 @@ +package managedinstances + +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 ManagedInstance struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceexternaladministrator.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceexternaladministrator.go new file mode 100644 index 00000000000..9844de05307 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceexternaladministrator.go @@ -0,0 +1,13 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceExternalAdministrator struct { + AdministratorType *AdministratorType `json:"administratorType,omitempty"` + AzureADOnlyAuthentication *bool `json:"azureADOnlyAuthentication,omitempty"` + Login *string `json:"login,omitempty"` + PrincipalType *PrincipalType `json:"principalType,omitempty"` + Sid *string `json:"sid,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstancepecproperty.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstancepecproperty.go new file mode 100644 index 00000000000..4e5c5ab6e59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstancepecproperty.go @@ -0,0 +1,9 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePecProperty struct { + Id *string `json:"id,omitempty"` + Properties *ManagedInstancePrivateEndpointConnectionProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..6bad8545c61 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateEndpointConnectionProperties struct { + PrivateEndpoint *ManagedInstancePrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *ManagedInstancePrivateLinkServiceConnectionStateProperty `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointproperty.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointproperty.go new file mode 100644 index 00000000000..0f993e64d0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivateendpointproperty.go @@ -0,0 +1,8 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..6c2f28784bc --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go @@ -0,0 +1,10 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstancePrivateLinkServiceConnectionStateProperty struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status string `json:"status"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceproperties.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceproperties.go new file mode 100644 index 00000000000..f726944a608 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceproperties.go @@ -0,0 +1,77 @@ +package managedinstances + +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 ManagedInstanceProperties struct { + AdministratorLogin *string `json:"administratorLogin,omitempty"` + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + Administrators *ManagedInstanceExternalAdministrator `json:"administrators,omitempty"` + AuthenticationMetadata *AuthMetadataLookupModes `json:"authenticationMetadata,omitempty"` + Collation *string `json:"collation,omitempty"` + CreateTime *string `json:"createTime,omitempty"` + CurrentBackupStorageRedundancy *BackupStorageRedundancy `json:"currentBackupStorageRedundancy,omitempty"` + DatabaseFormat *ManagedInstanceDatabaseFormat `json:"databaseFormat,omitempty"` + DnsZone *string `json:"dnsZone,omitempty"` + DnsZonePartner *string `json:"dnsZonePartner,omitempty"` + ExternalGovernanceStatus *ExternalGovernanceStatus `json:"externalGovernanceStatus,omitempty"` + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty"` + HybridSecondaryUsage *HybridSecondaryUsage `json:"hybridSecondaryUsage,omitempty"` + HybridSecondaryUsageDetected *HybridSecondaryUsageDetected `json:"hybridSecondaryUsageDetected,omitempty"` + InstancePoolId *string `json:"instancePoolId,omitempty"` + IsGeneralPurposeV2 *bool `json:"isGeneralPurposeV2,omitempty"` + KeyId *string `json:"keyId,omitempty"` + LicenseType *ManagedInstanceLicenseType `json:"licenseType,omitempty"` + MaintenanceConfigurationId *string `json:"maintenanceConfigurationId,omitempty"` + ManagedInstanceCreateMode *ManagedServerCreateMode `json:"managedInstanceCreateMode,omitempty"` + MinimalTlsVersion *string `json:"minimalTlsVersion,omitempty"` + PricingModel *PricingModel `json:"pricingModel,omitempty"` + PrimaryUserAssignedIdentityId *string `json:"primaryUserAssignedIdentityId,omitempty"` + PrivateEndpointConnections *[]ManagedInstancePecProperty `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ProxyOverride *ManagedInstanceProxyOverride `json:"proxyOverride,omitempty"` + PublicDataEndpointEnabled *bool `json:"publicDataEndpointEnabled,omitempty"` + RequestedBackupStorageRedundancy *BackupStorageRedundancy `json:"requestedBackupStorageRedundancy,omitempty"` + RestorePointInTime *string `json:"restorePointInTime,omitempty"` + ServicePrincipal *ServicePrincipal `json:"servicePrincipal,omitempty"` + SourceManagedInstanceId *string `json:"sourceManagedInstanceId,omitempty"` + State *string `json:"state,omitempty"` + StorageIOps *int64 `json:"storageIOps,omitempty"` + StorageSizeInGB *int64 `json:"storageSizeInGB,omitempty"` + StorageThroughputMBps *int64 `json:"storageThroughputMBps,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TimezoneId *string `json:"timezoneId,omitempty"` + VCores *int64 `json:"vCores,omitempty"` + VirtualClusterId *string `json:"virtualClusterId,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} + +func (o *ManagedInstanceProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} + +func (o *ManagedInstanceProperties) GetRestorePointInTimeAsTime() (*time.Time, error) { + if o.RestorePointInTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointInTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedInstanceProperties) SetRestorePointInTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointInTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceupdate.go b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceupdate.go new file mode 100644 index 00000000000..715d6f5b784 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_managedinstanceupdate.go @@ -0,0 +1,15 @@ +package managedinstances + +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 ManagedInstanceUpdate struct { + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ManagedInstanceProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_outboundenvironmentendpoint.go b/resource-manager/sql/2023-08-01/managedinstances/model_outboundenvironmentendpoint.go new file mode 100644 index 00000000000..503d29fe9f5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_outboundenvironmentendpoint.go @@ -0,0 +1,9 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundEnvironmentEndpoint struct { + Category *string `json:"category,omitempty"` + Endpoints *[]EndpointDependency `json:"endpoints,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_querymetricinterval.go b/resource-manager/sql/2023-08-01/managedinstances/model_querymetricinterval.go new file mode 100644 index 00000000000..00c5e8aa6c5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_querymetricinterval.go @@ -0,0 +1,11 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryMetricInterval struct { + ExecutionCount *int64 `json:"executionCount,omitempty"` + IntervalStartTime *string `json:"intervalStartTime,omitempty"` + IntervalType *QueryTimeGrainType `json:"intervalType,omitempty"` + Metrics *[]QueryMetricProperties `json:"metrics,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_querymetricproperties.go b/resource-manager/sql/2023-08-01/managedinstances/model_querymetricproperties.go new file mode 100644 index 00000000000..81519237575 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_querymetricproperties.go @@ -0,0 +1,16 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryMetricProperties struct { + Avg *float64 `json:"avg,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Max *float64 `json:"max,omitempty"` + Min *float64 `json:"min,omitempty"` + Name *string `json:"name,omitempty"` + Stdev *float64 `json:"stdev,omitempty"` + Sum *float64 `json:"sum,omitempty"` + Unit *QueryMetricUnitType `json:"unit,omitempty"` + Value *float64 `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_querystatisticsproperties.go b/resource-manager/sql/2023-08-01/managedinstances/model_querystatisticsproperties.go new file mode 100644 index 00000000000..456cf579283 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_querystatisticsproperties.go @@ -0,0 +1,12 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryStatisticsProperties struct { + DatabaseName *string `json:"databaseName,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Intervals *[]QueryMetricInterval `json:"intervals,omitempty"` + QueryId *string `json:"queryId,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go b/resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go new file mode 100644 index 00000000000..6534ae5095d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go @@ -0,0 +1,11 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshExternalGovernanceStatusOperationResultMI struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RefreshExternalGovernanceStatusOperationResultPropertiesMI `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go b/resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go new file mode 100644 index 00000000000..7e14768472b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go @@ -0,0 +1,13 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshExternalGovernanceStatusOperationResultPropertiesMI struct { + ErrorMessage *string `json:"errorMessage,omitempty"` + ManagedInstanceName *string `json:"managedInstanceName,omitempty"` + QueuedTime *string `json:"queuedTime,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestType *string `json:"requestType,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_serviceprincipal.go b/resource-manager/sql/2023-08-01/managedinstances/model_serviceprincipal.go new file mode 100644 index 00000000000..1e7a6c07887 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_serviceprincipal.go @@ -0,0 +1,11 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServicePrincipal struct { + ClientId *string `json:"clientId,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Type *ServicePrincipalType `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_sku.go b/resource-manager/sql/2023-08-01/managedinstances/model_sku.go new file mode 100644 index 00000000000..3a2fcc88d15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_sku.go @@ -0,0 +1,12 @@ +package managedinstances + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/model_topqueries.go b/resource-manager/sql/2023-08-01/managedinstances/model_topqueries.go new file mode 100644 index 00000000000..ebaf9db44e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/model_topqueries.go @@ -0,0 +1,14 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TopQueries struct { + AggregationFunction *string `json:"aggregationFunction,omitempty"` + EndTime *string `json:"endTime,omitempty"` + IntervalType *QueryTimeGrainType `json:"intervalType,omitempty"` + NumberOfQueries *int64 `json:"numberOfQueries,omitempty"` + ObservationMetric *string `json:"observationMetric,omitempty"` + Queries *[]QueryStatisticsProperties `json:"queries,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/predicates.go b/resource-manager/sql/2023-08-01/managedinstances/predicates.go new file mode 100644 index 00000000000..8d70aa8a061 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/predicates.go @@ -0,0 +1,78 @@ +package managedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ManagedInstanceOperationPredicate) Matches(input ManagedInstance) 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 +} + +type OutboundEnvironmentEndpointOperationPredicate struct { + Category *string +} + +func (p OutboundEnvironmentEndpointOperationPredicate) Matches(input OutboundEnvironmentEndpoint) bool { + + if p.Category != nil && (input.Category == nil || *p.Category != *input.Category) { + return false + } + + return true +} + +type TopQueriesOperationPredicate struct { + AggregationFunction *string + EndTime *string + NumberOfQueries *int64 + ObservationMetric *string + StartTime *string +} + +func (p TopQueriesOperationPredicate) Matches(input TopQueries) bool { + + if p.AggregationFunction != nil && (input.AggregationFunction == nil || *p.AggregationFunction != *input.AggregationFunction) { + return false + } + + if p.EndTime != nil && (input.EndTime == nil || *p.EndTime != *input.EndTime) { + return false + } + + if p.NumberOfQueries != nil && (input.NumberOfQueries == nil || *p.NumberOfQueries != *input.NumberOfQueries) { + return false + } + + if p.ObservationMetric != nil && (input.ObservationMetric == nil || *p.ObservationMetric != *input.ObservationMetric) { + return false + } + + if p.StartTime != nil && (input.StartTime == nil || *p.StartTime != *input.StartTime) { + return false + } + + return true +} diff --git a/resource-manager/sql/2023-08-01/managedinstances/version.go b/resource-manager/sql/2023-08-01/managedinstances/version.go new file mode 100644 index 00000000000..8a78fc44784 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstances/version.go @@ -0,0 +1,10 @@ +package managedinstances + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstances/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstancetdecertificates/README.md b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/README.md new file mode 100644 index 00000000000..c8da12cbff1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancetdecertificates` Documentation + +The `managedinstancetdecertificates` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancetdecertificates" +``` + + +### Client Initialization + +```go +client := managedinstancetdecertificates.NewManagedInstanceTdeCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceTdeCertificatesClient.Create` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstancetdecertificates.TdeCertificate{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstancetdecertificates/client.go b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/client.go new file mode 100644 index 00000000000..6dcfb8c143a --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/client.go @@ -0,0 +1,26 @@ +package managedinstancetdecertificates + +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 ManagedInstanceTdeCertificatesClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceTdeCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceTdeCertificatesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstancetdecertificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceTdeCertificatesClient: %+v", err) + } + + return &ManagedInstanceTdeCertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancetdecertificates/method_create.go b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/method_create.go new file mode 100644 index 00000000000..f0de15ddb97 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/method_create.go @@ -0,0 +1,75 @@ +package managedinstancetdecertificates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Create ... +func (c ManagedInstanceTdeCertificatesClient) Create(ctx context.Context, id commonids.SqlManagedInstanceId, input TdeCertificate) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/tdeCertificates", 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 ManagedInstanceTdeCertificatesClient) CreateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input TdeCertificate) 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/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificate.go b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificate.go new file mode 100644 index 00000000000..ff3dc70dac0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificate.go @@ -0,0 +1,11 @@ +package managedinstancetdecertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TdeCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TdeCertificateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificateproperties.go b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificateproperties.go new file mode 100644 index 00000000000..b9e8adb6c08 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/model_tdecertificateproperties.go @@ -0,0 +1,9 @@ +package managedinstancetdecertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TdeCertificateProperties struct { + CertPassword *string `json:"certPassword,omitempty"` + PrivateBlob string `json:"privateBlob"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancetdecertificates/version.go b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/version.go new file mode 100644 index 00000000000..a035892d1f6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancetdecertificates/version.go @@ -0,0 +1,10 @@ +package managedinstancetdecertificates + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstancetdecertificates/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/README.md b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/README.md new file mode 100644 index 00000000000..db121cea261 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments` Documentation + +The `managedinstancevulnerabilityassessments` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := managedinstancevulnerabilityassessments.NewManagedInstanceVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedinstancevulnerabilityassessments.ManagedInstanceVulnerabilityAssessment{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedInstanceVulnerabilityAssessmentsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManagedInstanceVulnerabilityAssessmentsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedInstanceVulnerabilityAssessmentsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/client.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/client.go new file mode 100644 index 00000000000..3caaad8212d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/client.go @@ -0,0 +1,26 @@ +package managedinstancevulnerabilityassessments + +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 ManagedInstanceVulnerabilityAssessmentsClient struct { + Client *resourcemanager.Client +} + +func NewManagedInstanceVulnerabilityAssessmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedInstanceVulnerabilityAssessmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedinstancevulnerabilityassessments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedInstanceVulnerabilityAssessmentsClient: %+v", err) + } + + return &ManagedInstanceVulnerabilityAssessmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..e99b5bc3559 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,60 @@ +package managedinstancevulnerabilityassessments + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceVulnerabilityAssessment +} + +// CreateOrUpdate ... +func (c ManagedInstanceVulnerabilityAssessmentsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedInstanceVulnerabilityAssessment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 ManagedInstanceVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..2d5068178e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_delete.go @@ -0,0 +1,48 @@ +package managedinstancevulnerabilityassessments + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ManagedInstanceVulnerabilityAssessmentsClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_get.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..cf558597025 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_get.go @@ -0,0 +1,55 @@ +package managedinstancevulnerabilityassessments + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedInstanceVulnerabilityAssessment +} + +// Get ... +func (c ManagedInstanceVulnerabilityAssessmentsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 ManagedInstanceVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_listbyinstance.go new file mode 100644 index 00000000000..fd8eb23fe58 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/method_listbyinstance.go @@ -0,0 +1,106 @@ +package managedinstancevulnerabilityassessments + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedInstanceVulnerabilityAssessment +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedInstanceVulnerabilityAssessment +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedInstanceVulnerabilityAssessmentsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/vulnerabilityAssessments", 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 *[]ManagedInstanceVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedInstanceVulnerabilityAssessmentsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedInstanceVulnerabilityAssessmentOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedInstanceVulnerabilityAssessmentsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedInstanceVulnerabilityAssessmentOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedInstanceVulnerabilityAssessment, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go new file mode 100644 index 00000000000..256fafc4167 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go @@ -0,0 +1,11 @@ +package managedinstancevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedInstanceVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..1828c8de6be --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package managedinstancevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath string `json:"storageContainerPath"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..0acb2f6c20f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package managedinstancevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/predicates.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..74c244d5479 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/predicates.go @@ -0,0 +1,27 @@ +package managedinstancevulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedInstanceVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedInstanceVulnerabilityAssessmentOperationPredicate) Matches(input ManagedInstanceVulnerabilityAssessment) 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/sql/2023-08-01/managedinstancevulnerabilityassessments/version.go b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/version.go new file mode 100644 index 00000000000..42d8c10371e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedinstancevulnerabilityassessments/version.go @@ -0,0 +1,10 @@ +package managedinstancevulnerabilityassessments + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedinstancevulnerabilityassessments/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/README.md b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/README.md new file mode 100644 index 00000000000..ed14975bfa5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedledgerdigestuploads` Documentation + +The `managedledgerdigestuploads` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedledgerdigestuploads" +``` + + +### Client Initialization + +```go +client := managedledgerdigestuploads.NewManagedLedgerDigestUploadsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedLedgerDigestUploadsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +payload := managedledgerdigestuploads.ManagedLedgerDigestUploads{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedLedgerDigestUploadsClient.Disable` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +if err := client.DisableThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedLedgerDigestUploadsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +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: `ManagedLedgerDigestUploadsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/client.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/client.go new file mode 100644 index 00000000000..06b0ada5f1e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/client.go @@ -0,0 +1,26 @@ +package managedledgerdigestuploads + +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 ManagedLedgerDigestUploadsClient struct { + Client *resourcemanager.Client +} + +func NewManagedLedgerDigestUploadsClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedLedgerDigestUploadsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedledgerdigestuploads", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedLedgerDigestUploadsClient: %+v", err) + } + + return &ManagedLedgerDigestUploadsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/constants.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/constants.go new file mode 100644 index 00000000000..9d3b56cbc15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/constants.go @@ -0,0 +1,51 @@ +package managedledgerdigestuploads + +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 ManagedLedgerDigestUploadsState string + +const ( + ManagedLedgerDigestUploadsStateDisabled ManagedLedgerDigestUploadsState = "Disabled" + ManagedLedgerDigestUploadsStateEnabled ManagedLedgerDigestUploadsState = "Enabled" +) + +func PossibleValuesForManagedLedgerDigestUploadsState() []string { + return []string{ + string(ManagedLedgerDigestUploadsStateDisabled), + string(ManagedLedgerDigestUploadsStateEnabled), + } +} + +func (s *ManagedLedgerDigestUploadsState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedLedgerDigestUploadsState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedLedgerDigestUploadsState(input string) (*ManagedLedgerDigestUploadsState, error) { + vals := map[string]ManagedLedgerDigestUploadsState{ + "disabled": ManagedLedgerDigestUploadsStateDisabled, + "enabled": ManagedLedgerDigestUploadsStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedLedgerDigestUploadsState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_createorupdate.go new file mode 100644 index 00000000000..c48f8c8602f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedledgerdigestuploads + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedLedgerDigestUploads +} + +// CreateOrUpdate ... +func (c ManagedLedgerDigestUploadsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedLedgerDigestUploads) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/ledgerDigestUploads/current", 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 ManagedLedgerDigestUploadsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, input ManagedLedgerDigestUploads) 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/sql/2023-08-01/managedledgerdigestuploads/method_disable.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_disable.go new file mode 100644 index 00000000000..9deee5182b3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_disable.go @@ -0,0 +1,72 @@ +package managedledgerdigestuploads + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DisableOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedLedgerDigestUploads +} + +// Disable ... +func (c ManagedLedgerDigestUploadsClient) Disable(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result DisableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/ledgerDigestUploads/current/disable", 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 +} + +// DisableThenPoll performs Disable then polls until it's completed +func (c ManagedLedgerDigestUploadsClient) DisableThenPoll(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) error { + result, err := c.Disable(ctx, id) + if err != nil { + return fmt.Errorf("performing Disable: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Disable: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_get.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_get.go new file mode 100644 index 00000000000..e244cc479e9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_get.go @@ -0,0 +1,55 @@ +package managedledgerdigestuploads + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedLedgerDigestUploads +} + +// Get ... +func (c ManagedLedgerDigestUploadsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/ledgerDigestUploads/current", 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 ManagedLedgerDigestUploads + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_listbydatabase.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_listbydatabase.go new file mode 100644 index 00000000000..3c3d455fa28 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/method_listbydatabase.go @@ -0,0 +1,106 @@ +package managedledgerdigestuploads + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedLedgerDigestUploads +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedLedgerDigestUploads +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ManagedLedgerDigestUploadsClient) ListByDatabase(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/ledgerDigestUploads", 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 *[]ManagedLedgerDigestUploads `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ManagedLedgerDigestUploadsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ManagedLedgerDigestUploadsOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedLedgerDigestUploadsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceDatabaseId, predicate ManagedLedgerDigestUploadsOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ManagedLedgerDigestUploads, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploads.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploads.go new file mode 100644 index 00000000000..8b263d02d17 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploads.go @@ -0,0 +1,11 @@ +package managedledgerdigestuploads + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedLedgerDigestUploads struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedLedgerDigestUploadsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go new file mode 100644 index 00000000000..ef73087d083 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go @@ -0,0 +1,9 @@ +package managedledgerdigestuploads + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedLedgerDigestUploadsProperties struct { + DigestStorageEndpoint *string `json:"digestStorageEndpoint,omitempty"` + State *ManagedLedgerDigestUploadsState `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedledgerdigestuploads/predicates.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/predicates.go new file mode 100644 index 00000000000..3b918d87f53 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/predicates.go @@ -0,0 +1,27 @@ +package managedledgerdigestuploads + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedLedgerDigestUploadsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedLedgerDigestUploadsOperationPredicate) Matches(input ManagedLedgerDigestUploads) 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/sql/2023-08-01/managedledgerdigestuploads/version.go b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/version.go new file mode 100644 index 00000000000..c0ac82d4136 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedledgerdigestuploads/version.go @@ -0,0 +1,10 @@ +package managedledgerdigestuploads + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedledgerdigestuploads/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md new file mode 100644 index 00000000000..6758777daaf --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md @@ -0,0 +1,87 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies` Documentation + +The `managedrestorabledroppeddatabasebackupshorttermretentionpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies" +``` + + +### Client Initialization + +```go +client := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + +payload := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + +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: `ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.ListByRestorableDroppedDatabase` + +```go +ctx := context.TODO() +id := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + +// alternatively `client.ListByRestorableDroppedDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByRestorableDroppedDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient.Update` + +```go +ctx := context.TODO() +id := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + +payload := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go new file mode 100644 index 00000000000..4d3926b2444 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go @@ -0,0 +1,26 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +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 ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedrestorabledroppeddatabasebackupshorttermretentionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient: %+v", err) + } + + return &ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go new file mode 100644 index 00000000000..ad58c9e2c83 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go @@ -0,0 +1,139 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstanceRestorableDroppedDatabaseId{}) +} + +var _ resourceids.ResourceId = &ManagedInstanceRestorableDroppedDatabaseId{} + +// ManagedInstanceRestorableDroppedDatabaseId is a struct representing the Resource ID for a Managed Instance Restorable Dropped Database +type ManagedInstanceRestorableDroppedDatabaseId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + RestorableDroppedDatabaseId string +} + +// NewManagedInstanceRestorableDroppedDatabaseID returns a new ManagedInstanceRestorableDroppedDatabaseId struct +func NewManagedInstanceRestorableDroppedDatabaseID(subscriptionId string, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseId string) ManagedInstanceRestorableDroppedDatabaseId { + return ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + RestorableDroppedDatabaseId: restorableDroppedDatabaseId, + } +} + +// ParseManagedInstanceRestorableDroppedDatabaseID parses 'input' into a ManagedInstanceRestorableDroppedDatabaseId +func ParseManagedInstanceRestorableDroppedDatabaseID(input string) (*ManagedInstanceRestorableDroppedDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceRestorableDroppedDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceRestorableDroppedDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstanceRestorableDroppedDatabaseIDInsensitively parses 'input' case-insensitively into a ManagedInstanceRestorableDroppedDatabaseId +// note: this method should only be used for API response data and not user input +func ParseManagedInstanceRestorableDroppedDatabaseIDInsensitively(input string) (*ManagedInstanceRestorableDroppedDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceRestorableDroppedDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceRestorableDroppedDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstanceRestorableDroppedDatabaseId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.RestorableDroppedDatabaseId, ok = input.Parsed["restorableDroppedDatabaseId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "restorableDroppedDatabaseId", input) + } + + return nil +} + +// ValidateManagedInstanceRestorableDroppedDatabaseID checks that 'input' can be parsed as a Managed Instance Restorable Dropped Database ID +func ValidateManagedInstanceRestorableDroppedDatabaseID(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 := ParseManagedInstanceRestorableDroppedDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Restorable Dropped Database ID +func (id ManagedInstanceRestorableDroppedDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/restorableDroppedDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.RestorableDroppedDatabaseId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Restorable Dropped Database ID +func (id ManagedInstanceRestorableDroppedDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticRestorableDroppedDatabases", "restorableDroppedDatabases", "restorableDroppedDatabases"), + resourceids.UserSpecifiedSegment("restorableDroppedDatabaseId", "restorableDroppedDatabaseId"), + } +} + +// String returns a human-readable description of this Managed Instance Restorable Dropped Database ID +func (id ManagedInstanceRestorableDroppedDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Restorable Dropped Database: %q", id.RestorableDroppedDatabaseId), + } + return fmt.Sprintf("Managed Instance Restorable Dropped Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go new file mode 100644 index 00000000000..9e2dcf0da2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go @@ -0,0 +1,327 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +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 = &ManagedInstanceRestorableDroppedDatabaseId{} + +func TestNewManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + id := NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.RestorableDroppedDatabaseId != "restorableDroppedDatabaseId" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedDatabaseId'", id.RestorableDroppedDatabaseId, "restorableDroppedDatabaseId") + } +} + +func TestFormatManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + actual := NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceRestorableDroppedDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceRestorableDroppedDatabaseID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.RestorableDroppedDatabaseId != v.Expected.RestorableDroppedDatabaseId { + t.Fatalf("Expected %q but got %q for RestorableDroppedDatabaseId", v.Expected.RestorableDroppedDatabaseId, actual.RestorableDroppedDatabaseId) + } + + } +} + +func TestParseManagedInstanceRestorableDroppedDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceRestorableDroppedDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEsToRaBlEdRoPpEdDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeId", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + RestorableDroppedDatabaseId: "rEsToRaBlEdRoPpEdDaTaBaSeId", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceRestorableDroppedDatabaseIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.RestorableDroppedDatabaseId != v.Expected.RestorableDroppedDatabaseId { + t.Fatalf("Expected %q but got %q for RestorableDroppedDatabaseId", v.Expected.RestorableDroppedDatabaseId, actual.RestorableDroppedDatabaseId) + } + + } +} + +func TestSegmentsForManagedInstanceRestorableDroppedDatabaseId(t *testing.T) { + segments := ManagedInstanceRestorableDroppedDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstanceRestorableDroppedDatabaseId 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/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..f16fb8db2cc --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go @@ -0,0 +1,75 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +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 *ManagedBackupShortTermRetentionPolicy +} + +// CreateOrUpdate ... +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) CreateOrUpdate(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId, input ManagedBackupShortTermRetentionPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId, input ManagedBackupShortTermRetentionPolicy) 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/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go new file mode 100644 index 00000000000..658ba4e5f1d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go @@ -0,0 +1,54 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +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 *ManagedBackupShortTermRetentionPolicy +} + +// Get ... +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) Get(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 ManagedBackupShortTermRetentionPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go new file mode 100644 index 00000000000..6c10dd7bb9d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go @@ -0,0 +1,105 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +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 ListByRestorableDroppedDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedBackupShortTermRetentionPolicy +} + +type ListByRestorableDroppedDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedBackupShortTermRetentionPolicy +} + +type ListByRestorableDroppedDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByRestorableDroppedDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByRestorableDroppedDatabase ... +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabase(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId) (result ListByRestorableDroppedDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByRestorableDroppedDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies", 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 *[]ManagedBackupShortTermRetentionPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByRestorableDroppedDatabaseComplete retrieves all the results into a single object +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabaseComplete(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId) (ListByRestorableDroppedDatabaseCompleteResult, error) { + return c.ListByRestorableDroppedDatabaseCompleteMatchingPredicate(ctx, id, ManagedBackupShortTermRetentionPolicyOperationPredicate{}) +} + +// ListByRestorableDroppedDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) ListByRestorableDroppedDatabaseCompleteMatchingPredicate(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId, predicate ManagedBackupShortTermRetentionPolicyOperationPredicate) (result ListByRestorableDroppedDatabaseCompleteResult, err error) { + items := make([]ManagedBackupShortTermRetentionPolicy, 0) + + resp, err := c.ListByRestorableDroppedDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByRestorableDroppedDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go new file mode 100644 index 00000000000..ae43aac50b3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go @@ -0,0 +1,75 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +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 *ManagedBackupShortTermRetentionPolicy +} + +// Update ... +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) Update(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId, input ManagedBackupShortTermRetentionPolicy) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/backupShortTermRetentionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesClient) UpdateThenPoll(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId, input ManagedBackupShortTermRetentionPolicy) 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/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go new file mode 100644 index 00000000000..e3f4bf7d26d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go @@ -0,0 +1,11 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedBackupShortTermRetentionPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedBackupShortTermRetentionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go new file mode 100644 index 00000000000..e90d7807e81 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go @@ -0,0 +1,8 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedBackupShortTermRetentionPolicyProperties struct { + RetentionDays *int64 `json:"retentionDays,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go new file mode 100644 index 00000000000..c6890ca1ddf --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go @@ -0,0 +1,27 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedBackupShortTermRetentionPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedBackupShortTermRetentionPolicyOperationPredicate) Matches(input ManagedBackupShortTermRetentionPolicy) 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/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go new file mode 100644 index 00000000000..eec9840c4a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go @@ -0,0 +1,10 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/README.md b/resource-manager/sql/2023-08-01/managedserverdnsaliases/README.md new file mode 100644 index 00000000000..4002760987f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/README.md @@ -0,0 +1,100 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedserverdnsaliases` Documentation + +The `managedserverdnsaliases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedserverdnsaliases" +``` + + +### Client Initialization + +```go +client := managedserverdnsaliases.NewManagedServerDnsAliasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedServerDnsAliasesClient.Acquire` + +```go +ctx := context.TODO() +id := managedserverdnsaliases.NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "dnsAliasName") + +payload := managedserverdnsaliases.ManagedServerDnsAliasAcquisition{ + // ... +} + + +if err := client.AcquireThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedServerDnsAliasesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedserverdnsaliases.NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "dnsAliasName") + +payload := managedserverdnsaliases.ManagedServerDnsAliasCreation{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedServerDnsAliasesClient.Delete` + +```go +ctx := context.TODO() +id := managedserverdnsaliases.NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "dnsAliasName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedServerDnsAliasesClient.Get` + +```go +ctx := context.TODO() +id := managedserverdnsaliases.NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "dnsAliasName") + +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: `ManagedServerDnsAliasesClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/client.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/client.go new file mode 100644 index 00000000000..bbb095b5022 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/client.go @@ -0,0 +1,26 @@ +package managedserverdnsaliases + +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 ManagedServerDnsAliasesClient struct { + Client *resourcemanager.Client +} + +func NewManagedServerDnsAliasesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedServerDnsAliasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedserverdnsaliases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedServerDnsAliasesClient: %+v", err) + } + + return &ManagedServerDnsAliasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias.go new file mode 100644 index 00000000000..4807769084f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias.go @@ -0,0 +1,139 @@ +package managedserverdnsaliases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstanceDnsAliasId{}) +} + +var _ resourceids.ResourceId = &ManagedInstanceDnsAliasId{} + +// ManagedInstanceDnsAliasId is a struct representing the Resource ID for a Managed Instance Dns Alias +type ManagedInstanceDnsAliasId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + DnsAliasName string +} + +// NewManagedInstanceDnsAliasID returns a new ManagedInstanceDnsAliasId struct +func NewManagedInstanceDnsAliasID(subscriptionId string, resourceGroupName string, managedInstanceName string, dnsAliasName string) ManagedInstanceDnsAliasId { + return ManagedInstanceDnsAliasId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + DnsAliasName: dnsAliasName, + } +} + +// ParseManagedInstanceDnsAliasID parses 'input' into a ManagedInstanceDnsAliasId +func ParseManagedInstanceDnsAliasID(input string) (*ManagedInstanceDnsAliasId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceDnsAliasId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceDnsAliasId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstanceDnsAliasIDInsensitively parses 'input' case-insensitively into a ManagedInstanceDnsAliasId +// note: this method should only be used for API response data and not user input +func ParseManagedInstanceDnsAliasIDInsensitively(input string) (*ManagedInstanceDnsAliasId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceDnsAliasId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceDnsAliasId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstanceDnsAliasId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.DnsAliasName, ok = input.Parsed["dnsAliasName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dnsAliasName", input) + } + + return nil +} + +// ValidateManagedInstanceDnsAliasID checks that 'input' can be parsed as a Managed Instance Dns Alias ID +func ValidateManagedInstanceDnsAliasID(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 := ParseManagedInstanceDnsAliasID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Dns Alias ID +func (id ManagedInstanceDnsAliasId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/dnsAliases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.DnsAliasName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Dns Alias ID +func (id ManagedInstanceDnsAliasId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticDnsAliases", "dnsAliases", "dnsAliases"), + resourceids.UserSpecifiedSegment("dnsAliasName", "dnsAliasName"), + } +} + +// String returns a human-readable description of this Managed Instance Dns Alias ID +func (id ManagedInstanceDnsAliasId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Dns Alias Name: %q", id.DnsAliasName), + } + return fmt.Sprintf("Managed Instance Dns Alias (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias_test.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias_test.go new file mode 100644 index 00000000000..a77921b1d1d --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/id_managedinstancednsalias_test.go @@ -0,0 +1,327 @@ +package managedserverdnsaliases + +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 = &ManagedInstanceDnsAliasId{} + +func TestNewManagedInstanceDnsAliasID(t *testing.T) { + id := NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "dnsAliasName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.DnsAliasName != "dnsAliasName" { + t.Fatalf("Expected %q but got %q for Segment 'DnsAliasName'", id.DnsAliasName, "dnsAliasName") + } +} + +func TestFormatManagedInstanceDnsAliasID(t *testing.T) { + actual := NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "dnsAliasName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases/dnsAliasName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstanceDnsAliasID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceDnsAliasId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases/dnsAliasName", + Expected: &ManagedInstanceDnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DnsAliasName: "dnsAliasName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases/dnsAliasName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceDnsAliasID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DnsAliasName != v.Expected.DnsAliasName { + t.Fatalf("Expected %q but got %q for DnsAliasName", v.Expected.DnsAliasName, actual.DnsAliasName) + } + + } +} + +func TestParseManagedInstanceDnsAliasIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceDnsAliasId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dNsAlIaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases/dnsAliasName", + Expected: &ManagedInstanceDnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + DnsAliasName: "dnsAliasName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/dnsAliases/dnsAliasName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dNsAlIaSeS/dNsAlIaSnAmE", + Expected: &ManagedInstanceDnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + DnsAliasName: "dNsAlIaSnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/dNsAlIaSeS/dNsAlIaSnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceDnsAliasIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.DnsAliasName != v.Expected.DnsAliasName { + t.Fatalf("Expected %q but got %q for DnsAliasName", v.Expected.DnsAliasName, actual.DnsAliasName) + } + + } +} + +func TestSegmentsForManagedInstanceDnsAliasId(t *testing.T) { + segments := ManagedInstanceDnsAliasId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstanceDnsAliasId 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/sql/2023-08-01/managedserverdnsaliases/method_acquire.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_acquire.go new file mode 100644 index 00000000000..c318d79ebcc --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_acquire.go @@ -0,0 +1,75 @@ +package managedserverdnsaliases + +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 AcquireOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedServerDnsAlias +} + +// Acquire ... +func (c ManagedServerDnsAliasesClient) Acquire(ctx context.Context, id ManagedInstanceDnsAliasId, input ManagedServerDnsAliasAcquisition) (result AcquireOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/acquire", 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 +} + +// AcquireThenPoll performs Acquire then polls until it's completed +func (c ManagedServerDnsAliasesClient) AcquireThenPoll(ctx context.Context, id ManagedInstanceDnsAliasId, input ManagedServerDnsAliasAcquisition) error { + result, err := c.Acquire(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Acquire: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Acquire: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_createorupdate.go new file mode 100644 index 00000000000..377fc21cba5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedserverdnsaliases + +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 *ManagedServerDnsAlias +} + +// CreateOrUpdate ... +func (c ManagedServerDnsAliasesClient) CreateOrUpdate(ctx context.Context, id ManagedInstanceDnsAliasId, input ManagedServerDnsAliasCreation) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ManagedServerDnsAliasesClient) CreateOrUpdateThenPoll(ctx context.Context, id ManagedInstanceDnsAliasId, input ManagedServerDnsAliasCreation) 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/sql/2023-08-01/managedserverdnsaliases/method_delete.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_delete.go new file mode 100644 index 00000000000..08ab08a773e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_delete.go @@ -0,0 +1,71 @@ +package managedserverdnsaliases + +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 ManagedServerDnsAliasesClient) Delete(ctx context.Context, id ManagedInstanceDnsAliasId) (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 ManagedServerDnsAliasesClient) DeleteThenPoll(ctx context.Context, id ManagedInstanceDnsAliasId) 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/sql/2023-08-01/managedserverdnsaliases/method_get.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_get.go new file mode 100644 index 00000000000..6d08e132028 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_get.go @@ -0,0 +1,53 @@ +package managedserverdnsaliases + +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 *ManagedServerDnsAlias +} + +// Get ... +func (c ManagedServerDnsAliasesClient) Get(ctx context.Context, id ManagedInstanceDnsAliasId) (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 ManagedServerDnsAlias + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_listbymanagedinstance.go new file mode 100644 index 00000000000..b78e1583e01 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/method_listbymanagedinstance.go @@ -0,0 +1,106 @@ +package managedserverdnsaliases + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedServerDnsAlias +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedServerDnsAlias +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ManagedServerDnsAliasesClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/dnsAliases", 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 *[]ManagedServerDnsAlias `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ManagedServerDnsAliasesClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, ManagedServerDnsAliasOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedServerDnsAliasesClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedServerDnsAliasOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]ManagedServerDnsAlias, 0) + + resp, err := c.ListByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsalias.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsalias.go new file mode 100644 index 00000000000..168bf0ac558 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsalias.go @@ -0,0 +1,11 @@ +package managedserverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedServerDnsAlias struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedServerDnsAliasProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go new file mode 100644 index 00000000000..a9c14c4d21f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go @@ -0,0 +1,8 @@ +package managedserverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedServerDnsAliasAcquisition struct { + OldManagedServerDnsAliasResourceId string `json:"oldManagedServerDnsAliasResourceId"` +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliascreation.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliascreation.go new file mode 100644 index 00000000000..764a4d8c75b --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliascreation.go @@ -0,0 +1,8 @@ +package managedserverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedServerDnsAliasCreation struct { + CreateDnsRecord *bool `json:"createDnsRecord,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasproperties.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasproperties.go new file mode 100644 index 00000000000..10111357fda --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/model_managedserverdnsaliasproperties.go @@ -0,0 +1,9 @@ +package managedserverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedServerDnsAliasProperties struct { + AzureDnsRecord *string `json:"azureDnsRecord,omitempty"` + PublicAzureDnsRecord *string `json:"publicAzureDnsRecord,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedserverdnsaliases/predicates.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/predicates.go new file mode 100644 index 00000000000..e28462262fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/predicates.go @@ -0,0 +1,27 @@ +package managedserverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedServerDnsAliasOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedServerDnsAliasOperationPredicate) Matches(input ManagedServerDnsAlias) 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/sql/2023-08-01/managedserverdnsaliases/version.go b/resource-manager/sql/2023-08-01/managedserverdnsaliases/version.go new file mode 100644 index 00000000000..1297e65dea8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserverdnsaliases/version.go @@ -0,0 +1,10 @@ +package managedserverdnsaliases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedserverdnsaliases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/README.md b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/README.md new file mode 100644 index 00000000000..9c946e3d99e --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies` Documentation + +The `managedserversecurityalertpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := managedserversecurityalertpolicies.NewManagedServerSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedServerSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := managedserversecurityalertpolicies.ManagedServerSecurityAlertPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedServerSecurityAlertPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ManagedServerSecurityAlertPoliciesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/client.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/client.go new file mode 100644 index 00000000000..96e6a83b8ad --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/client.go @@ -0,0 +1,26 @@ +package managedserversecurityalertpolicies + +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 ManagedServerSecurityAlertPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewManagedServerSecurityAlertPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ManagedServerSecurityAlertPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "managedserversecurityalertpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManagedServerSecurityAlertPoliciesClient: %+v", err) + } + + return &ManagedServerSecurityAlertPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/constants.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/constants.go new file mode 100644 index 00000000000..7c52e21af30 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/constants.go @@ -0,0 +1,51 @@ +package managedserversecurityalertpolicies + +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 SecurityAlertsPolicyState string + +const ( + SecurityAlertsPolicyStateDisabled SecurityAlertsPolicyState = "Disabled" + SecurityAlertsPolicyStateEnabled SecurityAlertsPolicyState = "Enabled" +) + +func PossibleValuesForSecurityAlertsPolicyState() []string { + return []string{ + string(SecurityAlertsPolicyStateDisabled), + string(SecurityAlertsPolicyStateEnabled), + } +} + +func (s *SecurityAlertsPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityAlertsPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityAlertsPolicyState(input string) (*SecurityAlertsPolicyState, error) { + vals := map[string]SecurityAlertsPolicyState{ + "disabled": SecurityAlertsPolicyStateDisabled, + "enabled": SecurityAlertsPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityAlertsPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..57aee003231 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package managedserversecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedServerSecurityAlertPolicy +} + +// CreateOrUpdate ... +func (c ManagedServerSecurityAlertPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedServerSecurityAlertPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ManagedServerSecurityAlertPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ManagedServerSecurityAlertPolicy) 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/sql/2023-08-01/managedserversecurityalertpolicies/method_get.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..5e927a5ac66 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_get.go @@ -0,0 +1,55 @@ +package managedserversecurityalertpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedServerSecurityAlertPolicy +} + +// Get ... +func (c ManagedServerSecurityAlertPoliciesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 ManagedServerSecurityAlertPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_listbyinstance.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_listbyinstance.go new file mode 100644 index 00000000000..d0588ca068f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/method_listbyinstance.go @@ -0,0 +1,106 @@ +package managedserversecurityalertpolicies + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedServerSecurityAlertPolicy +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ManagedServerSecurityAlertPolicy +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ManagedServerSecurityAlertPoliciesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/securityAlertPolicies", 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 *[]ManagedServerSecurityAlertPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ManagedServerSecurityAlertPoliciesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ManagedServerSecurityAlertPolicyOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ManagedServerSecurityAlertPoliciesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ManagedServerSecurityAlertPolicyOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ManagedServerSecurityAlertPolicy, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go new file mode 100644 index 00000000000..a3a3c5f4524 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go @@ -0,0 +1,16 @@ +package managedserversecurityalertpolicies + +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 ManagedServerSecurityAlertPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityAlertsPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go new file mode 100644 index 00000000000..7dc643f69f0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go @@ -0,0 +1,33 @@ +package managedserversecurityalertpolicies + +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 SecurityAlertsPolicyProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + DisabledAlerts *[]string `json:"disabledAlerts,omitempty"` + EmailAccountAdmins *bool `json:"emailAccountAdmins,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State SecurityAlertsPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} + +func (o *SecurityAlertsPolicyProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertsPolicyProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/predicates.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..c7d46c58a0f --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/predicates.go @@ -0,0 +1,27 @@ +package managedserversecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedServerSecurityAlertPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ManagedServerSecurityAlertPolicyOperationPredicate) Matches(input ManagedServerSecurityAlertPolicy) 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/sql/2023-08-01/managedserversecurityalertpolicies/version.go b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/version.go new file mode 100644 index 00000000000..0f377b958e4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/managedserversecurityalertpolicies/version.go @@ -0,0 +1,10 @@ +package managedserversecurityalertpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/managedserversecurityalertpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/README.md b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/README.md new file mode 100644 index 00000000000..0b213a77414 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/README.md @@ -0,0 +1,66 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations` Documentation + +The `networksecurityperimeterconfigurations` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations" +``` + + +### Client Initialization + +```go +client := networksecurityperimeterconfigurations.NewNetworkSecurityPerimeterConfigurationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NetworkSecurityPerimeterConfigurationsClient.Get` + +```go +ctx := context.TODO() +id := networksecurityperimeterconfigurations.NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "networkSecurityPerimeterConfigurationName") + +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: `NetworkSecurityPerimeterConfigurationsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NetworkSecurityPerimeterConfigurationsClient.Reconcile` + +```go +ctx := context.TODO() +id := networksecurityperimeterconfigurations.NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "networkSecurityPerimeterConfigurationName") + +if err := client.ReconcileThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/client.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/client.go new file mode 100644 index 00000000000..20530b9e06a --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/client.go @@ -0,0 +1,26 @@ +package networksecurityperimeterconfigurations + +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 NetworkSecurityPerimeterConfigurationsClient struct { + Client *resourcemanager.Client +} + +func NewNetworkSecurityPerimeterConfigurationsClientWithBaseURI(sdkApi sdkEnv.Api) (*NetworkSecurityPerimeterConfigurationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "networksecurityperimeterconfigurations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NetworkSecurityPerimeterConfigurationsClient: %+v", err) + } + + return &NetworkSecurityPerimeterConfigurationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..5ca3f6e6c25 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go @@ -0,0 +1,139 @@ +package networksecurityperimeterconfigurations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&NetworkSecurityPerimeterConfigurationId{}) +} + +var _ resourceids.ResourceId = &NetworkSecurityPerimeterConfigurationId{} + +// NetworkSecurityPerimeterConfigurationId is a struct representing the Resource ID for a Network Security Perimeter Configuration +type NetworkSecurityPerimeterConfigurationId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + NetworkSecurityPerimeterConfigurationName string +} + +// NewNetworkSecurityPerimeterConfigurationID returns a new NetworkSecurityPerimeterConfigurationId struct +func NewNetworkSecurityPerimeterConfigurationID(subscriptionId string, resourceGroupName string, serverName string, networkSecurityPerimeterConfigurationName string) NetworkSecurityPerimeterConfigurationId { + return NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + NetworkSecurityPerimeterConfigurationName: networkSecurityPerimeterConfigurationName, + } +} + +// ParseNetworkSecurityPerimeterConfigurationID parses 'input' into a NetworkSecurityPerimeterConfigurationId +func ParseNetworkSecurityPerimeterConfigurationID(input string) (*NetworkSecurityPerimeterConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkSecurityPerimeterConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkSecurityPerimeterConfigurationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNetworkSecurityPerimeterConfigurationIDInsensitively parses 'input' case-insensitively into a NetworkSecurityPerimeterConfigurationId +// note: this method should only be used for API response data and not user input +func ParseNetworkSecurityPerimeterConfigurationIDInsensitively(input string) (*NetworkSecurityPerimeterConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkSecurityPerimeterConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkSecurityPerimeterConfigurationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NetworkSecurityPerimeterConfigurationId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.NetworkSecurityPerimeterConfigurationName, ok = input.Parsed["networkSecurityPerimeterConfigurationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "networkSecurityPerimeterConfigurationName", input) + } + + return nil +} + +// ValidateNetworkSecurityPerimeterConfigurationID checks that 'input' can be parsed as a Network Security Perimeter Configuration ID +func ValidateNetworkSecurityPerimeterConfigurationID(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 := ParseNetworkSecurityPerimeterConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Network Security Perimeter Configuration ID +func (id NetworkSecurityPerimeterConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/networkSecurityPerimeterConfigurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.NetworkSecurityPerimeterConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Network Security Perimeter Configuration ID +func (id NetworkSecurityPerimeterConfigurationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticNetworkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations"), + resourceids.UserSpecifiedSegment("networkSecurityPerimeterConfigurationName", "networkSecurityPerimeterConfigurationName"), + } +} + +// String returns a human-readable description of this Network Security Perimeter Configuration ID +func (id NetworkSecurityPerimeterConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Network Security Perimeter Configuration Name: %q", id.NetworkSecurityPerimeterConfigurationName), + } + return fmt.Sprintf("Network Security Perimeter Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go new file mode 100644 index 00000000000..f3bcc888cdb --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go @@ -0,0 +1,327 @@ +package networksecurityperimeterconfigurations + +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 = &NetworkSecurityPerimeterConfigurationId{} + +func TestNewNetworkSecurityPerimeterConfigurationID(t *testing.T) { + id := NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "networkSecurityPerimeterConfigurationName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.NetworkSecurityPerimeterConfigurationName != "networkSecurityPerimeterConfigurationName" { + t.Fatalf("Expected %q but got %q for Segment 'NetworkSecurityPerimeterConfigurationName'", id.NetworkSecurityPerimeterConfigurationName, "networkSecurityPerimeterConfigurationName") + } +} + +func TestFormatNetworkSecurityPerimeterConfigurationID(t *testing.T) { + actual := NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "networkSecurityPerimeterConfigurationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNetworkSecurityPerimeterConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkSecurityPerimeterConfigurationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkSecurityPerimeterConfigurationID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.NetworkSecurityPerimeterConfigurationName != v.Expected.NetworkSecurityPerimeterConfigurationName { + t.Fatalf("Expected %q but got %q for NetworkSecurityPerimeterConfigurationName", v.Expected.NetworkSecurityPerimeterConfigurationName, actual.NetworkSecurityPerimeterConfigurationName) + } + + } +} + +func TestParseNetworkSecurityPerimeterConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkSecurityPerimeterConfigurationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnNaMe", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + NetworkSecurityPerimeterConfigurationName: "nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkSecurityPerimeterConfigurationIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.NetworkSecurityPerimeterConfigurationName != v.Expected.NetworkSecurityPerimeterConfigurationName { + t.Fatalf("Expected %q but got %q for NetworkSecurityPerimeterConfigurationName", v.Expected.NetworkSecurityPerimeterConfigurationName, actual.NetworkSecurityPerimeterConfigurationName) + } + + } +} + +func TestSegmentsForNetworkSecurityPerimeterConfigurationId(t *testing.T) { + segments := NetworkSecurityPerimeterConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NetworkSecurityPerimeterConfigurationId 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/sql/2023-08-01/networksecurityperimeterconfigurations/method_get.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_get.go new file mode 100644 index 00000000000..ff7885e0a3d --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_get.go @@ -0,0 +1,53 @@ +package networksecurityperimeterconfigurations + +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 *NetworkSecurityPerimeterConfiguration +} + +// Get ... +func (c NetworkSecurityPerimeterConfigurationsClient) Get(ctx context.Context, id NetworkSecurityPerimeterConfigurationId) (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 NetworkSecurityPerimeterConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_listbyserver.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_listbyserver.go new file mode 100644 index 00000000000..fbf350145f6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_listbyserver.go @@ -0,0 +1,106 @@ +package networksecurityperimeterconfigurations + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]NetworkSecurityPerimeterConfiguration +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []NetworkSecurityPerimeterConfiguration +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c NetworkSecurityPerimeterConfigurationsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/networkSecurityPerimeterConfigurations", 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 *[]NetworkSecurityPerimeterConfiguration `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c NetworkSecurityPerimeterConfigurationsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, NetworkSecurityPerimeterConfigurationOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NetworkSecurityPerimeterConfigurationsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate NetworkSecurityPerimeterConfigurationOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]NetworkSecurityPerimeterConfiguration, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_reconcile.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_reconcile.go new file mode 100644 index 00000000000..94b8d84fcd8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/method_reconcile.go @@ -0,0 +1,71 @@ +package networksecurityperimeterconfigurations + +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 ReconcileOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *NetworkSecurityPerimeterConfiguration +} + +// Reconcile ... +func (c NetworkSecurityPerimeterConfigurationsClient) Reconcile(ctx context.Context, id NetworkSecurityPerimeterConfigurationId) (result ReconcileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/reconcile", 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 +} + +// ReconcileThenPoll performs Reconcile then polls until it's completed +func (c NetworkSecurityPerimeterConfigurationsClient) ReconcileThenPoll(ctx context.Context, id NetworkSecurityPerimeterConfigurationId) error { + result, err := c.Reconcile(ctx, id) + if err != nil { + return fmt.Errorf("performing Reconcile: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Reconcile: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..44c20a00fad --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go @@ -0,0 +1,11 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *NetworkSecurityPerimeterConfigurationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go new file mode 100644 index 00000000000..bbb025c967f --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go @@ -0,0 +1,12 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationProperties struct { + NetworkSecurityPerimeter *NSPConfigPerimeter `json:"networkSecurityPerimeter,omitempty"` + Profile *NSPConfigProfile `json:"profile,omitempty"` + ProvisioningIssues *[]NSPProvisioningIssue `json:"provisioningIssues,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ResourceAssociation *NSPConfigAssociation `json:"resourceAssociation,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go new file mode 100644 index 00000000000..0b853ab1da5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPConfigAccessRule struct { + Name *string `json:"name,omitempty"` + Properties *NSPConfigAccessRuleProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go new file mode 100644 index 00000000000..1f533729752 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go @@ -0,0 +1,13 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPConfigAccessRuleProperties struct { + AddressPrefixes *[]string `json:"addressPrefixes,omitempty"` + Direction *string `json:"direction,omitempty"` + FullyQualifiedDomainNames *[]string `json:"fullyQualifiedDomainNames,omitempty"` + NetworkSecurityPerimeters *[]NSPConfigNetworkSecurityPerimeterRule `json:"networkSecurityPerimeters,omitempty"` + ServiceTags *[]string `json:"serviceTags,omitempty"` + Subscriptions *[]string `json:"subscriptions,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigassociation.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigassociation.go new file mode 100644 index 00000000000..0322378c71b --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigassociation.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPConfigAssociation struct { + AccessMode *string `json:"accessMode,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go new file mode 100644 index 00000000000..c529b35b6bb --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go @@ -0,0 +1,10 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPConfigNetworkSecurityPerimeterRule struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + PerimeterGuid *string `json:"perimeterGuid,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigperimeter.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigperimeter.go new file mode 100644 index 00000000000..245acf0922b --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigperimeter.go @@ -0,0 +1,10 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPConfigPerimeter struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + PerimeterGuid *string `json:"perimeterGuid,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigprofile.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigprofile.go new file mode 100644 index 00000000000..91e4365d818 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspconfigprofile.go @@ -0,0 +1,10 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPConfigProfile struct { + AccessRules *[]NSPConfigAccessRule `json:"accessRules,omitempty"` + AccessRulesVersion *string `json:"accessRulesVersion,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissue.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissue.go new file mode 100644 index 00000000000..522a879dcd9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissue.go @@ -0,0 +1,9 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPProvisioningIssue struct { + Name *string `json:"name,omitempty"` + Properties *NSPProvisioningIssueProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go new file mode 100644 index 00000000000..9d59f8ebd6b --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go @@ -0,0 +1,12 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NSPProvisioningIssueProperties struct { + Description *string `json:"description,omitempty"` + IssueType *string `json:"issueType,omitempty"` + Severity *string `json:"severity,omitempty"` + SuggestedAccessRules *[]string `json:"suggestedAccessRules,omitempty"` + SuggestedResourceIds *[]string `json:"suggestedResourceIds,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/predicates.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/predicates.go new file mode 100644 index 00000000000..fd3dce574e9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/predicates.go @@ -0,0 +1,27 @@ +package networksecurityperimeterconfigurations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkSecurityPerimeterConfigurationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p NetworkSecurityPerimeterConfigurationOperationPredicate) Matches(input NetworkSecurityPerimeterConfiguration) 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/sql/2023-08-01/networksecurityperimeterconfigurations/version.go b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/version.go new file mode 100644 index 00000000000..6caf6b5f06b --- /dev/null +++ b/resource-manager/sql/2023-08-01/networksecurityperimeterconfigurations/version.go @@ -0,0 +1,10 @@ +package networksecurityperimeterconfigurations + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/networksecurityperimeterconfigurations/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/README.md b/resource-manager/sql/2023-08-01/outboundfirewallrules/README.md new file mode 100644 index 00000000000..d6ba2af961a --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/README.md @@ -0,0 +1,78 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/outboundfirewallrules` Documentation + +The `outboundfirewallrules` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/outboundfirewallrules" +``` + + +### Client Initialization + +```go +client := outboundfirewallrules.NewOutboundFirewallRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OutboundFirewallRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := outboundfirewallrules.NewOutboundFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "outboundFirewallRuleName") + +if err := client.CreateOrUpdateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `OutboundFirewallRulesClient.Delete` + +```go +ctx := context.TODO() +id := outboundfirewallrules.NewOutboundFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "outboundFirewallRuleName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `OutboundFirewallRulesClient.Get` + +```go +ctx := context.TODO() +id := outboundfirewallrules.NewOutboundFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "outboundFirewallRuleName") + +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: `OutboundFirewallRulesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/client.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/client.go new file mode 100644 index 00000000000..da90d0a7fa0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/client.go @@ -0,0 +1,26 @@ +package outboundfirewallrules + +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 OutboundFirewallRulesClient struct { + Client *resourcemanager.Client +} + +func NewOutboundFirewallRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*OutboundFirewallRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "outboundfirewallrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OutboundFirewallRulesClient: %+v", err) + } + + return &OutboundFirewallRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule.go new file mode 100644 index 00000000000..aab0c4f9ed0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule.go @@ -0,0 +1,139 @@ +package outboundfirewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OutboundFirewallRuleId{}) +} + +var _ resourceids.ResourceId = &OutboundFirewallRuleId{} + +// OutboundFirewallRuleId is a struct representing the Resource ID for a Outbound Firewall Rule +type OutboundFirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + OutboundFirewallRuleName string +} + +// NewOutboundFirewallRuleID returns a new OutboundFirewallRuleId struct +func NewOutboundFirewallRuleID(subscriptionId string, resourceGroupName string, serverName string, outboundFirewallRuleName string) OutboundFirewallRuleId { + return OutboundFirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + OutboundFirewallRuleName: outboundFirewallRuleName, + } +} + +// ParseOutboundFirewallRuleID parses 'input' into a OutboundFirewallRuleId +func ParseOutboundFirewallRuleID(input string) (*OutboundFirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&OutboundFirewallRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OutboundFirewallRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOutboundFirewallRuleIDInsensitively parses 'input' case-insensitively into a OutboundFirewallRuleId +// note: this method should only be used for API response data and not user input +func ParseOutboundFirewallRuleIDInsensitively(input string) (*OutboundFirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&OutboundFirewallRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OutboundFirewallRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OutboundFirewallRuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.OutboundFirewallRuleName, ok = input.Parsed["outboundFirewallRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "outboundFirewallRuleName", input) + } + + return nil +} + +// ValidateOutboundFirewallRuleID checks that 'input' can be parsed as a Outbound Firewall Rule ID +func ValidateOutboundFirewallRuleID(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 := ParseOutboundFirewallRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Outbound Firewall Rule ID +func (id OutboundFirewallRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/outboundFirewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.OutboundFirewallRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Outbound Firewall Rule ID +func (id OutboundFirewallRuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticOutboundFirewallRules", "outboundFirewallRules", "outboundFirewallRules"), + resourceids.UserSpecifiedSegment("outboundFirewallRuleName", "outboundFirewallRuleName"), + } +} + +// String returns a human-readable description of this Outbound Firewall Rule ID +func (id OutboundFirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Outbound Firewall Rule Name: %q", id.OutboundFirewallRuleName), + } + return fmt.Sprintf("Outbound Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule_test.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule_test.go new file mode 100644 index 00000000000..dd62ec95a8a --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/id_outboundfirewallrule_test.go @@ -0,0 +1,327 @@ +package outboundfirewallrules + +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 = &OutboundFirewallRuleId{} + +func TestNewOutboundFirewallRuleID(t *testing.T) { + id := NewOutboundFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "outboundFirewallRuleName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.OutboundFirewallRuleName != "outboundFirewallRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'OutboundFirewallRuleName'", id.OutboundFirewallRuleName, "outboundFirewallRuleName") + } +} + +func TestFormatOutboundFirewallRuleID(t *testing.T) { + actual := NewOutboundFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "outboundFirewallRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules/outboundFirewallRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOutboundFirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OutboundFirewallRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules/outboundFirewallRuleName", + Expected: &OutboundFirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + OutboundFirewallRuleName: "outboundFirewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules/outboundFirewallRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOutboundFirewallRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.OutboundFirewallRuleName != v.Expected.OutboundFirewallRuleName { + t.Fatalf("Expected %q but got %q for OutboundFirewallRuleName", v.Expected.OutboundFirewallRuleName, actual.OutboundFirewallRuleName) + } + + } +} + +func TestParseOutboundFirewallRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OutboundFirewallRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/oUtBoUnDfIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules/outboundFirewallRuleName", + Expected: &OutboundFirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + OutboundFirewallRuleName: "outboundFirewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/outboundFirewallRules/outboundFirewallRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/oUtBoUnDfIrEwAlLrUlEs/oUtBoUnDfIrEwAlLrUlEnAmE", + Expected: &OutboundFirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + OutboundFirewallRuleName: "oUtBoUnDfIrEwAlLrUlEnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/oUtBoUnDfIrEwAlLrUlEs/oUtBoUnDfIrEwAlLrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOutboundFirewallRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.OutboundFirewallRuleName != v.Expected.OutboundFirewallRuleName { + t.Fatalf("Expected %q but got %q for OutboundFirewallRuleName", v.Expected.OutboundFirewallRuleName, actual.OutboundFirewallRuleName) + } + + } +} + +func TestSegmentsForOutboundFirewallRuleId(t *testing.T) { + segments := OutboundFirewallRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OutboundFirewallRuleId 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/sql/2023-08-01/outboundfirewallrules/method_createorupdate.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_createorupdate.go new file mode 100644 index 00000000000..e1d895e1d09 --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_createorupdate.go @@ -0,0 +1,72 @@ +package outboundfirewallrules + +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 *OutboundFirewallRule +} + +// CreateOrUpdate ... +func (c OutboundFirewallRulesClient) CreateOrUpdate(ctx context.Context, id OutboundFirewallRuleId) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c OutboundFirewallRulesClient) CreateOrUpdateThenPoll(ctx context.Context, id OutboundFirewallRuleId) error { + result, err := c.CreateOrUpdate(ctx, id) + 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/sql/2023-08-01/outboundfirewallrules/method_delete.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_delete.go new file mode 100644 index 00000000000..898eab96d2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_delete.go @@ -0,0 +1,71 @@ +package outboundfirewallrules + +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 OutboundFirewallRulesClient) Delete(ctx context.Context, id OutboundFirewallRuleId) (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 OutboundFirewallRulesClient) DeleteThenPoll(ctx context.Context, id OutboundFirewallRuleId) 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/sql/2023-08-01/outboundfirewallrules/method_get.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_get.go new file mode 100644 index 00000000000..13c62b7ab15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_get.go @@ -0,0 +1,53 @@ +package outboundfirewallrules + +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 *OutboundFirewallRule +} + +// Get ... +func (c OutboundFirewallRulesClient) Get(ctx context.Context, id OutboundFirewallRuleId) (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 OutboundFirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/method_listbyserver.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_listbyserver.go new file mode 100644 index 00000000000..41445efebec --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/method_listbyserver.go @@ -0,0 +1,106 @@ +package outboundfirewallrules + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OutboundFirewallRule +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []OutboundFirewallRule +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c OutboundFirewallRulesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/outboundFirewallRules", 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 *[]OutboundFirewallRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c OutboundFirewallRulesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, OutboundFirewallRuleOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OutboundFirewallRulesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate OutboundFirewallRuleOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]OutboundFirewallRule, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallrule.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallrule.go new file mode 100644 index 00000000000..f1befbd713b --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallrule.go @@ -0,0 +1,11 @@ +package outboundfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundFirewallRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *OutboundFirewallRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallruleproperties.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallruleproperties.go new file mode 100644 index 00000000000..22615651f94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/model_outboundfirewallruleproperties.go @@ -0,0 +1,8 @@ +package outboundfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundFirewallRuleProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/outboundfirewallrules/predicates.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/predicates.go new file mode 100644 index 00000000000..9d87029d13c --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/predicates.go @@ -0,0 +1,27 @@ +package outboundfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundFirewallRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p OutboundFirewallRuleOperationPredicate) Matches(input OutboundFirewallRule) 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/sql/2023-08-01/outboundfirewallrules/version.go b/resource-manager/sql/2023-08-01/outboundfirewallrules/version.go new file mode 100644 index 00000000000..ad5007140ea --- /dev/null +++ b/resource-manager/sql/2023-08-01/outboundfirewallrules/version.go @@ -0,0 +1,10 @@ +package outboundfirewallrules + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/outboundfirewallrules/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/README.md b/resource-manager/sql/2023-08-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..d8428521815 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/client.go b/resource-manager/sql/2023-08-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/constants.go b/resource-manager/sql/2023-08-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..3f2dafe57d6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/constants.go @@ -0,0 +1,145 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointProvisioningState string + +const ( + PrivateEndpointProvisioningStateApproving PrivateEndpointProvisioningState = "Approving" + PrivateEndpointProvisioningStateDropping PrivateEndpointProvisioningState = "Dropping" + PrivateEndpointProvisioningStateFailed PrivateEndpointProvisioningState = "Failed" + PrivateEndpointProvisioningStateReady PrivateEndpointProvisioningState = "Ready" + PrivateEndpointProvisioningStateRejecting PrivateEndpointProvisioningState = "Rejecting" +) + +func PossibleValuesForPrivateEndpointProvisioningState() []string { + return []string{ + string(PrivateEndpointProvisioningStateApproving), + string(PrivateEndpointProvisioningStateDropping), + string(PrivateEndpointProvisioningStateFailed), + string(PrivateEndpointProvisioningStateReady), + string(PrivateEndpointProvisioningStateRejecting), + } +} + +func (s *PrivateEndpointProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointProvisioningState(input string) (*PrivateEndpointProvisioningState, error) { + vals := map[string]PrivateEndpointProvisioningState{ + "approving": PrivateEndpointProvisioningStateApproving, + "dropping": PrivateEndpointProvisioningStateDropping, + "failed": PrivateEndpointProvisioningStateFailed, + "ready": PrivateEndpointProvisioningStateReady, + "rejecting": PrivateEndpointProvisioningStateRejecting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointProvisioningState(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStateActionsRequire string + +const ( + PrivateLinkServiceConnectionStateActionsRequireNone PrivateLinkServiceConnectionStateActionsRequire = "None" +) + +func PossibleValuesForPrivateLinkServiceConnectionStateActionsRequire() []string { + return []string{ + string(PrivateLinkServiceConnectionStateActionsRequireNone), + } +} + +func (s *PrivateLinkServiceConnectionStateActionsRequire) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateLinkServiceConnectionStateActionsRequire(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateLinkServiceConnectionStateActionsRequire(input string) (*PrivateLinkServiceConnectionStateActionsRequire, error) { + vals := map[string]PrivateLinkServiceConnectionStateActionsRequire{ + "none": PrivateLinkServiceConnectionStateActionsRequireNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStateActionsRequire(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStateStatus string + +const ( + PrivateLinkServiceConnectionStateStatusApproved PrivateLinkServiceConnectionStateStatus = "Approved" + PrivateLinkServiceConnectionStateStatusDisconnected PrivateLinkServiceConnectionStateStatus = "Disconnected" + PrivateLinkServiceConnectionStateStatusPending PrivateLinkServiceConnectionStateStatus = "Pending" + PrivateLinkServiceConnectionStateStatusRejected PrivateLinkServiceConnectionStateStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStateStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStateStatusApproved), + string(PrivateLinkServiceConnectionStateStatusDisconnected), + string(PrivateLinkServiceConnectionStateStatusPending), + string(PrivateLinkServiceConnectionStateStatusRejected), + } +} + +func (s *PrivateLinkServiceConnectionStateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateLinkServiceConnectionStateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateLinkServiceConnectionStateStatus(input string) (*PrivateLinkServiceConnectionStateStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStateStatus{ + "approved": PrivateLinkServiceConnectionStateStatusApproved, + "disconnected": PrivateLinkServiceConnectionStateStatusDisconnected, + "pending": PrivateLinkServiceConnectionStateStatusPending, + "rejected": PrivateLinkServiceConnectionStateStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStateStatus(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..6a4b4977281 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, serverName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..364d8fd9145 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/method_createorupdate.go b/resource-manager/sql/2023-08-01/privateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..943007e4641 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/method_createorupdate.go @@ -0,0 +1,75 @@ +package privateendpointconnections + +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 *PrivateEndpointConnection +} + +// CreateOrUpdate ... +func (c PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) 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/sql/2023-08-01/privateendpointconnections/method_delete.go b/resource-manager/sql/2023-08-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package privateendpointconnections + +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 PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/method_get.go b/resource-manager/sql/2023-08-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..351242746d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/method_listbyserver.go b/resource-manager/sql/2023-08-01/privateendpointconnections/method_listbyserver.go new file mode 100644 index 00000000000..7d901871bf9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/method_listbyserver.go @@ -0,0 +1,106 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c PrivateEndpointConnectionsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate PrivateEndpointConnectionOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..f4006fb2af0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionStateProperty `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointproperty.go b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointproperty.go new file mode 100644 index 00000000000..b0b0ff18482 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privateendpointproperty.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..fe8f03a4364 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionStateProperty struct { + ActionsRequired *PrivateLinkServiceConnectionStateActionsRequire `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status PrivateLinkServiceConnectionStateStatus `json:"status"` +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/predicates.go b/resource-manager/sql/2023-08-01/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..4a03a91ce52 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/predicates.go @@ -0,0 +1,27 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/sql/2023-08-01/privateendpointconnections/version.go b/resource-manager/sql/2023-08-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..2ce856a87a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/README.md b/resource-manager/sql/2023-08-01/privatelinkresources/README.md new file mode 100644 index 00000000000..4dc1c312eaa --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkresources.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateLinkResourceName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/client.go b/resource-manager/sql/2023-08-01/privatelinkresources/client.go new file mode 100644 index 00000000000..28c00b21f03 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource.go b/resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource.go new file mode 100644 index 00000000000..5e1cd1e6bfe --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource.go @@ -0,0 +1,139 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateLinkResourceId{}) +} + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, serverName string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceName"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource_test.go b/resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource_test.go new file mode 100644 index 00000000000..b73a6040dd2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateLinkResourceName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.PrivateLinkResourceName != "privateLinkResourceName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceName") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "privateLinkResourceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources/privateLinkResourceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/method_get.go b/resource-manager/sql/2023-08-01/privatelinkresources/method_get.go new file mode 100644 index 00000000000..4fe26146181 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/method_get.go @@ -0,0 +1,53 @@ +package privatelinkresources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkResourcesClient) Get(ctx context.Context, id PrivateLinkResourceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/method_listbyserver.go b/resource-manager/sql/2023-08-01/privatelinkresources/method_listbyserver.go new file mode 100644 index 00000000000..a30057bb061 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/method_listbyserver.go @@ -0,0 +1,106 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c PrivateLinkResourcesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c PrivateLinkResourcesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkResourcesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate PrivateLinkResourceOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/predicates.go b/resource-manager/sql/2023-08-01/privatelinkresources/predicates.go new file mode 100644 index 00000000000..19b771c3994 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/predicates.go @@ -0,0 +1,27 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/sql/2023-08-01/privatelinkresources/version.go b/resource-manager/sql/2023-08-01/privatelinkresources/version.go new file mode 100644 index 00000000000..1b92d294a40 --- /dev/null +++ b/resource-manager/sql/2023-08-01/privatelinkresources/version.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresources/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/README.md b/resource-manager/sql/2023-08-01/recoverabledatabases/README.md new file mode 100644 index 00000000000..dee513de12f --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/recoverabledatabases` Documentation + +The `recoverabledatabases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/recoverabledatabases" +``` + + +### Client Initialization + +```go +client := recoverabledatabases.NewRecoverableDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoverableDatabasesClient.Get` + +```go +ctx := context.TODO() +id := recoverabledatabases.NewRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "recoverableDatabaseName") + +read, err := client.Get(ctx, id, recoverabledatabases.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RecoverableDatabasesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/client.go b/resource-manager/sql/2023-08-01/recoverabledatabases/client.go new file mode 100644 index 00000000000..80982a3b14c --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/client.go @@ -0,0 +1,26 @@ +package recoverabledatabases + +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 RecoverableDatabasesClient struct { + Client *resourcemanager.Client +} + +func NewRecoverableDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*RecoverableDatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "recoverabledatabases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RecoverableDatabasesClient: %+v", err) + } + + return &RecoverableDatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/constants.go b/resource-manager/sql/2023-08-01/recoverabledatabases/constants.go new file mode 100644 index 00000000000..267d325be61 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/constants.go @@ -0,0 +1,48 @@ +package recoverabledatabases + +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 DatabaseKeyType string + +const ( + DatabaseKeyTypeAzureKeyVault DatabaseKeyType = "AzureKeyVault" +) + +func PossibleValuesForDatabaseKeyType() []string { + return []string{ + string(DatabaseKeyTypeAzureKeyVault), + } +} + +func (s *DatabaseKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseKeyType(input string) (*DatabaseKeyType, error) { + vals := map[string]DatabaseKeyType{ + "azurekeyvault": DatabaseKeyTypeAzureKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase.go b/resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase.go new file mode 100644 index 00000000000..2f0603bf9d2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase.go @@ -0,0 +1,139 @@ +package recoverabledatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RecoverableDatabaseId{}) +} + +var _ resourceids.ResourceId = &RecoverableDatabaseId{} + +// RecoverableDatabaseId is a struct representing the Resource ID for a Recoverable Database +type RecoverableDatabaseId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + RecoverableDatabaseName string +} + +// NewRecoverableDatabaseID returns a new RecoverableDatabaseId struct +func NewRecoverableDatabaseID(subscriptionId string, resourceGroupName string, serverName string, recoverableDatabaseName string) RecoverableDatabaseId { + return RecoverableDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + RecoverableDatabaseName: recoverableDatabaseName, + } +} + +// ParseRecoverableDatabaseID parses 'input' into a RecoverableDatabaseId +func ParseRecoverableDatabaseID(input string) (*RecoverableDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoverableDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoverableDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecoverableDatabaseIDInsensitively parses 'input' case-insensitively into a RecoverableDatabaseId +// note: this method should only be used for API response data and not user input +func ParseRecoverableDatabaseIDInsensitively(input string) (*RecoverableDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoverableDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoverableDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecoverableDatabaseId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.RecoverableDatabaseName, ok = input.Parsed["recoverableDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recoverableDatabaseName", input) + } + + return nil +} + +// ValidateRecoverableDatabaseID checks that 'input' can be parsed as a Recoverable Database ID +func ValidateRecoverableDatabaseID(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 := ParseRecoverableDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recoverable Database ID +func (id RecoverableDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/recoverableDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.RecoverableDatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recoverable Database ID +func (id RecoverableDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticRecoverableDatabases", "recoverableDatabases", "recoverableDatabases"), + resourceids.UserSpecifiedSegment("recoverableDatabaseName", "recoverableDatabaseName"), + } +} + +// String returns a human-readable description of this Recoverable Database ID +func (id RecoverableDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Recoverable Database Name: %q", id.RecoverableDatabaseName), + } + return fmt.Sprintf("Recoverable Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase_test.go b/resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase_test.go new file mode 100644 index 00000000000..6ee7539663f --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/id_recoverabledatabase_test.go @@ -0,0 +1,327 @@ +package recoverabledatabases + +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 = &RecoverableDatabaseId{} + +func TestNewRecoverableDatabaseID(t *testing.T) { + id := NewRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "recoverableDatabaseName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.RecoverableDatabaseName != "recoverableDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'RecoverableDatabaseName'", id.RecoverableDatabaseName, "recoverableDatabaseName") + } +} + +func TestFormatRecoverableDatabaseID(t *testing.T) { + actual := NewRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "recoverableDatabaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases/recoverableDatabaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecoverableDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoverableDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases/recoverableDatabaseName", + Expected: &RecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + RecoverableDatabaseName: "recoverableDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases/recoverableDatabaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoverableDatabaseID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.RecoverableDatabaseName != v.Expected.RecoverableDatabaseName { + t.Fatalf("Expected %q but got %q for RecoverableDatabaseName", v.Expected.RecoverableDatabaseName, actual.RecoverableDatabaseName) + } + + } +} + +func TestParseRecoverableDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoverableDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/rEcOvErAbLeDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases/recoverableDatabaseName", + Expected: &RecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + RecoverableDatabaseName: "recoverableDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/recoverableDatabases/recoverableDatabaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeNaMe", + Expected: &RecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + RecoverableDatabaseName: "rEcOvErAbLeDaTaBaSeNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoverableDatabaseIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.RecoverableDatabaseName != v.Expected.RecoverableDatabaseName { + t.Fatalf("Expected %q but got %q for RecoverableDatabaseName", v.Expected.RecoverableDatabaseName, actual.RecoverableDatabaseName) + } + + } +} + +func TestSegmentsForRecoverableDatabaseId(t *testing.T) { + segments := RecoverableDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecoverableDatabaseId 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/sql/2023-08-01/recoverabledatabases/method_get.go b/resource-manager/sql/2023-08-01/recoverabledatabases/method_get.go new file mode 100644 index 00000000000..2d9eda80b4d --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/method_get.go @@ -0,0 +1,87 @@ +package recoverabledatabases + +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 *RecoverableDatabase +} + +type GetOperationOptions struct { + Expand *string + Filter *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)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// Get ... +func (c RecoverableDatabasesClient) Get(ctx context.Context, id RecoverableDatabaseId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 RecoverableDatabase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/method_listbyserver.go b/resource-manager/sql/2023-08-01/recoverabledatabases/method_listbyserver.go new file mode 100644 index 00000000000..c57293af9ea --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/method_listbyserver.go @@ -0,0 +1,106 @@ +package recoverabledatabases + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecoverableDatabase +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecoverableDatabase +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c RecoverableDatabasesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/recoverableDatabases", 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 *[]RecoverableDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c RecoverableDatabasesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, RecoverableDatabaseOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecoverableDatabasesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate RecoverableDatabaseOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]RecoverableDatabase, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/model_databasekey.go b/resource-manager/sql/2023-08-01/recoverabledatabases/model_databasekey.go new file mode 100644 index 00000000000..fc75de7ec27 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/model_databasekey.go @@ -0,0 +1,29 @@ +package recoverabledatabases + +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 DatabaseKey struct { + CreationDate *string `json:"creationDate,omitempty"` + Subregion *string `json:"subregion,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Type *DatabaseKeyType `json:"type,omitempty"` +} + +func (o *DatabaseKey) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseKey) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabase.go b/resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabase.go new file mode 100644 index 00000000000..28597f651c5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabase.go @@ -0,0 +1,11 @@ +package recoverabledatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableDatabase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoverableDatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabaseproperties.go b/resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabaseproperties.go new file mode 100644 index 00000000000..94941f9ec23 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/model_recoverabledatabaseproperties.go @@ -0,0 +1,30 @@ +package recoverabledatabases + +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 RecoverableDatabaseProperties struct { + Edition *string `json:"edition,omitempty"` + ElasticPoolName *string `json:"elasticPoolName,omitempty"` + Keys *map[string]DatabaseKey `json:"keys,omitempty"` + LastAvailableBackupDate *string `json:"lastAvailableBackupDate,omitempty"` + ServiceLevelObjective *string `json:"serviceLevelObjective,omitempty"` +} + +func (o *RecoverableDatabaseProperties) GetLastAvailableBackupDateAsTime() (*time.Time, error) { + if o.LastAvailableBackupDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastAvailableBackupDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoverableDatabaseProperties) SetLastAvailableBackupDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastAvailableBackupDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/recoverabledatabases/predicates.go b/resource-manager/sql/2023-08-01/recoverabledatabases/predicates.go new file mode 100644 index 00000000000..829eeb8ad7d --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/predicates.go @@ -0,0 +1,27 @@ +package recoverabledatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableDatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RecoverableDatabaseOperationPredicate) Matches(input RecoverableDatabase) 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/sql/2023-08-01/recoverabledatabases/version.go b/resource-manager/sql/2023-08-01/recoverabledatabases/version.go new file mode 100644 index 00000000000..b8ff6015fd6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverabledatabases/version.go @@ -0,0 +1,10 @@ +package recoverabledatabases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/recoverabledatabases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/README.md b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/README.md new file mode 100644 index 00000000000..2d5e593738d --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/recoverablemanageddatabases` Documentation + +The `recoverablemanageddatabases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/recoverablemanageddatabases" +``` + + +### Client Initialization + +```go +client := recoverablemanageddatabases.NewRecoverableManagedDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoverableManagedDatabasesClient.Get` + +```go +ctx := context.TODO() +id := recoverablemanageddatabases.NewManagedInstanceRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "recoverableDatabaseName") + +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: `RecoverableManagedDatabasesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/client.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/client.go new file mode 100644 index 00000000000..62ff80d8685 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/client.go @@ -0,0 +1,26 @@ +package recoverablemanageddatabases + +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 RecoverableManagedDatabasesClient struct { + Client *resourcemanager.Client +} + +func NewRecoverableManagedDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*RecoverableManagedDatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "recoverablemanageddatabases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RecoverableManagedDatabasesClient: %+v", err) + } + + return &RecoverableManagedDatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go new file mode 100644 index 00000000000..4a94f7c3afa --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go @@ -0,0 +1,139 @@ +package recoverablemanageddatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstanceRecoverableDatabaseId{}) +} + +var _ resourceids.ResourceId = &ManagedInstanceRecoverableDatabaseId{} + +// ManagedInstanceRecoverableDatabaseId is a struct representing the Resource ID for a Managed Instance Recoverable Database +type ManagedInstanceRecoverableDatabaseId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + RecoverableDatabaseName string +} + +// NewManagedInstanceRecoverableDatabaseID returns a new ManagedInstanceRecoverableDatabaseId struct +func NewManagedInstanceRecoverableDatabaseID(subscriptionId string, resourceGroupName string, managedInstanceName string, recoverableDatabaseName string) ManagedInstanceRecoverableDatabaseId { + return ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + RecoverableDatabaseName: recoverableDatabaseName, + } +} + +// ParseManagedInstanceRecoverableDatabaseID parses 'input' into a ManagedInstanceRecoverableDatabaseId +func ParseManagedInstanceRecoverableDatabaseID(input string) (*ManagedInstanceRecoverableDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceRecoverableDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceRecoverableDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstanceRecoverableDatabaseIDInsensitively parses 'input' case-insensitively into a ManagedInstanceRecoverableDatabaseId +// note: this method should only be used for API response data and not user input +func ParseManagedInstanceRecoverableDatabaseIDInsensitively(input string) (*ManagedInstanceRecoverableDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceRecoverableDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceRecoverableDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstanceRecoverableDatabaseId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.RecoverableDatabaseName, ok = input.Parsed["recoverableDatabaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recoverableDatabaseName", input) + } + + return nil +} + +// ValidateManagedInstanceRecoverableDatabaseID checks that 'input' can be parsed as a Managed Instance Recoverable Database ID +func ValidateManagedInstanceRecoverableDatabaseID(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 := ParseManagedInstanceRecoverableDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Recoverable Database ID +func (id ManagedInstanceRecoverableDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/recoverableDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.RecoverableDatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Recoverable Database ID +func (id ManagedInstanceRecoverableDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticRecoverableDatabases", "recoverableDatabases", "recoverableDatabases"), + resourceids.UserSpecifiedSegment("recoverableDatabaseName", "recoverableDatabaseName"), + } +} + +// String returns a human-readable description of this Managed Instance Recoverable Database ID +func (id ManagedInstanceRecoverableDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Recoverable Database Name: %q", id.RecoverableDatabaseName), + } + return fmt.Sprintf("Managed Instance Recoverable Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go new file mode 100644 index 00000000000..a8be34ee829 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go @@ -0,0 +1,327 @@ +package recoverablemanageddatabases + +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 = &ManagedInstanceRecoverableDatabaseId{} + +func TestNewManagedInstanceRecoverableDatabaseID(t *testing.T) { + id := NewManagedInstanceRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "recoverableDatabaseName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.RecoverableDatabaseName != "recoverableDatabaseName" { + t.Fatalf("Expected %q but got %q for Segment 'RecoverableDatabaseName'", id.RecoverableDatabaseName, "recoverableDatabaseName") + } +} + +func TestFormatManagedInstanceRecoverableDatabaseID(t *testing.T) { + actual := NewManagedInstanceRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "recoverableDatabaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases/recoverableDatabaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstanceRecoverableDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceRecoverableDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases/recoverableDatabaseName", + Expected: &ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + RecoverableDatabaseName: "recoverableDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases/recoverableDatabaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceRecoverableDatabaseID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.RecoverableDatabaseName != v.Expected.RecoverableDatabaseName { + t.Fatalf("Expected %q but got %q for RecoverableDatabaseName", v.Expected.RecoverableDatabaseName, actual.RecoverableDatabaseName) + } + + } +} + +func TestParseManagedInstanceRecoverableDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceRecoverableDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEcOvErAbLeDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases/recoverableDatabaseName", + Expected: &ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + RecoverableDatabaseName: "recoverableDatabaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/recoverableDatabases/recoverableDatabaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeNaMe", + Expected: &ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + RecoverableDatabaseName: "rEcOvErAbLeDaTaBaSeNaMe", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceRecoverableDatabaseIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.RecoverableDatabaseName != v.Expected.RecoverableDatabaseName { + t.Fatalf("Expected %q but got %q for RecoverableDatabaseName", v.Expected.RecoverableDatabaseName, actual.RecoverableDatabaseName) + } + + } +} + +func TestSegmentsForManagedInstanceRecoverableDatabaseId(t *testing.T) { + segments := ManagedInstanceRecoverableDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstanceRecoverableDatabaseId 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/sql/2023-08-01/recoverablemanageddatabases/method_get.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_get.go new file mode 100644 index 00000000000..4a358c3509a --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_get.go @@ -0,0 +1,53 @@ +package recoverablemanageddatabases + +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 *RecoverableManagedDatabase +} + +// Get ... +func (c RecoverableManagedDatabasesClient) Get(ctx context.Context, id ManagedInstanceRecoverableDatabaseId) (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 RecoverableManagedDatabase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_listbyinstance.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_listbyinstance.go new file mode 100644 index 00000000000..57dd01f6bf9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/method_listbyinstance.go @@ -0,0 +1,106 @@ +package recoverablemanageddatabases + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecoverableManagedDatabase +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecoverableManagedDatabase +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c RecoverableManagedDatabasesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/recoverableDatabases", 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 *[]RecoverableManagedDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c RecoverableManagedDatabasesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, RecoverableManagedDatabaseOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecoverableManagedDatabasesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate RecoverableManagedDatabaseOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]RecoverableManagedDatabase, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabase.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabase.go new file mode 100644 index 00000000000..ea9c6fcfdc4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabase.go @@ -0,0 +1,11 @@ +package recoverablemanageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableManagedDatabase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoverableManagedDatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go new file mode 100644 index 00000000000..85695723462 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go @@ -0,0 +1,8 @@ +package recoverablemanageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableManagedDatabaseProperties struct { + LastAvailableBackupDate *string `json:"lastAvailableBackupDate,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/recoverablemanageddatabases/predicates.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/predicates.go new file mode 100644 index 00000000000..e7c04e344c3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/predicates.go @@ -0,0 +1,27 @@ +package recoverablemanageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableManagedDatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RecoverableManagedDatabaseOperationPredicate) Matches(input RecoverableManagedDatabase) 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/sql/2023-08-01/recoverablemanageddatabases/version.go b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/version.go new file mode 100644 index 00000000000..f0f1e7cff92 --- /dev/null +++ b/resource-manager/sql/2023-08-01/recoverablemanageddatabases/version.go @@ -0,0 +1,10 @@ +package recoverablemanageddatabases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/recoverablemanageddatabases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/README.md b/resource-manager/sql/2023-08-01/replicationlinks/README.md new file mode 100644 index 00000000000..0e6646703f1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/README.md @@ -0,0 +1,141 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/replicationlinks` Documentation + +The `replicationlinks` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/replicationlinks" +``` + + +### Client Initialization + +```go +client := replicationlinks.NewReplicationLinksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationLinksClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := replicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + +payload := replicationlinks.ReplicationLink{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationLinksClient.Delete` + +```go +ctx := context.TODO() +id := replicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationLinksClient.Failover` + +```go +ctx := context.TODO() +id := replicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + +if err := client.FailoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationLinksClient.FailoverAllowDataLoss` + +```go +ctx := context.TODO() +id := replicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + +if err := client.FailoverAllowDataLossThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationLinksClient.Get` + +```go +ctx := context.TODO() +id := replicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + +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: `ReplicationLinksClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationLinksClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationLinksClient.Update` + +```go +ctx := context.TODO() +id := replicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + +payload := replicationlinks.ReplicationLinkUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/replicationlinks/client.go b/resource-manager/sql/2023-08-01/replicationlinks/client.go new file mode 100644 index 00000000000..3b6d95b1729 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/client.go @@ -0,0 +1,26 @@ +package replicationlinks + +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 ReplicationLinksClient struct { + Client *resourcemanager.Client +} + +func NewReplicationLinksClientWithBaseURI(sdkApi sdkEnv.Api) (*ReplicationLinksClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "replicationlinks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ReplicationLinksClient: %+v", err) + } + + return &ReplicationLinksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/constants.go b/resource-manager/sql/2023-08-01/replicationlinks/constants.go new file mode 100644 index 00000000000..c05bcf02bd6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/constants.go @@ -0,0 +1,151 @@ +package replicationlinks + +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 ReplicationLinkType string + +const ( + ReplicationLinkTypeGEO ReplicationLinkType = "GEO" + ReplicationLinkTypeNAMED ReplicationLinkType = "NAMED" + ReplicationLinkTypeSTANDBY ReplicationLinkType = "STANDBY" +) + +func PossibleValuesForReplicationLinkType() []string { + return []string{ + string(ReplicationLinkTypeGEO), + string(ReplicationLinkTypeNAMED), + string(ReplicationLinkTypeSTANDBY), + } +} + +func (s *ReplicationLinkType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationLinkType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationLinkType(input string) (*ReplicationLinkType, error) { + vals := map[string]ReplicationLinkType{ + "geo": ReplicationLinkTypeGEO, + "named": ReplicationLinkTypeNAMED, + "standby": ReplicationLinkTypeSTANDBY, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationLinkType(input) + return &out, nil +} + +type ReplicationRole string + +const ( + ReplicationRoleCopy ReplicationRole = "Copy" + ReplicationRoleNonReadableSecondary ReplicationRole = "NonReadableSecondary" + ReplicationRolePrimary ReplicationRole = "Primary" + ReplicationRoleSecondary ReplicationRole = "Secondary" + ReplicationRoleSource ReplicationRole = "Source" +) + +func PossibleValuesForReplicationRole() []string { + return []string{ + string(ReplicationRoleCopy), + string(ReplicationRoleNonReadableSecondary), + string(ReplicationRolePrimary), + string(ReplicationRoleSecondary), + string(ReplicationRoleSource), + } +} + +func (s *ReplicationRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationRole(input string) (*ReplicationRole, error) { + vals := map[string]ReplicationRole{ + "copy": ReplicationRoleCopy, + "nonreadablesecondary": ReplicationRoleNonReadableSecondary, + "primary": ReplicationRolePrimary, + "secondary": ReplicationRoleSecondary, + "source": ReplicationRoleSource, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationRole(input) + return &out, nil +} + +type ReplicationState string + +const ( + ReplicationStateCATCHUP ReplicationState = "CATCH_UP" + ReplicationStatePENDING ReplicationState = "PENDING" + ReplicationStateSEEDING ReplicationState = "SEEDING" + ReplicationStateSUSPENDED ReplicationState = "SUSPENDED" +) + +func PossibleValuesForReplicationState() []string { + return []string{ + string(ReplicationStateCATCHUP), + string(ReplicationStatePENDING), + string(ReplicationStateSEEDING), + string(ReplicationStateSUSPENDED), + } +} + +func (s *ReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationState(input string) (*ReplicationState, error) { + vals := map[string]ReplicationState{ + "catch_up": ReplicationStateCATCHUP, + "pending": ReplicationStatePENDING, + "seeding": ReplicationStateSEEDING, + "suspended": ReplicationStateSUSPENDED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink.go b/resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink.go new file mode 100644 index 00000000000..d9069de6613 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink.go @@ -0,0 +1,148 @@ +package replicationlinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ReplicationLinkId{}) +} + +var _ resourceids.ResourceId = &ReplicationLinkId{} + +// ReplicationLinkId is a struct representing the Resource ID for a Replication Link +type ReplicationLinkId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + LinkId string +} + +// NewReplicationLinkID returns a new ReplicationLinkId struct +func NewReplicationLinkID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, linkId string) ReplicationLinkId { + return ReplicationLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + LinkId: linkId, + } +} + +// ParseReplicationLinkID parses 'input' into a ReplicationLinkId +func ParseReplicationLinkID(input string) (*ReplicationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicationLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicationLinkId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReplicationLinkIDInsensitively parses 'input' case-insensitively into a ReplicationLinkId +// note: this method should only be used for API response data and not user input +func ParseReplicationLinkIDInsensitively(input string) (*ReplicationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicationLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicationLinkId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReplicationLinkId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.LinkId, ok = input.Parsed["linkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "linkId", input) + } + + return nil +} + +// ValidateReplicationLinkID checks that 'input' can be parsed as a Replication Link ID +func ValidateReplicationLinkID(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 := ParseReplicationLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Link ID +func (id ReplicationLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/replicationLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.LinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Link ID +func (id ReplicationLinkId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticReplicationLinks", "replicationLinks", "replicationLinks"), + resourceids.UserSpecifiedSegment("linkId", "linkId"), + } +} + +// String returns a human-readable description of this Replication Link ID +func (id ReplicationLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Link: %q", id.LinkId), + } + return fmt.Sprintf("Replication Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink_test.go b/resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink_test.go new file mode 100644 index 00000000000..d8cf5fbc774 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/id_replicationlink_test.go @@ -0,0 +1,372 @@ +package replicationlinks + +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 = &ReplicationLinkId{} + +func TestNewReplicationLinkID(t *testing.T) { + id := NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.LinkId != "linkId" { + t.Fatalf("Expected %q but got %q for Segment 'LinkId'", id.LinkId, "linkId") + } +} + +func TestFormatReplicationLinkID(t *testing.T) { + actual := NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "linkId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks/linkId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationLinkId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks/linkId", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + LinkId: "linkId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks/linkId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationLinkID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.LinkId != v.Expected.LinkId { + t.Fatalf("Expected %q but got %q for LinkId", v.Expected.LinkId, actual.LinkId) + } + + } +} + +func TestParseReplicationLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationLinkId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/rEpLiCaTiOnLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks/linkId", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + LinkId: "linkId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/replicationLinks/linkId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/rEpLiCaTiOnLiNkS/lInKiD", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + LinkId: "lInKiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/rEpLiCaTiOnLiNkS/lInKiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationLinkIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.LinkId != v.Expected.LinkId { + t.Fatalf("Expected %q but got %q for LinkId", v.Expected.LinkId, actual.LinkId) + } + + } +} + +func TestSegmentsForReplicationLinkId(t *testing.T) { + segments := ReplicationLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationLinkId 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/sql/2023-08-01/replicationlinks/method_createorupdate.go b/resource-manager/sql/2023-08-01/replicationlinks/method_createorupdate.go new file mode 100644 index 00000000000..b24ffacde87 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_createorupdate.go @@ -0,0 +1,75 @@ +package replicationlinks + +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 *ReplicationLink +} + +// CreateOrUpdate ... +func (c ReplicationLinksClient) CreateOrUpdate(ctx context.Context, id ReplicationLinkId, input ReplicationLink) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ReplicationLinksClient) CreateOrUpdateThenPoll(ctx context.Context, id ReplicationLinkId, input ReplicationLink) 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/sql/2023-08-01/replicationlinks/method_delete.go b/resource-manager/sql/2023-08-01/replicationlinks/method_delete.go new file mode 100644 index 00000000000..b5e55aaaecd --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_delete.go @@ -0,0 +1,70 @@ +package replicationlinks + +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 ReplicationLinksClient) Delete(ctx context.Context, id ReplicationLinkId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ReplicationLinksClient) DeleteThenPoll(ctx context.Context, id ReplicationLinkId) 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/sql/2023-08-01/replicationlinks/method_failover.go b/resource-manager/sql/2023-08-01/replicationlinks/method_failover.go new file mode 100644 index 00000000000..5bc22978e9a --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_failover.go @@ -0,0 +1,71 @@ +package replicationlinks + +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 FailoverOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ReplicationLink +} + +// Failover ... +func (c ReplicationLinksClient) Failover(ctx context.Context, id ReplicationLinkId) (result FailoverOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/failover", 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 +} + +// FailoverThenPoll performs Failover then polls until it's completed +func (c ReplicationLinksClient) FailoverThenPoll(ctx context.Context, id ReplicationLinkId) error { + result, err := c.Failover(ctx, id) + if err != nil { + return fmt.Errorf("performing Failover: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Failover: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/method_failoverallowdataloss.go b/resource-manager/sql/2023-08-01/replicationlinks/method_failoverallowdataloss.go new file mode 100644 index 00000000000..0e7cb662c79 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_failoverallowdataloss.go @@ -0,0 +1,71 @@ +package replicationlinks + +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 FailoverAllowDataLossOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ReplicationLink +} + +// FailoverAllowDataLoss ... +func (c ReplicationLinksClient) FailoverAllowDataLoss(ctx context.Context, id ReplicationLinkId) (result FailoverAllowDataLossOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceFailoverAllowDataLoss", 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 +} + +// FailoverAllowDataLossThenPoll performs FailoverAllowDataLoss then polls until it's completed +func (c ReplicationLinksClient) FailoverAllowDataLossThenPoll(ctx context.Context, id ReplicationLinkId) error { + result, err := c.FailoverAllowDataLoss(ctx, id) + if err != nil { + return fmt.Errorf("performing FailoverAllowDataLoss: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after FailoverAllowDataLoss: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/method_get.go b/resource-manager/sql/2023-08-01/replicationlinks/method_get.go new file mode 100644 index 00000000000..640a612f108 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_get.go @@ -0,0 +1,53 @@ +package replicationlinks + +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 *ReplicationLink +} + +// Get ... +func (c ReplicationLinksClient) Get(ctx context.Context, id ReplicationLinkId) (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 ReplicationLink + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/method_listbydatabase.go b/resource-manager/sql/2023-08-01/replicationlinks/method_listbydatabase.go new file mode 100644 index 00000000000..d822c28ded5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_listbydatabase.go @@ -0,0 +1,106 @@ +package replicationlinks + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReplicationLink +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReplicationLink +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c ReplicationLinksClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/replicationLinks", 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 *[]ReplicationLink `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c ReplicationLinksClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, ReplicationLinkOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReplicationLinksClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate ReplicationLinkOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]ReplicationLink, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/method_listbyserver.go b/resource-manager/sql/2023-08-01/replicationlinks/method_listbyserver.go new file mode 100644 index 00000000000..4c0dc194d25 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_listbyserver.go @@ -0,0 +1,106 @@ +package replicationlinks + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReplicationLink +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReplicationLink +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ReplicationLinksClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/replicationLinks", 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 *[]ReplicationLink `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ReplicationLinksClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ReplicationLinkOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReplicationLinksClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ReplicationLinkOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ReplicationLink, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/method_update.go b/resource-manager/sql/2023-08-01/replicationlinks/method_update.go new file mode 100644 index 00000000000..bafe58d3ae5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/method_update.go @@ -0,0 +1,75 @@ +package replicationlinks + +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 *ReplicationLink +} + +// Update ... +func (c ReplicationLinksClient) Update(ctx context.Context, id ReplicationLinkId, input ReplicationLinkUpdate) (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 ReplicationLinksClient) UpdateThenPoll(ctx context.Context, id ReplicationLinkId, input ReplicationLinkUpdate) 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/sql/2023-08-01/replicationlinks/model_replicationlink.go b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlink.go new file mode 100644 index 00000000000..c2212644298 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlink.go @@ -0,0 +1,11 @@ +package replicationlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLink struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicationLinkProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkproperties.go b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkproperties.go new file mode 100644 index 00000000000..5d2f0decd2f --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkproperties.go @@ -0,0 +1,37 @@ +package replicationlinks + +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 ReplicationLinkProperties struct { + IsTerminationAllowed *bool `json:"isTerminationAllowed,omitempty"` + LinkType *ReplicationLinkType `json:"linkType,omitempty"` + PartnerDatabase *string `json:"partnerDatabase,omitempty"` + PartnerDatabaseId *string `json:"partnerDatabaseId,omitempty"` + PartnerLocation *string `json:"partnerLocation,omitempty"` + PartnerRole *ReplicationRole `json:"partnerRole,omitempty"` + PartnerServer *string `json:"partnerServer,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + ReplicationMode *string `json:"replicationMode,omitempty"` + ReplicationState *ReplicationState `json:"replicationState,omitempty"` + Role *ReplicationRole `json:"role,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *ReplicationLinkProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicationLinkProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdate.go b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdate.go new file mode 100644 index 00000000000..c7a8d228e45 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdate.go @@ -0,0 +1,11 @@ +package replicationlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLinkUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicationLinkUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdateproperties.go b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdateproperties.go new file mode 100644 index 00000000000..3ecdf96347f --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/model_replicationlinkupdateproperties.go @@ -0,0 +1,8 @@ +package replicationlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLinkUpdateProperties struct { + LinkType *ReplicationLinkType `json:"linkType,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/replicationlinks/predicates.go b/resource-manager/sql/2023-08-01/replicationlinks/predicates.go new file mode 100644 index 00000000000..d148d45bd2b --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/predicates.go @@ -0,0 +1,27 @@ +package replicationlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLinkOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ReplicationLinkOperationPredicate) Matches(input ReplicationLink) 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/sql/2023-08-01/replicationlinks/version.go b/resource-manager/sql/2023-08-01/replicationlinks/version.go new file mode 100644 index 00000000000..aaae8bc45f9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/replicationlinks/version.go @@ -0,0 +1,10 @@ +package replicationlinks + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/replicationlinks/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/README.md b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/README.md new file mode 100644 index 00000000000..30316aa2fda --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorabledroppeddatabases` Documentation + +The `restorabledroppeddatabases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorabledroppeddatabases" +``` + + +### Client Initialization + +```go +client := restorabledroppeddatabases.NewRestorableDroppedDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RestorableDroppedDatabasesClient.Get` + +```go +ctx := context.TODO() +id := restorabledroppeddatabases.NewRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "restorableDroppedDatabaseId") + +read, err := client.Get(ctx, id, restorabledroppeddatabases.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RestorableDroppedDatabasesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/client.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/client.go new file mode 100644 index 00000000000..b005e027e5e --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/client.go @@ -0,0 +1,26 @@ +package restorabledroppeddatabases + +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 RestorableDroppedDatabasesClient struct { + Client *resourcemanager.Client +} + +func NewRestorableDroppedDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*RestorableDroppedDatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "restorabledroppeddatabases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RestorableDroppedDatabasesClient: %+v", err) + } + + return &RestorableDroppedDatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/constants.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/constants.go new file mode 100644 index 00000000000..63c43392891 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/constants.go @@ -0,0 +1,95 @@ +package restorabledroppeddatabases + +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 BackupStorageRedundancy string + +const ( + BackupStorageRedundancyGeo BackupStorageRedundancy = "Geo" + BackupStorageRedundancyGeoZone BackupStorageRedundancy = "GeoZone" + BackupStorageRedundancyLocal BackupStorageRedundancy = "Local" + BackupStorageRedundancyZone BackupStorageRedundancy = "Zone" +) + +func PossibleValuesForBackupStorageRedundancy() []string { + return []string{ + string(BackupStorageRedundancyGeo), + string(BackupStorageRedundancyGeoZone), + string(BackupStorageRedundancyLocal), + string(BackupStorageRedundancyZone), + } +} + +func (s *BackupStorageRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupStorageRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBackupStorageRedundancy(input string) (*BackupStorageRedundancy, error) { + vals := map[string]BackupStorageRedundancy{ + "geo": BackupStorageRedundancyGeo, + "geozone": BackupStorageRedundancyGeoZone, + "local": BackupStorageRedundancyLocal, + "zone": BackupStorageRedundancyZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BackupStorageRedundancy(input) + return &out, nil +} + +type DatabaseKeyType string + +const ( + DatabaseKeyTypeAzureKeyVault DatabaseKeyType = "AzureKeyVault" +) + +func PossibleValuesForDatabaseKeyType() []string { + return []string{ + string(DatabaseKeyTypeAzureKeyVault), + } +} + +func (s *DatabaseKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDatabaseKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDatabaseKeyType(input string) (*DatabaseKeyType, error) { + vals := map[string]DatabaseKeyType{ + "azurekeyvault": DatabaseKeyTypeAzureKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DatabaseKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase.go new file mode 100644 index 00000000000..c4e2c1a3e75 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase.go @@ -0,0 +1,139 @@ +package restorabledroppeddatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RestorableDroppedDatabaseId{}) +} + +var _ resourceids.ResourceId = &RestorableDroppedDatabaseId{} + +// RestorableDroppedDatabaseId is a struct representing the Resource ID for a Restorable Dropped Database +type RestorableDroppedDatabaseId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + RestorableDroppedDatabaseId string +} + +// NewRestorableDroppedDatabaseID returns a new RestorableDroppedDatabaseId struct +func NewRestorableDroppedDatabaseID(subscriptionId string, resourceGroupName string, serverName string, restorableDroppedDatabaseId string) RestorableDroppedDatabaseId { + return RestorableDroppedDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + RestorableDroppedDatabaseId: restorableDroppedDatabaseId, + } +} + +// ParseRestorableDroppedDatabaseID parses 'input' into a RestorableDroppedDatabaseId +func ParseRestorableDroppedDatabaseID(input string) (*RestorableDroppedDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorableDroppedDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorableDroppedDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRestorableDroppedDatabaseIDInsensitively parses 'input' case-insensitively into a RestorableDroppedDatabaseId +// note: this method should only be used for API response data and not user input +func ParseRestorableDroppedDatabaseIDInsensitively(input string) (*RestorableDroppedDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorableDroppedDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorableDroppedDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RestorableDroppedDatabaseId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.RestorableDroppedDatabaseId, ok = input.Parsed["restorableDroppedDatabaseId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "restorableDroppedDatabaseId", input) + } + + return nil +} + +// ValidateRestorableDroppedDatabaseID checks that 'input' can be parsed as a Restorable Dropped Database ID +func ValidateRestorableDroppedDatabaseID(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 := ParseRestorableDroppedDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Restorable Dropped Database ID +func (id RestorableDroppedDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/restorableDroppedDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.RestorableDroppedDatabaseId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Restorable Dropped Database ID +func (id RestorableDroppedDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticRestorableDroppedDatabases", "restorableDroppedDatabases", "restorableDroppedDatabases"), + resourceids.UserSpecifiedSegment("restorableDroppedDatabaseId", "restorableDroppedDatabaseId"), + } +} + +// String returns a human-readable description of this Restorable Dropped Database ID +func (id RestorableDroppedDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Restorable Dropped Database: %q", id.RestorableDroppedDatabaseId), + } + return fmt.Sprintf("Restorable Dropped Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go new file mode 100644 index 00000000000..497b87a2082 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go @@ -0,0 +1,327 @@ +package restorabledroppeddatabases + +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 = &RestorableDroppedDatabaseId{} + +func TestNewRestorableDroppedDatabaseID(t *testing.T) { + id := NewRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "restorableDroppedDatabaseId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.RestorableDroppedDatabaseId != "restorableDroppedDatabaseId" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedDatabaseId'", id.RestorableDroppedDatabaseId, "restorableDroppedDatabaseId") + } +} + +func TestFormatRestorableDroppedDatabaseID(t *testing.T) { + actual := NewRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "restorableDroppedDatabaseId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases/restorableDroppedDatabaseId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRestorableDroppedDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorableDroppedDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases/restorableDroppedDatabaseId", + Expected: &RestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases/restorableDroppedDatabaseId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorableDroppedDatabaseID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.RestorableDroppedDatabaseId != v.Expected.RestorableDroppedDatabaseId { + t.Fatalf("Expected %q but got %q for RestorableDroppedDatabaseId", v.Expected.RestorableDroppedDatabaseId, actual.RestorableDroppedDatabaseId) + } + + } +} + +func TestParseRestorableDroppedDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorableDroppedDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/rEsToRaBlEdRoPpEdDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases/restorableDroppedDatabaseId", + Expected: &RestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/restorableDroppedDatabases/restorableDroppedDatabaseId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeId", + Expected: &RestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + RestorableDroppedDatabaseId: "rEsToRaBlEdRoPpEdDaTaBaSeId", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorableDroppedDatabaseIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.RestorableDroppedDatabaseId != v.Expected.RestorableDroppedDatabaseId { + t.Fatalf("Expected %q but got %q for RestorableDroppedDatabaseId", v.Expected.RestorableDroppedDatabaseId, actual.RestorableDroppedDatabaseId) + } + + } +} + +func TestSegmentsForRestorableDroppedDatabaseId(t *testing.T) { + segments := RestorableDroppedDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RestorableDroppedDatabaseId 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/sql/2023-08-01/restorabledroppeddatabases/method_get.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_get.go new file mode 100644 index 00000000000..7327393e747 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_get.go @@ -0,0 +1,87 @@ +package restorabledroppeddatabases + +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 *RestorableDroppedDatabase +} + +type GetOperationOptions struct { + Expand *string + Filter *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)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// Get ... +func (c RestorableDroppedDatabasesClient) Get(ctx context.Context, id RestorableDroppedDatabaseId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 RestorableDroppedDatabase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_listbyserver.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_listbyserver.go new file mode 100644 index 00000000000..7c4fae2734b --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/method_listbyserver.go @@ -0,0 +1,106 @@ +package restorabledroppeddatabases + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RestorableDroppedDatabase +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []RestorableDroppedDatabase +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c RestorableDroppedDatabasesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/restorableDroppedDatabases", 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 *[]RestorableDroppedDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c RestorableDroppedDatabasesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, RestorableDroppedDatabaseOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RestorableDroppedDatabasesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate RestorableDroppedDatabaseOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]RestorableDroppedDatabase, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_databasekey.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_databasekey.go new file mode 100644 index 00000000000..7e7c7b8618f --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_databasekey.go @@ -0,0 +1,29 @@ +package restorabledroppeddatabases + +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 DatabaseKey struct { + CreationDate *string `json:"creationDate,omitempty"` + Subregion *string `json:"subregion,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Type *DatabaseKeyType `json:"type,omitempty"` +} + +func (o *DatabaseKey) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatabaseKey) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabase.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabase.go new file mode 100644 index 00000000000..4b1875917bd --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabase.go @@ -0,0 +1,14 @@ +package restorabledroppeddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedDatabase struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RestorableDroppedDatabaseProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go new file mode 100644 index 00000000000..ddf85481b60 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go @@ -0,0 +1,56 @@ +package restorabledroppeddatabases + +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 RestorableDroppedDatabaseProperties struct { + BackupStorageRedundancy *BackupStorageRedundancy `json:"backupStorageRedundancy,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + DeletionDate *string `json:"deletionDate,omitempty"` + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + Keys *map[string]DatabaseKey `json:"keys,omitempty"` + MaxSizeBytes *int64 `json:"maxSizeBytes,omitempty"` +} + +func (o *RestorableDroppedDatabaseProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedDatabaseProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *RestorableDroppedDatabaseProperties) GetDeletionDateAsTime() (*time.Time, error) { + if o.DeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedDatabaseProperties) SetDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionDate = &formatted +} + +func (o *RestorableDroppedDatabaseProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedDatabaseProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_sku.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_sku.go new file mode 100644 index 00000000000..26243c65823 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/model_sku.go @@ -0,0 +1,12 @@ +package restorabledroppeddatabases + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppeddatabases/predicates.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/predicates.go new file mode 100644 index 00000000000..539816771bc --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/predicates.go @@ -0,0 +1,32 @@ +package restorabledroppeddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedDatabaseOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RestorableDroppedDatabaseOperationPredicate) Matches(input RestorableDroppedDatabase) 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/sql/2023-08-01/restorabledroppeddatabases/version.go b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/version.go new file mode 100644 index 00000000000..51026a4522b --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppeddatabases/version.go @@ -0,0 +1,10 @@ +package restorabledroppeddatabases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/restorabledroppeddatabases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/README.md b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/README.md new file mode 100644 index 00000000000..3fead739573 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases` Documentation + +The `restorabledroppedmanageddatabases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases" +``` + + +### Client Initialization + +```go +client := restorabledroppedmanageddatabases.NewRestorableDroppedManagedDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RestorableDroppedManagedDatabasesClient.Get` + +```go +ctx := context.TODO() +id := restorabledroppedmanageddatabases.NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + +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: `RestorableDroppedManagedDatabasesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/client.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/client.go new file mode 100644 index 00000000000..3e9c9bd3617 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/client.go @@ -0,0 +1,26 @@ +package restorabledroppedmanageddatabases + +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 RestorableDroppedManagedDatabasesClient struct { + Client *resourcemanager.Client +} + +func NewRestorableDroppedManagedDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*RestorableDroppedManagedDatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "restorabledroppedmanageddatabases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RestorableDroppedManagedDatabasesClient: %+v", err) + } + + return &RestorableDroppedManagedDatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go new file mode 100644 index 00000000000..ce006387f8d --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go @@ -0,0 +1,139 @@ +package restorabledroppedmanageddatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ManagedInstanceRestorableDroppedDatabaseId{}) +} + +var _ resourceids.ResourceId = &ManagedInstanceRestorableDroppedDatabaseId{} + +// ManagedInstanceRestorableDroppedDatabaseId is a struct representing the Resource ID for a Managed Instance Restorable Dropped Database +type ManagedInstanceRestorableDroppedDatabaseId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + RestorableDroppedDatabaseId string +} + +// NewManagedInstanceRestorableDroppedDatabaseID returns a new ManagedInstanceRestorableDroppedDatabaseId struct +func NewManagedInstanceRestorableDroppedDatabaseID(subscriptionId string, resourceGroupName string, managedInstanceName string, restorableDroppedDatabaseId string) ManagedInstanceRestorableDroppedDatabaseId { + return ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + RestorableDroppedDatabaseId: restorableDroppedDatabaseId, + } +} + +// ParseManagedInstanceRestorableDroppedDatabaseID parses 'input' into a ManagedInstanceRestorableDroppedDatabaseId +func ParseManagedInstanceRestorableDroppedDatabaseID(input string) (*ManagedInstanceRestorableDroppedDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceRestorableDroppedDatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceRestorableDroppedDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseManagedInstanceRestorableDroppedDatabaseIDInsensitively parses 'input' case-insensitively into a ManagedInstanceRestorableDroppedDatabaseId +// note: this method should only be used for API response data and not user input +func ParseManagedInstanceRestorableDroppedDatabaseIDInsensitively(input string) (*ManagedInstanceRestorableDroppedDatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&ManagedInstanceRestorableDroppedDatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ManagedInstanceRestorableDroppedDatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ManagedInstanceRestorableDroppedDatabaseId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.RestorableDroppedDatabaseId, ok = input.Parsed["restorableDroppedDatabaseId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "restorableDroppedDatabaseId", input) + } + + return nil +} + +// ValidateManagedInstanceRestorableDroppedDatabaseID checks that 'input' can be parsed as a Managed Instance Restorable Dropped Database ID +func ValidateManagedInstanceRestorableDroppedDatabaseID(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 := ParseManagedInstanceRestorableDroppedDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Managed Instance Restorable Dropped Database ID +func (id ManagedInstanceRestorableDroppedDatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/restorableDroppedDatabases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.RestorableDroppedDatabaseId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Managed Instance Restorable Dropped Database ID +func (id ManagedInstanceRestorableDroppedDatabaseId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticRestorableDroppedDatabases", "restorableDroppedDatabases", "restorableDroppedDatabases"), + resourceids.UserSpecifiedSegment("restorableDroppedDatabaseId", "restorableDroppedDatabaseId"), + } +} + +// String returns a human-readable description of this Managed Instance Restorable Dropped Database ID +func (id ManagedInstanceRestorableDroppedDatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Restorable Dropped Database: %q", id.RestorableDroppedDatabaseId), + } + return fmt.Sprintf("Managed Instance Restorable Dropped Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go new file mode 100644 index 00000000000..63ad778b030 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go @@ -0,0 +1,327 @@ +package restorabledroppedmanageddatabases + +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 = &ManagedInstanceRestorableDroppedDatabaseId{} + +func TestNewManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + id := NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.RestorableDroppedDatabaseId != "restorableDroppedDatabaseId" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedDatabaseId'", id.RestorableDroppedDatabaseId, "restorableDroppedDatabaseId") + } +} + +func TestFormatManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + actual := NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "restorableDroppedDatabaseId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceRestorableDroppedDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceRestorableDroppedDatabaseID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.RestorableDroppedDatabaseId != v.Expected.RestorableDroppedDatabaseId { + t.Fatalf("Expected %q but got %q for RestorableDroppedDatabaseId", v.Expected.RestorableDroppedDatabaseId, actual.RestorableDroppedDatabaseId) + } + + } +} + +func TestParseManagedInstanceRestorableDroppedDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ManagedInstanceRestorableDroppedDatabaseId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEsToRaBlEdRoPpEdDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/restorableDroppedDatabases/restorableDroppedDatabaseId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeId", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + RestorableDroppedDatabaseId: "rEsToRaBlEdRoPpEdDaTaBaSeId", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseManagedInstanceRestorableDroppedDatabaseIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.RestorableDroppedDatabaseId != v.Expected.RestorableDroppedDatabaseId { + t.Fatalf("Expected %q but got %q for RestorableDroppedDatabaseId", v.Expected.RestorableDroppedDatabaseId, actual.RestorableDroppedDatabaseId) + } + + } +} + +func TestSegmentsForManagedInstanceRestorableDroppedDatabaseId(t *testing.T) { + segments := ManagedInstanceRestorableDroppedDatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ManagedInstanceRestorableDroppedDatabaseId 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/sql/2023-08-01/restorabledroppedmanageddatabases/method_get.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_get.go new file mode 100644 index 00000000000..7e520c5f8f6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_get.go @@ -0,0 +1,53 @@ +package restorabledroppedmanageddatabases + +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 *RestorableDroppedManagedDatabase +} + +// Get ... +func (c RestorableDroppedManagedDatabasesClient) Get(ctx context.Context, id ManagedInstanceRestorableDroppedDatabaseId) (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 RestorableDroppedManagedDatabase + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_listbyinstance.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_listbyinstance.go new file mode 100644 index 00000000000..ebb6740b164 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/method_listbyinstance.go @@ -0,0 +1,106 @@ +package restorabledroppedmanageddatabases + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RestorableDroppedManagedDatabase +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []RestorableDroppedManagedDatabase +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c RestorableDroppedManagedDatabasesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/restorableDroppedDatabases", 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 *[]RestorableDroppedManagedDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c RestorableDroppedManagedDatabasesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, RestorableDroppedManagedDatabaseOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RestorableDroppedManagedDatabasesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate RestorableDroppedManagedDatabaseOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]RestorableDroppedManagedDatabase, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go new file mode 100644 index 00000000000..eef2ed97d2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go @@ -0,0 +1,13 @@ +package restorabledroppedmanageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedManagedDatabase struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *RestorableDroppedManagedDatabaseProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go new file mode 100644 index 00000000000..12044efef1f --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go @@ -0,0 +1,53 @@ +package restorabledroppedmanageddatabases + +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 RestorableDroppedManagedDatabaseProperties struct { + CreationDate *string `json:"creationDate,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + DeletionDate *string `json:"deletionDate,omitempty"` + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` +} + +func (o *RestorableDroppedManagedDatabaseProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedManagedDatabaseProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *RestorableDroppedManagedDatabaseProperties) GetDeletionDateAsTime() (*time.Time, error) { + if o.DeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedManagedDatabaseProperties) SetDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionDate = &formatted +} + +func (o *RestorableDroppedManagedDatabaseProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedManagedDatabaseProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/predicates.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/predicates.go new file mode 100644 index 00000000000..4ccec82b5ad --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/predicates.go @@ -0,0 +1,32 @@ +package restorabledroppedmanageddatabases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedManagedDatabaseOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RestorableDroppedManagedDatabaseOperationPredicate) Matches(input RestorableDroppedManagedDatabase) 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/sql/2023-08-01/restorabledroppedmanageddatabases/version.go b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/version.go new file mode 100644 index 00000000000..ba4ea7fbad8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorabledroppedmanageddatabases/version.go @@ -0,0 +1,10 @@ +package restorabledroppedmanageddatabases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/restorabledroppedmanageddatabases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/README.md b/resource-manager/sql/2023-08-01/restorepoints/README.md new file mode 100644 index 00000000000..6ef5b032280 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/README.md @@ -0,0 +1,87 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorepoints` Documentation + +The `restorepoints` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/restorepoints" +``` + + +### Client Initialization + +```go +client := restorepoints.NewRestorePointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RestorePointsClient.Create` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := restorepoints.CreateDatabaseRestorePointDefinition{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RestorePointsClient.Delete` + +```go +ctx := context.TODO() +id := restorepoints.NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "restorePointName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RestorePointsClient.Get` + +```go +ctx := context.TODO() +id := restorepoints.NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "restorePointName") + +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: `RestorePointsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/restorepoints/client.go b/resource-manager/sql/2023-08-01/restorepoints/client.go new file mode 100644 index 00000000000..febed9d42f1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/client.go @@ -0,0 +1,26 @@ +package restorepoints + +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 RestorePointsClient struct { + Client *resourcemanager.Client +} + +func NewRestorePointsClientWithBaseURI(sdkApi sdkEnv.Api) (*RestorePointsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "restorepoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RestorePointsClient: %+v", err) + } + + return &RestorePointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/constants.go b/resource-manager/sql/2023-08-01/restorepoints/constants.go new file mode 100644 index 00000000000..ac6a55fdb7b --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/constants.go @@ -0,0 +1,51 @@ +package restorepoints + +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 RestorePointType string + +const ( + RestorePointTypeCONTINUOUS RestorePointType = "CONTINUOUS" + RestorePointTypeDISCRETE RestorePointType = "DISCRETE" +) + +func PossibleValuesForRestorePointType() []string { + return []string{ + string(RestorePointTypeCONTINUOUS), + string(RestorePointTypeDISCRETE), + } +} + +func (s *RestorePointType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestorePointType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestorePointType(input string) (*RestorePointType, error) { + vals := map[string]RestorePointType{ + "continuous": RestorePointTypeCONTINUOUS, + "discrete": RestorePointTypeDISCRETE, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestorePointType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/id_restorepoint.go b/resource-manager/sql/2023-08-01/restorepoints/id_restorepoint.go new file mode 100644 index 00000000000..8d873771181 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/id_restorepoint.go @@ -0,0 +1,148 @@ +package restorepoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RestorePointId{}) +} + +var _ resourceids.ResourceId = &RestorePointId{} + +// RestorePointId is a struct representing the Resource ID for a Restore Point +type RestorePointId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + RestorePointName string +} + +// NewRestorePointID returns a new RestorePointId struct +func NewRestorePointID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, restorePointName string) RestorePointId { + return RestorePointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + RestorePointName: restorePointName, + } +} + +// ParseRestorePointID parses 'input' into a RestorePointId +func ParseRestorePointID(input string) (*RestorePointId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorePointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorePointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRestorePointIDInsensitively parses 'input' case-insensitively into a RestorePointId +// note: this method should only be used for API response data and not user input +func ParseRestorePointIDInsensitively(input string) (*RestorePointId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorePointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorePointId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RestorePointId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.RestorePointName, ok = input.Parsed["restorePointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "restorePointName", input) + } + + return nil +} + +// ValidateRestorePointID checks that 'input' can be parsed as a Restore Point ID +func ValidateRestorePointID(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 := ParseRestorePointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Restore Point ID +func (id RestorePointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/restorePoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.RestorePointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Restore Point ID +func (id RestorePointId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticRestorePoints", "restorePoints", "restorePoints"), + resourceids.UserSpecifiedSegment("restorePointName", "restorePointName"), + } +} + +// String returns a human-readable description of this Restore Point ID +func (id RestorePointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Restore Point Name: %q", id.RestorePointName), + } + return fmt.Sprintf("Restore Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/id_restorepoint_test.go b/resource-manager/sql/2023-08-01/restorepoints/id_restorepoint_test.go new file mode 100644 index 00000000000..a238010b523 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/id_restorepoint_test.go @@ -0,0 +1,372 @@ +package restorepoints + +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 = &RestorePointId{} + +func TestNewRestorePointID(t *testing.T) { + id := NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "restorePointName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.RestorePointName != "restorePointName" { + t.Fatalf("Expected %q but got %q for Segment 'RestorePointName'", id.RestorePointName, "restorePointName") + } +} + +func TestFormatRestorePointID(t *testing.T) { + actual := NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "restorePointName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints/restorePointName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRestorePointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorePointId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints/restorePointName", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RestorePointName: "restorePointName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints/restorePointName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorePointID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RestorePointName != v.Expected.RestorePointName { + t.Fatalf("Expected %q but got %q for RestorePointName", v.Expected.RestorePointName, actual.RestorePointName) + } + + } +} + +func TestParseRestorePointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorePointId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/rEsToRePoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints/restorePointName", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + RestorePointName: "restorePointName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/restorePoints/restorePointName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/rEsToRePoInTs/rEsToRePoInTnAmE", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + RestorePointName: "rEsToRePoInTnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/rEsToRePoInTs/rEsToRePoInTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorePointIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.RestorePointName != v.Expected.RestorePointName { + t.Fatalf("Expected %q but got %q for RestorePointName", v.Expected.RestorePointName, actual.RestorePointName) + } + + } +} + +func TestSegmentsForRestorePointId(t *testing.T) { + segments := RestorePointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RestorePointId 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/sql/2023-08-01/restorepoints/method_create.go b/resource-manager/sql/2023-08-01/restorepoints/method_create.go new file mode 100644 index 00000000000..f1f894e7a71 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/method_create.go @@ -0,0 +1,77 @@ +package restorepoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RestorePoint +} + +// Create ... +func (c RestorePointsClient) Create(ctx context.Context, id commonids.SqlDatabaseId, input CreateDatabaseRestorePointDefinition) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/restorePoints", 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 RestorePointsClient) CreateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input CreateDatabaseRestorePointDefinition) 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/sql/2023-08-01/restorepoints/method_delete.go b/resource-manager/sql/2023-08-01/restorepoints/method_delete.go new file mode 100644 index 00000000000..c38083352d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/method_delete.go @@ -0,0 +1,46 @@ +package restorepoints + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c RestorePointsClient) Delete(ctx context.Context, id RestorePointId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/method_get.go b/resource-manager/sql/2023-08-01/restorepoints/method_get.go new file mode 100644 index 00000000000..b3641545843 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/method_get.go @@ -0,0 +1,53 @@ +package restorepoints + +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 *RestorePoint +} + +// Get ... +func (c RestorePointsClient) Get(ctx context.Context, id RestorePointId) (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 RestorePoint + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/method_listbydatabase.go b/resource-manager/sql/2023-08-01/restorepoints/method_listbydatabase.go new file mode 100644 index 00000000000..977a780cf89 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/method_listbydatabase.go @@ -0,0 +1,106 @@ +package restorepoints + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RestorePoint +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []RestorePoint +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c RestorePointsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/restorePoints", 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 *[]RestorePoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c RestorePointsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, RestorePointOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RestorePointsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate RestorePointOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]RestorePoint, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/model_createdatabaserestorepointdefinition.go b/resource-manager/sql/2023-08-01/restorepoints/model_createdatabaserestorepointdefinition.go new file mode 100644 index 00000000000..723d3552e70 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/model_createdatabaserestorepointdefinition.go @@ -0,0 +1,8 @@ +package restorepoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateDatabaseRestorePointDefinition struct { + RestorePointLabel string `json:"restorePointLabel"` +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/model_restorepoint.go b/resource-manager/sql/2023-08-01/restorepoints/model_restorepoint.go new file mode 100644 index 00000000000..29140bd9ec4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/model_restorepoint.go @@ -0,0 +1,12 @@ +package restorepoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePoint struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RestorePointProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/model_restorepointproperties.go b/resource-manager/sql/2023-08-01/restorepoints/model_restorepointproperties.go new file mode 100644 index 00000000000..c8981806d01 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/model_restorepointproperties.go @@ -0,0 +1,41 @@ +package restorepoints + +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 RestorePointProperties struct { + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + RestorePointCreationDate *string `json:"restorePointCreationDate,omitempty"` + RestorePointLabel *string `json:"restorePointLabel,omitempty"` + RestorePointType *RestorePointType `json:"restorePointType,omitempty"` +} + +func (o *RestorePointProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorePointProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} + +func (o *RestorePointProperties) GetRestorePointCreationDateAsTime() (*time.Time, error) { + if o.RestorePointCreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointCreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorePointProperties) SetRestorePointCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointCreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/restorepoints/predicates.go b/resource-manager/sql/2023-08-01/restorepoints/predicates.go new file mode 100644 index 00000000000..163b30b8206 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/predicates.go @@ -0,0 +1,32 @@ +package restorepoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePointOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RestorePointOperationPredicate) Matches(input RestorePoint) 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/sql/2023-08-01/restorepoints/version.go b/resource-manager/sql/2023-08-01/restorepoints/version.go new file mode 100644 index 00000000000..d3604ed7e85 --- /dev/null +++ b/resource-manager/sql/2023-08-01/restorepoints/version.go @@ -0,0 +1,10 @@ +package restorepoints + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/restorepoints/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/README.md b/resource-manager/sql/2023-08-01/sensitivitylabels/README.md new file mode 100644 index 00000000000..edf5473aa71 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/README.md @@ -0,0 +1,199 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sensitivitylabels` Documentation + +The `sensitivitylabels` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sensitivitylabels" +``` + + +### Client Initialization + +```go +client := sensitivitylabels.NewSensitivityLabelsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SensitivityLabelsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := sensitivitylabels.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + +payload := sensitivitylabels.SensitivityLabel{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SensitivityLabelsClient.Delete` + +```go +ctx := context.TODO() +id := sensitivitylabels.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SensitivityLabelsClient.DisableRecommendation` + +```go +ctx := context.TODO() +id := sensitivitylabels.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + +read, err := client.DisableRecommendation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SensitivityLabelsClient.EnableRecommendation` + +```go +ctx := context.TODO() +id := sensitivitylabels.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + +read, err := client.EnableRecommendation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SensitivityLabelsClient.Get` + +```go +ctx := context.TODO() +id := sensitivitylabels.NewSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName", "current") + +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: `SensitivityLabelsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id, sensitivitylabels.DefaultListByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id, sensitivitylabels.DefaultListByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SensitivityLabelsClient.ListCurrentByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListCurrentByDatabase(ctx, id, sensitivitylabels.DefaultListCurrentByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListCurrentByDatabaseComplete(ctx, id, sensitivitylabels.DefaultListCurrentByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SensitivityLabelsClient.ListRecommendedByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListRecommendedByDatabase(ctx, id, sensitivitylabels.DefaultListRecommendedByDatabaseOperationOptions())` can be used to do batched pagination +items, err := client.ListRecommendedByDatabaseComplete(ctx, id, sensitivitylabels.DefaultListRecommendedByDatabaseOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SensitivityLabelsClient.RecommendedSensitivityLabelsUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := sensitivitylabels.RecommendedSensitivityLabelUpdateList{ + // ... +} + + +read, err := client.RecommendedSensitivityLabelsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SensitivityLabelsClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := sensitivitylabels.SensitivityLabelUpdateList{ + // ... +} + + +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/sql/2023-08-01/sensitivitylabels/client.go b/resource-manager/sql/2023-08-01/sensitivitylabels/client.go new file mode 100644 index 00000000000..e5c16bac54c --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/client.go @@ -0,0 +1,26 @@ +package sensitivitylabels + +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 SensitivityLabelsClient struct { + Client *resourcemanager.Client +} + +func NewSensitivityLabelsClientWithBaseURI(sdkApi sdkEnv.Api) (*SensitivityLabelsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sensitivitylabels", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SensitivityLabelsClient: %+v", err) + } + + return &SensitivityLabelsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/constants.go b/resource-manager/sql/2023-08-01/sensitivitylabels/constants.go new file mode 100644 index 00000000000..9abd34c2cdd --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/constants.go @@ -0,0 +1,230 @@ +package sensitivitylabels + +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 ClientClassificationSource string + +const ( + ClientClassificationSourceMIP ClientClassificationSource = "MIP" + ClientClassificationSourceNative ClientClassificationSource = "Native" + ClientClassificationSourceNone ClientClassificationSource = "None" + ClientClassificationSourceRecommended ClientClassificationSource = "Recommended" +) + +func PossibleValuesForClientClassificationSource() []string { + return []string{ + string(ClientClassificationSourceMIP), + string(ClientClassificationSourceNative), + string(ClientClassificationSourceNone), + string(ClientClassificationSourceRecommended), + } +} + +func (s *ClientClassificationSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClientClassificationSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClientClassificationSource(input string) (*ClientClassificationSource, error) { + vals := map[string]ClientClassificationSource{ + "mip": ClientClassificationSourceMIP, + "native": ClientClassificationSourceNative, + "none": ClientClassificationSourceNone, + "recommended": ClientClassificationSourceRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClientClassificationSource(input) + return &out, nil +} + +type RecommendedSensitivityLabelUpdateKind string + +const ( + RecommendedSensitivityLabelUpdateKindDisable RecommendedSensitivityLabelUpdateKind = "disable" + RecommendedSensitivityLabelUpdateKindEnable RecommendedSensitivityLabelUpdateKind = "enable" +) + +func PossibleValuesForRecommendedSensitivityLabelUpdateKind() []string { + return []string{ + string(RecommendedSensitivityLabelUpdateKindDisable), + string(RecommendedSensitivityLabelUpdateKindEnable), + } +} + +func (s *RecommendedSensitivityLabelUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedSensitivityLabelUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedSensitivityLabelUpdateKind(input string) (*RecommendedSensitivityLabelUpdateKind, error) { + vals := map[string]RecommendedSensitivityLabelUpdateKind{ + "disable": RecommendedSensitivityLabelUpdateKindDisable, + "enable": RecommendedSensitivityLabelUpdateKindEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedSensitivityLabelUpdateKind(input) + return &out, nil +} + +type SensitivityLabelRank string + +const ( + SensitivityLabelRankCritical SensitivityLabelRank = "Critical" + SensitivityLabelRankHigh SensitivityLabelRank = "High" + SensitivityLabelRankLow SensitivityLabelRank = "Low" + SensitivityLabelRankMedium SensitivityLabelRank = "Medium" + SensitivityLabelRankNone SensitivityLabelRank = "None" +) + +func PossibleValuesForSensitivityLabelRank() []string { + return []string{ + string(SensitivityLabelRankCritical), + string(SensitivityLabelRankHigh), + string(SensitivityLabelRankLow), + string(SensitivityLabelRankMedium), + string(SensitivityLabelRankNone), + } +} + +func (s *SensitivityLabelRank) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelRank(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelRank(input string) (*SensitivityLabelRank, error) { + vals := map[string]SensitivityLabelRank{ + "critical": SensitivityLabelRankCritical, + "high": SensitivityLabelRankHigh, + "low": SensitivityLabelRankLow, + "medium": SensitivityLabelRankMedium, + "none": SensitivityLabelRankNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelRank(input) + return &out, nil +} + +type SensitivityLabelSource string + +const ( + SensitivityLabelSourceCurrent SensitivityLabelSource = "current" + SensitivityLabelSourceRecommended SensitivityLabelSource = "recommended" +) + +func PossibleValuesForSensitivityLabelSource() []string { + return []string{ + string(SensitivityLabelSourceCurrent), + string(SensitivityLabelSourceRecommended), + } +} + +func (s *SensitivityLabelSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelSource(input string) (*SensitivityLabelSource, error) { + vals := map[string]SensitivityLabelSource{ + "current": SensitivityLabelSourceCurrent, + "recommended": SensitivityLabelSourceRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelSource(input) + return &out, nil +} + +type SensitivityLabelUpdateKind string + +const ( + SensitivityLabelUpdateKindRemove SensitivityLabelUpdateKind = "remove" + SensitivityLabelUpdateKindSet SensitivityLabelUpdateKind = "set" +) + +func PossibleValuesForSensitivityLabelUpdateKind() []string { + return []string{ + string(SensitivityLabelUpdateKindRemove), + string(SensitivityLabelUpdateKindSet), + } +} + +func (s *SensitivityLabelUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelUpdateKind(input string) (*SensitivityLabelUpdateKind, error) { + vals := map[string]SensitivityLabelUpdateKind{ + "remove": SensitivityLabelUpdateKindRemove, + "set": SensitivityLabelUpdateKindSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelUpdateKind(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/id_column.go b/resource-manager/sql/2023-08-01/sensitivitylabels/id_column.go new file mode 100644 index 00000000000..7216a76c9ae --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/id_column.go @@ -0,0 +1,166 @@ +package sensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ColumnId{}) +} + +var _ resourceids.ResourceId = &ColumnId{} + +// ColumnId is a struct representing the Resource ID for a Column +type ColumnId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string + TableName string + ColumnName string +} + +// NewColumnID returns a new ColumnId struct +func NewColumnID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string, tableName string, columnName string) ColumnId { + return ColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseColumnID parses 'input' into a ColumnId +func ParseColumnID(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseColumnIDInsensitively parses 'input' case-insensitively into a ColumnId +// note: this method should only be used for API response data and not user input +func ParseColumnIDInsensitively(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ColumnId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateColumnID checks that 'input' can be parsed as a Column ID +func ValidateColumnID(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 := ParseColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Column ID +func (id ColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Column ID +func (id ColumnId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnName"), + } +} + +// String returns a human-readable description of this Column ID +func (id ColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/id_column_test.go b/resource-manager/sql/2023-08-01/sensitivitylabels/id_column_test.go new file mode 100644 index 00000000000..5f9e033922a --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/id_column_test.go @@ -0,0 +1,462 @@ +package sensitivitylabels + +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 = &ColumnId{} + +func TestNewColumnID(t *testing.T) { + id := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } + + if id.ColumnName != "columnName" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnName") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + ColumnName: "cOlUmNnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForColumnId(t *testing.T) { + segments := ColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ColumnId 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/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource.go b/resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource.go new file mode 100644 index 00000000000..4127f134bae --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource.go @@ -0,0 +1,183 @@ +package sensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SensitivityLabelSourceId{}) +} + +var _ resourceids.ResourceId = &SensitivityLabelSourceId{} + +// SensitivityLabelSourceId is a struct representing the Resource ID for a Sensitivity Label Source +type SensitivityLabelSourceId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SchemaName string + TableName string + ColumnName string + SensitivityLabelSource SensitivityLabelSource +} + +// NewSensitivityLabelSourceID returns a new SensitivityLabelSourceId struct +func NewSensitivityLabelSourceID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, schemaName string, tableName string, columnName string, sensitivityLabelSource SensitivityLabelSource) SensitivityLabelSourceId { + return SensitivityLabelSourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + SensitivityLabelSource: sensitivityLabelSource, + } +} + +// ParseSensitivityLabelSourceID parses 'input' into a SensitivityLabelSourceId +func ParseSensitivityLabelSourceID(input string) (*SensitivityLabelSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&SensitivityLabelSourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SensitivityLabelSourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSensitivityLabelSourceIDInsensitively parses 'input' case-insensitively into a SensitivityLabelSourceId +// note: this method should only be used for API response data and not user input +func ParseSensitivityLabelSourceIDInsensitively(input string) (*SensitivityLabelSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&SensitivityLabelSourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SensitivityLabelSourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SensitivityLabelSourceId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + if v, ok := input.Parsed["sensitivityLabelSource"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sensitivityLabelSource", input) + } + + sensitivityLabelSource, err := parseSensitivityLabelSource(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.SensitivityLabelSource = *sensitivityLabelSource + } + + return nil +} + +// ValidateSensitivityLabelSourceID checks that 'input' can be parsed as a Sensitivity Label Source ID +func ValidateSensitivityLabelSourceID(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 := ParseSensitivityLabelSourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sensitivity Label Source ID +func (id SensitivityLabelSourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/schemas/%s/tables/%s/columns/%s/sensitivityLabels/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SchemaName, id.TableName, id.ColumnName, string(id.SensitivityLabelSource)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sensitivity Label Source ID +func (id SensitivityLabelSourceId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaName"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableName"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnName"), + resourceids.StaticSegment("staticSensitivityLabels", "sensitivityLabels", "sensitivityLabels"), + resourceids.ConstantSegment("sensitivityLabelSource", PossibleValuesForSensitivityLabelSource(), "current"), + } +} + +// String returns a human-readable description of this Sensitivity Label Source ID +func (id SensitivityLabelSourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + fmt.Sprintf("Sensitivity Label Source: %q", string(id.SensitivityLabelSource)), + } + return fmt.Sprintf("Sensitivity Label Source (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource_test.go b/resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource_test.go new file mode 100644 index 00000000000..17fff7c0039 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/id_sensitivitylabelsource_test.go @@ -0,0 +1,507 @@ +package sensitivitylabels + +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 = &SensitivityLabelSourceId{} + +func TestNewSensitivityLabelSourceID(t *testing.T) { + id := NewSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName", "current") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SchemaName != "schemaName" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaName") + } + + if id.TableName != "tableName" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableName") + } + + if id.ColumnName != "columnName" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnName") + } + + if id.SensitivityLabelSource != "current" { + t.Fatalf("Expected %q but got %q for Segment 'SensitivityLabelSource'", id.SensitivityLabelSource, "current") + } +} + +func TestFormatSensitivityLabelSourceID(t *testing.T) { + actual := NewSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "schemaName", "tableName", "columnName", "current").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSensitivityLabelSourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SensitivityLabelSourceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSensitivityLabelSourceID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + if actual.SensitivityLabelSource != v.Expected.SensitivityLabelSource { + t.Fatalf("Expected %q but got %q for SensitivityLabelSource", v.Expected.SensitivityLabelSource, actual.SensitivityLabelSource) + } + + } +} + +func TestParseSensitivityLabelSourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SensitivityLabelSourceId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/sEnSiTiViTyLaBeLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SchemaName: "schemaName", + TableName: "tableName", + ColumnName: "columnName", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/schemas/schemaName/tables/tableName/columns/columnName/sensitivityLabels/current/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/sEnSiTiViTyLaBeLs/cUrReNt", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SchemaName: "sChEmAnAmE", + TableName: "tAbLeNaMe", + ColumnName: "cOlUmNnAmE", + SensitivityLabelSource: "current", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sChEmAs/sChEmAnAmE/tAbLeS/tAbLeNaMe/cOlUmNs/cOlUmNnAmE/sEnSiTiViTyLaBeLs/cUrReNt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSensitivityLabelSourceIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + if actual.SensitivityLabelSource != v.Expected.SensitivityLabelSource { + t.Fatalf("Expected %q but got %q for SensitivityLabelSource", v.Expected.SensitivityLabelSource, actual.SensitivityLabelSource) + } + + } +} + +func TestSegmentsForSensitivityLabelSourceId(t *testing.T) { + segments := SensitivityLabelSourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SensitivityLabelSourceId 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/sql/2023-08-01/sensitivitylabels/method_createorupdate.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_createorupdate.go new file mode 100644 index 00000000000..5f894e78280 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_createorupdate.go @@ -0,0 +1,59 @@ +package sensitivitylabels + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SensitivityLabel +} + +// CreateOrUpdate ... +func (c SensitivityLabelsClient) CreateOrUpdate(ctx context.Context, id ColumnId, input SensitivityLabel) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sensitivityLabels/current", 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 SensitivityLabel + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_delete.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_delete.go new file mode 100644 index 00000000000..135b5d7b6f8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_delete.go @@ -0,0 +1,47 @@ +package sensitivitylabels + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SensitivityLabelsClient) Delete(ctx context.Context, id ColumnId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/sensitivityLabels/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_disablerecommendation.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_disablerecommendation.go new file mode 100644 index 00000000000..d8a8a7a89ab --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_disablerecommendation.go @@ -0,0 +1,47 @@ +package sensitivitylabels + +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 DisableRecommendationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DisableRecommendation ... +func (c SensitivityLabelsClient) DisableRecommendation(ctx context.Context, id ColumnId) (result DisableRecommendationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sensitivityLabels/recommended/disable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_enablerecommendation.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_enablerecommendation.go new file mode 100644 index 00000000000..84bab20c878 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_enablerecommendation.go @@ -0,0 +1,47 @@ +package sensitivitylabels + +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 EnableRecommendationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// EnableRecommendation ... +func (c SensitivityLabelsClient) EnableRecommendation(ctx context.Context, id ColumnId) (result EnableRecommendationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sensitivityLabels/recommended/enable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_get.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_get.go new file mode 100644 index 00000000000..88bde8c3384 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_get.go @@ -0,0 +1,53 @@ +package sensitivitylabels + +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 *SensitivityLabel +} + +// Get ... +func (c SensitivityLabelsClient) Get(ctx context.Context, id SensitivityLabelSourceId) (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 SensitivityLabel + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_listbydatabase.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_listbydatabase.go new file mode 100644 index 00000000000..661b362c83e --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_listbydatabase.go @@ -0,0 +1,135 @@ +package sensitivitylabels + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type ListByDatabaseOperationOptions struct { + Filter *string +} + +func DefaultListByDatabaseOperationOptions() ListByDatabaseOperationOptions { + return ListByDatabaseOperationOptions{} +} + +func (o ListByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c SensitivityLabelsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/sensitivityLabels", 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 *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c SensitivityLabelsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SensitivityLabelsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, options ListByDatabaseOperationOptions, predicate SensitivityLabelOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.ListByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_listcurrentbydatabase.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_listcurrentbydatabase.go new file mode 100644 index 00000000000..b689585e559 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_listcurrentbydatabase.go @@ -0,0 +1,139 @@ +package sensitivitylabels + +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 ListCurrentByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type ListCurrentByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type ListCurrentByDatabaseOperationOptions struct { + Count *bool + Filter *string +} + +func DefaultListCurrentByDatabaseOperationOptions() ListCurrentByDatabaseOperationOptions { + return ListCurrentByDatabaseOperationOptions{} +} + +func (o ListCurrentByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListCurrentByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListCurrentByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCurrentByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCurrentByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListCurrentByDatabase ... +func (c SensitivityLabelsClient) ListCurrentByDatabase(ctx context.Context, id commonids.SqlDatabaseId, options ListCurrentByDatabaseOperationOptions) (result ListCurrentByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCurrentByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/currentSensitivityLabels", 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 *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListCurrentByDatabaseComplete retrieves all the results into a single object +func (c SensitivityLabelsClient) ListCurrentByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId, options ListCurrentByDatabaseOperationOptions) (ListCurrentByDatabaseCompleteResult, error) { + return c.ListCurrentByDatabaseCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// ListCurrentByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SensitivityLabelsClient) ListCurrentByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, options ListCurrentByDatabaseOperationOptions, predicate SensitivityLabelOperationPredicate) (result ListCurrentByDatabaseCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.ListCurrentByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCurrentByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_listrecommendedbydatabase.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_listrecommendedbydatabase.go new file mode 100644 index 00000000000..ecaac2fad9f --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_listrecommendedbydatabase.go @@ -0,0 +1,139 @@ +package sensitivitylabels + +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 ListRecommendedByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type ListRecommendedByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type ListRecommendedByDatabaseOperationOptions struct { + Filter *string + IncludeDisabledRecommendations *bool +} + +func DefaultListRecommendedByDatabaseOperationOptions() ListRecommendedByDatabaseOperationOptions { + return ListRecommendedByDatabaseOperationOptions{} +} + +func (o ListRecommendedByDatabaseOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListRecommendedByDatabaseOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListRecommendedByDatabaseOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IncludeDisabledRecommendations != nil { + out.Append("includeDisabledRecommendations", fmt.Sprintf("%v", *o.IncludeDisabledRecommendations)) + } + return &out +} + +type ListRecommendedByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListRecommendedByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListRecommendedByDatabase ... +func (c SensitivityLabelsClient) ListRecommendedByDatabase(ctx context.Context, id commonids.SqlDatabaseId, options ListRecommendedByDatabaseOperationOptions) (result ListRecommendedByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListRecommendedByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", 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 *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListRecommendedByDatabaseComplete retrieves all the results into a single object +func (c SensitivityLabelsClient) ListRecommendedByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId, options ListRecommendedByDatabaseOperationOptions) (ListRecommendedByDatabaseCompleteResult, error) { + return c.ListRecommendedByDatabaseCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// ListRecommendedByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SensitivityLabelsClient) ListRecommendedByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, options ListRecommendedByDatabaseOperationOptions, predicate SensitivityLabelOperationPredicate) (result ListRecommendedByDatabaseCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.ListRecommendedByDatabase(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListRecommendedByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go new file mode 100644 index 00000000000..074171f81a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go @@ -0,0 +1,52 @@ +package sensitivitylabels + +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 RecommendedSensitivityLabelsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RecommendedSensitivityLabelsUpdate ... +func (c SensitivityLabelsClient) RecommendedSensitivityLabelsUpdate(ctx context.Context, id commonids.SqlDatabaseId, input RecommendedSensitivityLabelUpdateList) (result RecommendedSensitivityLabelsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/method_update.go b/resource-manager/sql/2023-08-01/sensitivitylabels/method_update.go new file mode 100644 index 00000000000..934dc80d015 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/method_update.go @@ -0,0 +1,52 @@ +package sensitivitylabels + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Update ... +func (c SensitivityLabelsClient) Update(ctx context.Context, id commonids.SqlDatabaseId, input SensitivityLabelUpdateList) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/currentSensitivityLabels", 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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdate.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdate.go new file mode 100644 index 00000000000..6e89d6532f3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdate.go @@ -0,0 +1,11 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendedSensitivityLabelUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go new file mode 100644 index 00000000000..845828d3bb3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go @@ -0,0 +1,8 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateList struct { + Operations *[]RecommendedSensitivityLabelUpdate `json:"operations,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..0c4f9fbabb2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go @@ -0,0 +1,11 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateProperties struct { + Column string `json:"column"` + Op RecommendedSensitivityLabelUpdateKind `json:"op"` + Schema string `json:"schema"` + Table string `json:"table"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabel.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabel.go new file mode 100644 index 00000000000..2f4141ad3da --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabel.go @@ -0,0 +1,12 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabel struct { + Id *string `json:"id,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SensitivityLabelProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelproperties.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelproperties.go new file mode 100644 index 00000000000..b1b13a8a2f3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelproperties.go @@ -0,0 +1,17 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelProperties struct { + ClientClassificationSource *ClientClassificationSource `json:"clientClassificationSource,omitempty"` + ColumnName *string `json:"columnName,omitempty"` + InformationType *string `json:"informationType,omitempty"` + InformationTypeId *string `json:"informationTypeId,omitempty"` + IsDisabled *bool `json:"isDisabled,omitempty"` + LabelId *string `json:"labelId,omitempty"` + LabelName *string `json:"labelName,omitempty"` + Rank *SensitivityLabelRank `json:"rank,omitempty"` + SchemaName *string `json:"schemaName,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdate.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdate.go new file mode 100644 index 00000000000..03bdd726e63 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdate.go @@ -0,0 +1,11 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SensitivityLabelUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdatelist.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdatelist.go new file mode 100644 index 00000000000..0e153cd92bc --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdatelist.go @@ -0,0 +1,8 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdateList struct { + Operations *[]SensitivityLabelUpdate `json:"operations,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdateproperties.go b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..697ecfb9f0a --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/model_sensitivitylabelupdateproperties.go @@ -0,0 +1,12 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdateProperties struct { + Column string `json:"column"` + Op SensitivityLabelUpdateKind `json:"op"` + Schema string `json:"schema"` + SensitivityLabel *SensitivityLabel `json:"sensitivityLabel,omitempty"` + Table string `json:"table"` +} diff --git a/resource-manager/sql/2023-08-01/sensitivitylabels/predicates.go b/resource-manager/sql/2023-08-01/sensitivitylabels/predicates.go new file mode 100644 index 00000000000..c3026932143 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/predicates.go @@ -0,0 +1,32 @@ +package sensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelOperationPredicate struct { + Id *string + ManagedBy *string + Name *string + Type *string +} + +func (p SensitivityLabelOperationPredicate) Matches(input SensitivityLabel) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + 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/sql/2023-08-01/sensitivitylabels/version.go b/resource-manager/sql/2023-08-01/sensitivitylabels/version.go new file mode 100644 index 00000000000..6dd4914144a --- /dev/null +++ b/resource-manager/sql/2023-08-01/sensitivitylabels/version.go @@ -0,0 +1,10 @@ +package sensitivitylabels + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sensitivitylabels/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..cc29f089cb5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings` Documentation + +The `serveradvancedthreatprotectionsettings` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := serveradvancedthreatprotectionsettings.NewServerAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serveradvancedthreatprotectionsettings.ServerAdvancedThreatProtection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAdvancedThreatProtectionSettingsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerAdvancedThreatProtectionSettingsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..0d676922ffb --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/client.go @@ -0,0 +1,26 @@ +package serveradvancedthreatprotectionsettings + +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 ServerAdvancedThreatProtectionSettingsClient struct { + Client *resourcemanager.Client +} + +func NewServerAdvancedThreatProtectionSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerAdvancedThreatProtectionSettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serveradvancedthreatprotectionsettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerAdvancedThreatProtectionSettingsClient: %+v", err) + } + + return &ServerAdvancedThreatProtectionSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..1e51889a6ac --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/constants.go @@ -0,0 +1,54 @@ +package serveradvancedthreatprotectionsettings + +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 AdvancedThreatProtectionState string + +const ( + AdvancedThreatProtectionStateDisabled AdvancedThreatProtectionState = "Disabled" + AdvancedThreatProtectionStateEnabled AdvancedThreatProtectionState = "Enabled" + AdvancedThreatProtectionStateNew AdvancedThreatProtectionState = "New" +) + +func PossibleValuesForAdvancedThreatProtectionState() []string { + return []string{ + string(AdvancedThreatProtectionStateDisabled), + string(AdvancedThreatProtectionStateEnabled), + string(AdvancedThreatProtectionStateNew), + } +} + +func (s *AdvancedThreatProtectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvancedThreatProtectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvancedThreatProtectionState(input string) (*AdvancedThreatProtectionState, error) { + vals := map[string]AdvancedThreatProtectionState{ + "disabled": AdvancedThreatProtectionStateDisabled, + "enabled": AdvancedThreatProtectionStateEnabled, + "new": AdvancedThreatProtectionStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvancedThreatProtectionState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..9b6eac9b9c5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_createorupdate.go @@ -0,0 +1,76 @@ +package serveradvancedthreatprotectionsettings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerAdvancedThreatProtection +} + +// CreateOrUpdate ... +func (c ServerAdvancedThreatProtectionSettingsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerAdvancedThreatProtection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ServerAdvancedThreatProtectionSettingsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerAdvancedThreatProtection) 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/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..acc2ff53f99 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,55 @@ +package serveradvancedthreatprotectionsettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerAdvancedThreatProtection +} + +// Get ... +func (c ServerAdvancedThreatProtectionSettingsClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings/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 ServerAdvancedThreatProtection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_listbyserver.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_listbyserver.go new file mode 100644 index 00000000000..f22ea47813e --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/method_listbyserver.go @@ -0,0 +1,106 @@ +package serveradvancedthreatprotectionsettings + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerAdvancedThreatProtection +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerAdvancedThreatProtection +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerAdvancedThreatProtectionSettingsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/advancedThreatProtectionSettings", 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 *[]ServerAdvancedThreatProtection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerAdvancedThreatProtectionSettingsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerAdvancedThreatProtectionOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerAdvancedThreatProtectionSettingsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerAdvancedThreatProtectionOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerAdvancedThreatProtection, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..7b891652fc0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go @@ -0,0 +1,27 @@ +package serveradvancedthreatprotectionsettings + +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 AdvancedThreatProtectionProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + State AdvancedThreatProtectionState `json:"state"` +} + +func (o *AdvancedThreatProtectionProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *AdvancedThreatProtectionProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go new file mode 100644 index 00000000000..623a3e9aef2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go @@ -0,0 +1,16 @@ +package serveradvancedthreatprotectionsettings + +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 ServerAdvancedThreatProtection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvancedThreatProtectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..d76325ab336 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/predicates.go @@ -0,0 +1,27 @@ +package serveradvancedthreatprotectionsettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerAdvancedThreatProtectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerAdvancedThreatProtectionOperationPredicate) Matches(input ServerAdvancedThreatProtection) 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/sql/2023-08-01/serveradvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..fc2a5c0b4a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvancedthreatprotectionsettings/version.go @@ -0,0 +1,10 @@ +package serveradvancedthreatprotectionsettings + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serveradvancedthreatprotectionsettings/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/README.md b/resource-manager/sql/2023-08-01/serveradvisors/README.md new file mode 100644 index 00000000000..27701b5821a --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveradvisors` Documentation + +The `serveradvisors` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveradvisors" +``` + + +### Client Initialization + +```go +client := serveradvisors.NewServerAdvisorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAdvisorsClient.Get` + +```go +ctx := context.TODO() +id := serveradvisors.NewAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "advisorName") + +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: `ServerAdvisorsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.ListByServer(ctx, id, serveradvisors.DefaultListByServerOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerAdvisorsClient.Update` + +```go +ctx := context.TODO() +id := serveradvisors.NewAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "advisorName") + +payload := serveradvisors.Advisor{ + // ... +} + + +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/sql/2023-08-01/serveradvisors/client.go b/resource-manager/sql/2023-08-01/serveradvisors/client.go new file mode 100644 index 00000000000..3933667d1fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/client.go @@ -0,0 +1,26 @@ +package serveradvisors + +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 ServerAdvisorsClient struct { + Client *resourcemanager.Client +} + +func NewServerAdvisorsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerAdvisorsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serveradvisors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerAdvisorsClient: %+v", err) + } + + return &ServerAdvisorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/constants.go b/resource-manager/sql/2023-08-01/serveradvisors/constants.go new file mode 100644 index 00000000000..88c4fcc07ed --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/constants.go @@ -0,0 +1,351 @@ +package serveradvisors + +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 AdvisorStatus string + +const ( + AdvisorStatusGA AdvisorStatus = "GA" + AdvisorStatusLimitedPublicPreview AdvisorStatus = "LimitedPublicPreview" + AdvisorStatusPrivatePreview AdvisorStatus = "PrivatePreview" + AdvisorStatusPublicPreview AdvisorStatus = "PublicPreview" +) + +func PossibleValuesForAdvisorStatus() []string { + return []string{ + string(AdvisorStatusGA), + string(AdvisorStatusLimitedPublicPreview), + string(AdvisorStatusPrivatePreview), + string(AdvisorStatusPublicPreview), + } +} + +func (s *AdvisorStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdvisorStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdvisorStatus(input string) (*AdvisorStatus, error) { + vals := map[string]AdvisorStatus{ + "ga": AdvisorStatusGA, + "limitedpublicpreview": AdvisorStatusLimitedPublicPreview, + "privatepreview": AdvisorStatusPrivatePreview, + "publicpreview": AdvisorStatusPublicPreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdvisorStatus(input) + return &out, nil +} + +type AutoExecuteStatus string + +const ( + AutoExecuteStatusDefault AutoExecuteStatus = "Default" + AutoExecuteStatusDisabled AutoExecuteStatus = "Disabled" + AutoExecuteStatusEnabled AutoExecuteStatus = "Enabled" +) + +func PossibleValuesForAutoExecuteStatus() []string { + return []string{ + string(AutoExecuteStatusDefault), + string(AutoExecuteStatusDisabled), + string(AutoExecuteStatusEnabled), + } +} + +func (s *AutoExecuteStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoExecuteStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoExecuteStatus(input string) (*AutoExecuteStatus, error) { + vals := map[string]AutoExecuteStatus{ + "default": AutoExecuteStatusDefault, + "disabled": AutoExecuteStatusDisabled, + "enabled": AutoExecuteStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoExecuteStatus(input) + return &out, nil +} + +type AutoExecuteStatusInheritedFrom string + +const ( + AutoExecuteStatusInheritedFromDatabase AutoExecuteStatusInheritedFrom = "Database" + AutoExecuteStatusInheritedFromDefault AutoExecuteStatusInheritedFrom = "Default" + AutoExecuteStatusInheritedFromElasticPool AutoExecuteStatusInheritedFrom = "ElasticPool" + AutoExecuteStatusInheritedFromServer AutoExecuteStatusInheritedFrom = "Server" + AutoExecuteStatusInheritedFromSubscription AutoExecuteStatusInheritedFrom = "Subscription" +) + +func PossibleValuesForAutoExecuteStatusInheritedFrom() []string { + return []string{ + string(AutoExecuteStatusInheritedFromDatabase), + string(AutoExecuteStatusInheritedFromDefault), + string(AutoExecuteStatusInheritedFromElasticPool), + string(AutoExecuteStatusInheritedFromServer), + string(AutoExecuteStatusInheritedFromSubscription), + } +} + +func (s *AutoExecuteStatusInheritedFrom) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoExecuteStatusInheritedFrom(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoExecuteStatusInheritedFrom(input string) (*AutoExecuteStatusInheritedFrom, error) { + vals := map[string]AutoExecuteStatusInheritedFrom{ + "database": AutoExecuteStatusInheritedFromDatabase, + "default": AutoExecuteStatusInheritedFromDefault, + "elasticpool": AutoExecuteStatusInheritedFromElasticPool, + "server": AutoExecuteStatusInheritedFromServer, + "subscription": AutoExecuteStatusInheritedFromSubscription, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoExecuteStatusInheritedFrom(input) + return &out, nil +} + +type ImplementationMethod string + +const ( + ImplementationMethodAzurePowerShell ImplementationMethod = "AzurePowerShell" + ImplementationMethodTSql ImplementationMethod = "TSql" +) + +func PossibleValuesForImplementationMethod() []string { + return []string{ + string(ImplementationMethodAzurePowerShell), + string(ImplementationMethodTSql), + } +} + +func (s *ImplementationMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImplementationMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImplementationMethod(input string) (*ImplementationMethod, error) { + vals := map[string]ImplementationMethod{ + "azurepowershell": ImplementationMethodAzurePowerShell, + "tsql": ImplementationMethodTSql, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImplementationMethod(input) + return &out, nil +} + +type IsRetryable string + +const ( + IsRetryableNo IsRetryable = "No" + IsRetryableYes IsRetryable = "Yes" +) + +func PossibleValuesForIsRetryable() []string { + return []string{ + string(IsRetryableNo), + string(IsRetryableYes), + } +} + +func (s *IsRetryable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIsRetryable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIsRetryable(input string) (*IsRetryable, error) { + vals := map[string]IsRetryable{ + "no": IsRetryableNo, + "yes": IsRetryableYes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IsRetryable(input) + return &out, nil +} + +type RecommendedActionCurrentState string + +const ( + RecommendedActionCurrentStateActive RecommendedActionCurrentState = "Active" + RecommendedActionCurrentStateError RecommendedActionCurrentState = "Error" + RecommendedActionCurrentStateExecuting RecommendedActionCurrentState = "Executing" + RecommendedActionCurrentStateExpired RecommendedActionCurrentState = "Expired" + RecommendedActionCurrentStateIgnored RecommendedActionCurrentState = "Ignored" + RecommendedActionCurrentStateMonitoring RecommendedActionCurrentState = "Monitoring" + RecommendedActionCurrentStatePending RecommendedActionCurrentState = "Pending" + RecommendedActionCurrentStatePendingRevert RecommendedActionCurrentState = "PendingRevert" + RecommendedActionCurrentStateResolved RecommendedActionCurrentState = "Resolved" + RecommendedActionCurrentStateRevertCancelled RecommendedActionCurrentState = "RevertCancelled" + RecommendedActionCurrentStateReverted RecommendedActionCurrentState = "Reverted" + RecommendedActionCurrentStateReverting RecommendedActionCurrentState = "Reverting" + RecommendedActionCurrentStateSuccess RecommendedActionCurrentState = "Success" + RecommendedActionCurrentStateVerifying RecommendedActionCurrentState = "Verifying" +) + +func PossibleValuesForRecommendedActionCurrentState() []string { + return []string{ + string(RecommendedActionCurrentStateActive), + string(RecommendedActionCurrentStateError), + string(RecommendedActionCurrentStateExecuting), + string(RecommendedActionCurrentStateExpired), + string(RecommendedActionCurrentStateIgnored), + string(RecommendedActionCurrentStateMonitoring), + string(RecommendedActionCurrentStatePending), + string(RecommendedActionCurrentStatePendingRevert), + string(RecommendedActionCurrentStateResolved), + string(RecommendedActionCurrentStateRevertCancelled), + string(RecommendedActionCurrentStateReverted), + string(RecommendedActionCurrentStateReverting), + string(RecommendedActionCurrentStateSuccess), + string(RecommendedActionCurrentStateVerifying), + } +} + +func (s *RecommendedActionCurrentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedActionCurrentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedActionCurrentState(input string) (*RecommendedActionCurrentState, error) { + vals := map[string]RecommendedActionCurrentState{ + "active": RecommendedActionCurrentStateActive, + "error": RecommendedActionCurrentStateError, + "executing": RecommendedActionCurrentStateExecuting, + "expired": RecommendedActionCurrentStateExpired, + "ignored": RecommendedActionCurrentStateIgnored, + "monitoring": RecommendedActionCurrentStateMonitoring, + "pending": RecommendedActionCurrentStatePending, + "pendingrevert": RecommendedActionCurrentStatePendingRevert, + "resolved": RecommendedActionCurrentStateResolved, + "revertcancelled": RecommendedActionCurrentStateRevertCancelled, + "reverted": RecommendedActionCurrentStateReverted, + "reverting": RecommendedActionCurrentStateReverting, + "success": RecommendedActionCurrentStateSuccess, + "verifying": RecommendedActionCurrentStateVerifying, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedActionCurrentState(input) + return &out, nil +} + +type RecommendedActionInitiatedBy string + +const ( + RecommendedActionInitiatedBySystem RecommendedActionInitiatedBy = "System" + RecommendedActionInitiatedByUser RecommendedActionInitiatedBy = "User" +) + +func PossibleValuesForRecommendedActionInitiatedBy() []string { + return []string{ + string(RecommendedActionInitiatedBySystem), + string(RecommendedActionInitiatedByUser), + } +} + +func (s *RecommendedActionInitiatedBy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedActionInitiatedBy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedActionInitiatedBy(input string) (*RecommendedActionInitiatedBy, error) { + vals := map[string]RecommendedActionInitiatedBy{ + "system": RecommendedActionInitiatedBySystem, + "user": RecommendedActionInitiatedByUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedActionInitiatedBy(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/id_advisor.go b/resource-manager/sql/2023-08-01/serveradvisors/id_advisor.go new file mode 100644 index 00000000000..c2d3c0d6ef5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/id_advisor.go @@ -0,0 +1,139 @@ +package serveradvisors + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AdvisorId{}) +} + +var _ resourceids.ResourceId = &AdvisorId{} + +// AdvisorId is a struct representing the Resource ID for a Advisor +type AdvisorId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + AdvisorName string +} + +// NewAdvisorID returns a new AdvisorId struct +func NewAdvisorID(subscriptionId string, resourceGroupName string, serverName string, advisorName string) AdvisorId { + return AdvisorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + AdvisorName: advisorName, + } +} + +// ParseAdvisorID parses 'input' into a AdvisorId +func ParseAdvisorID(input string) (*AdvisorId, error) { + parser := resourceids.NewParserFromResourceIdType(&AdvisorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AdvisorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAdvisorIDInsensitively parses 'input' case-insensitively into a AdvisorId +// note: this method should only be used for API response data and not user input +func ParseAdvisorIDInsensitively(input string) (*AdvisorId, error) { + parser := resourceids.NewParserFromResourceIdType(&AdvisorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AdvisorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AdvisorId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.AdvisorName, ok = input.Parsed["advisorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "advisorName", input) + } + + return nil +} + +// ValidateAdvisorID checks that 'input' can be parsed as a Advisor ID +func ValidateAdvisorID(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 := ParseAdvisorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Advisor ID +func (id AdvisorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/advisors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.AdvisorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Advisor ID +func (id AdvisorId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorName"), + } +} + +// String returns a human-readable description of this Advisor ID +func (id AdvisorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Advisor Name: %q", id.AdvisorName), + } + return fmt.Sprintf("Advisor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/id_advisor_test.go b/resource-manager/sql/2023-08-01/serveradvisors/id_advisor_test.go new file mode 100644 index 00000000000..1c24bc6d7be --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/id_advisor_test.go @@ -0,0 +1,327 @@ +package serveradvisors + +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 = &AdvisorId{} + +func TestNewAdvisorID(t *testing.T) { + id := NewAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "advisorName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.AdvisorName != "advisorName" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorName") + } +} + +func TestFormatAdvisorID(t *testing.T) { + actual := NewAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "advisorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors/advisorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAdvisorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AdvisorId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors/advisorName", + Expected: &AdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + AdvisorName: "advisorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors/advisorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAdvisorID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + } +} + +func TestParseAdvisorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AdvisorId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/aDvIsOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors/advisorName", + Expected: &AdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + AdvisorName: "advisorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/advisors/advisorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/aDvIsOrS/aDvIsOrNaMe", + Expected: &AdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + AdvisorName: "aDvIsOrNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/aDvIsOrS/aDvIsOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAdvisorIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.AdvisorName != v.Expected.AdvisorName { + t.Fatalf("Expected %q but got %q for AdvisorName", v.Expected.AdvisorName, actual.AdvisorName) + } + + } +} + +func TestSegmentsForAdvisorId(t *testing.T) { + segments := AdvisorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AdvisorId 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/sql/2023-08-01/serveradvisors/method_get.go b/resource-manager/sql/2023-08-01/serveradvisors/method_get.go new file mode 100644 index 00000000000..027a2dd784b --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/method_get.go @@ -0,0 +1,53 @@ +package serveradvisors + +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 *Advisor +} + +// Get ... +func (c ServerAdvisorsClient) Get(ctx context.Context, id AdvisorId) (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 Advisor + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/method_listbyserver.go b/resource-manager/sql/2023-08-01/serveradvisors/method_listbyserver.go new file mode 100644 index 00000000000..88ed4156027 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/method_listbyserver.go @@ -0,0 +1,84 @@ +package serveradvisors + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Advisor +} + +type ListByServerOperationOptions struct { + Expand *string +} + +func DefaultListByServerOperationOptions() ListByServerOperationOptions { + return ListByServerOperationOptions{} +} + +func (o ListByServerOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServerOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByServerOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// ListByServer ... +func (c ServerAdvisorsClient) ListByServer(ctx context.Context, id commonids.SqlServerId, options ListByServerOperationOptions) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/advisors", 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 []Advisor + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/method_update.go b/resource-manager/sql/2023-08-01/serveradvisors/method_update.go new file mode 100644 index 00000000000..26eae2eb675 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/method_update.go @@ -0,0 +1,57 @@ +package serveradvisors + +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 *Advisor +} + +// Update ... +func (c ServerAdvisorsClient) Update(ctx context.Context, id AdvisorId, input Advisor) (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 Advisor + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_advisor.go b/resource-manager/sql/2023-08-01/serveradvisors/model_advisor.go new file mode 100644 index 00000000000..62a95459c61 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_advisor.go @@ -0,0 +1,13 @@ +package serveradvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Advisor struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdvisorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_advisorproperties.go b/resource-manager/sql/2023-08-01/serveradvisors/model_advisorproperties.go new file mode 100644 index 00000000000..e207bccdb60 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_advisorproperties.go @@ -0,0 +1,31 @@ +package serveradvisors + +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 AdvisorProperties struct { + AdvisorStatus *AdvisorStatus `json:"advisorStatus,omitempty"` + AutoExecuteStatus AutoExecuteStatus `json:"autoExecuteStatus"` + AutoExecuteStatusInheritedFrom *AutoExecuteStatusInheritedFrom `json:"autoExecuteStatusInheritedFrom,omitempty"` + LastChecked *string `json:"lastChecked,omitempty"` + RecommendationsStatus *string `json:"recommendationsStatus,omitempty"` + RecommendedActions *[]RecommendedAction `json:"recommendedActions,omitempty"` +} + +func (o *AdvisorProperties) GetLastCheckedAsTime() (*time.Time, error) { + if o.LastChecked == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastChecked, "2006-01-02T15:04:05Z07:00") +} + +func (o *AdvisorProperties) SetLastCheckedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastChecked = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedaction.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedaction.go new file mode 100644 index 00000000000..434168219bf --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedaction.go @@ -0,0 +1,13 @@ +package serveradvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedAction struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendedActionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionerrorinfo.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionerrorinfo.go new file mode 100644 index 00000000000..75fb513d44c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionerrorinfo.go @@ -0,0 +1,9 @@ +package serveradvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionErrorInfo struct { + ErrorCode *string `json:"errorCode,omitempty"` + IsRetryable *IsRetryable `json:"isRetryable,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimpactrecord.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimpactrecord.go new file mode 100644 index 00000000000..6982c356f12 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimpactrecord.go @@ -0,0 +1,12 @@ +package serveradvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionImpactRecord struct { + AbsoluteValue *float64 `json:"absoluteValue,omitempty"` + ChangeValueAbsolute *float64 `json:"changeValueAbsolute,omitempty"` + ChangeValueRelative *float64 `json:"changeValueRelative,omitempty"` + DimensionName *string `json:"dimensionName,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimplementationinfo.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimplementationinfo.go new file mode 100644 index 00000000000..d46b55a832f --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionimplementationinfo.go @@ -0,0 +1,9 @@ +package serveradvisors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedActionImplementationInfo struct { + Method *ImplementationMethod `json:"method,omitempty"` + Script *string `json:"script,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionmetricinfo.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionmetricinfo.go new file mode 100644 index 00000000000..f236c5ae826 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionmetricinfo.go @@ -0,0 +1,30 @@ +package serveradvisors + +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 RecommendedActionMetricInfo struct { + MetricName *string `json:"metricName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + TimeGrain *string `json:"timeGrain,omitempty"` + Unit *string `json:"unit,omitempty"` + Value *float64 `json:"value,omitempty"` +} + +func (o *RecommendedActionMetricInfo) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionMetricInfo) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionproperties.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionproperties.go new file mode 100644 index 00000000000..75e3bf0ae84 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionproperties.go @@ -0,0 +1,108 @@ +package serveradvisors + +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 RecommendedActionProperties struct { + Details *map[string]string `json:"details,omitempty"` + ErrorDetails *RecommendedActionErrorInfo `json:"errorDetails,omitempty"` + EstimatedImpact *[]RecommendedActionImpactRecord `json:"estimatedImpact,omitempty"` + ExecuteActionDuration *string `json:"executeActionDuration,omitempty"` + ExecuteActionInitiatedBy *RecommendedActionInitiatedBy `json:"executeActionInitiatedBy,omitempty"` + ExecuteActionInitiatedTime *string `json:"executeActionInitiatedTime,omitempty"` + ExecuteActionStartTime *string `json:"executeActionStartTime,omitempty"` + ImplementationDetails *RecommendedActionImplementationInfo `json:"implementationDetails,omitempty"` + IsArchivedAction *bool `json:"isArchivedAction,omitempty"` + IsExecutableAction *bool `json:"isExecutableAction,omitempty"` + IsRevertableAction *bool `json:"isRevertableAction,omitempty"` + LastRefresh *string `json:"lastRefresh,omitempty"` + LinkedObjects *[]string `json:"linkedObjects,omitempty"` + ObservedImpact *[]RecommendedActionImpactRecord `json:"observedImpact,omitempty"` + RecommendationReason *string `json:"recommendationReason,omitempty"` + RevertActionDuration *string `json:"revertActionDuration,omitempty"` + RevertActionInitiatedBy *RecommendedActionInitiatedBy `json:"revertActionInitiatedBy,omitempty"` + RevertActionInitiatedTime *string `json:"revertActionInitiatedTime,omitempty"` + RevertActionStartTime *string `json:"revertActionStartTime,omitempty"` + Score *int64 `json:"score,omitempty"` + State RecommendedActionStateInfo `json:"state"` + TimeSeries *[]RecommendedActionMetricInfo `json:"timeSeries,omitempty"` + ValidSince *string `json:"validSince,omitempty"` +} + +func (o *RecommendedActionProperties) GetExecuteActionInitiatedTimeAsTime() (*time.Time, error) { + if o.ExecuteActionInitiatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExecuteActionInitiatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetExecuteActionInitiatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExecuteActionInitiatedTime = &formatted +} + +func (o *RecommendedActionProperties) GetExecuteActionStartTimeAsTime() (*time.Time, error) { + if o.ExecuteActionStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExecuteActionStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetExecuteActionStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExecuteActionStartTime = &formatted +} + +func (o *RecommendedActionProperties) GetLastRefreshAsTime() (*time.Time, error) { + if o.LastRefresh == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastRefresh, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetLastRefreshAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastRefresh = &formatted +} + +func (o *RecommendedActionProperties) GetRevertActionInitiatedTimeAsTime() (*time.Time, error) { + if o.RevertActionInitiatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RevertActionInitiatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetRevertActionInitiatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevertActionInitiatedTime = &formatted +} + +func (o *RecommendedActionProperties) GetRevertActionStartTimeAsTime() (*time.Time, error) { + if o.RevertActionStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RevertActionStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetRevertActionStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RevertActionStartTime = &formatted +} + +func (o *RecommendedActionProperties) GetValidSinceAsTime() (*time.Time, error) { + if o.ValidSince == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidSince, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionProperties) SetValidSinceAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidSince = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionstateinfo.go b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionstateinfo.go new file mode 100644 index 00000000000..9db79192c83 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/model_recommendedactionstateinfo.go @@ -0,0 +1,28 @@ +package serveradvisors + +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 RecommendedActionStateInfo struct { + ActionInitiatedBy *RecommendedActionInitiatedBy `json:"actionInitiatedBy,omitempty"` + CurrentValue RecommendedActionCurrentState `json:"currentValue"` + LastModified *string `json:"lastModified,omitempty"` +} + +func (o *RecommendedActionStateInfo) GetLastModifiedAsTime() (*time.Time, error) { + if o.LastModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecommendedActionStateInfo) SetLastModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModified = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serveradvisors/version.go b/resource-manager/sql/2023-08-01/serveradvisors/version.go new file mode 100644 index 00000000000..5579cd6cf16 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveradvisors/version.go @@ -0,0 +1,10 @@ +package serveradvisors + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serveradvisors/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/README.md b/resource-manager/sql/2023-08-01/serverautomatictuning/README.md new file mode 100644 index 00000000000..48019a55509 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverautomatictuning` Documentation + +The `serverautomatictuning` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverautomatictuning" +``` + + +### Client Initialization + +```go +client := serverautomatictuning.NewServerAutomaticTuningClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAutomaticTuningClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerAutomaticTuningClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serverautomatictuning.ServerAutomaticTuning{ + // ... +} + + +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/sql/2023-08-01/serverautomatictuning/client.go b/resource-manager/sql/2023-08-01/serverautomatictuning/client.go new file mode 100644 index 00000000000..2730beb5fc5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/client.go @@ -0,0 +1,26 @@ +package serverautomatictuning + +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 ServerAutomaticTuningClient struct { + Client *resourcemanager.Client +} + +func NewServerAutomaticTuningClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerAutomaticTuningClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverautomatictuning", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerAutomaticTuningClient: %+v", err) + } + + return &ServerAutomaticTuningClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/constants.go b/resource-manager/sql/2023-08-01/serverautomatictuning/constants.go new file mode 100644 index 00000000000..f4e6120511c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/constants.go @@ -0,0 +1,183 @@ +package serverautomatictuning + +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 AutomaticTuningOptionModeActual string + +const ( + AutomaticTuningOptionModeActualOff AutomaticTuningOptionModeActual = "Off" + AutomaticTuningOptionModeActualOn AutomaticTuningOptionModeActual = "On" +) + +func PossibleValuesForAutomaticTuningOptionModeActual() []string { + return []string{ + string(AutomaticTuningOptionModeActualOff), + string(AutomaticTuningOptionModeActualOn), + } +} + +func (s *AutomaticTuningOptionModeActual) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningOptionModeActual(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningOptionModeActual(input string) (*AutomaticTuningOptionModeActual, error) { + vals := map[string]AutomaticTuningOptionModeActual{ + "off": AutomaticTuningOptionModeActualOff, + "on": AutomaticTuningOptionModeActualOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningOptionModeActual(input) + return &out, nil +} + +type AutomaticTuningOptionModeDesired string + +const ( + AutomaticTuningOptionModeDesiredDefault AutomaticTuningOptionModeDesired = "Default" + AutomaticTuningOptionModeDesiredOff AutomaticTuningOptionModeDesired = "Off" + AutomaticTuningOptionModeDesiredOn AutomaticTuningOptionModeDesired = "On" +) + +func PossibleValuesForAutomaticTuningOptionModeDesired() []string { + return []string{ + string(AutomaticTuningOptionModeDesiredDefault), + string(AutomaticTuningOptionModeDesiredOff), + string(AutomaticTuningOptionModeDesiredOn), + } +} + +func (s *AutomaticTuningOptionModeDesired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningOptionModeDesired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningOptionModeDesired(input string) (*AutomaticTuningOptionModeDesired, error) { + vals := map[string]AutomaticTuningOptionModeDesired{ + "default": AutomaticTuningOptionModeDesiredDefault, + "off": AutomaticTuningOptionModeDesiredOff, + "on": AutomaticTuningOptionModeDesiredOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningOptionModeDesired(input) + return &out, nil +} + +type AutomaticTuningServerMode string + +const ( + AutomaticTuningServerModeAuto AutomaticTuningServerMode = "Auto" + AutomaticTuningServerModeCustom AutomaticTuningServerMode = "Custom" + AutomaticTuningServerModeUnspecified AutomaticTuningServerMode = "Unspecified" +) + +func PossibleValuesForAutomaticTuningServerMode() []string { + return []string{ + string(AutomaticTuningServerModeAuto), + string(AutomaticTuningServerModeCustom), + string(AutomaticTuningServerModeUnspecified), + } +} + +func (s *AutomaticTuningServerMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningServerMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningServerMode(input string) (*AutomaticTuningServerMode, error) { + vals := map[string]AutomaticTuningServerMode{ + "auto": AutomaticTuningServerModeAuto, + "custom": AutomaticTuningServerModeCustom, + "unspecified": AutomaticTuningServerModeUnspecified, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningServerMode(input) + return &out, nil +} + +type AutomaticTuningServerReason string + +const ( + AutomaticTuningServerReasonAutoConfigured AutomaticTuningServerReason = "AutoConfigured" + AutomaticTuningServerReasonDefault AutomaticTuningServerReason = "Default" + AutomaticTuningServerReasonDisabled AutomaticTuningServerReason = "Disabled" +) + +func PossibleValuesForAutomaticTuningServerReason() []string { + return []string{ + string(AutomaticTuningServerReasonAutoConfigured), + string(AutomaticTuningServerReasonDefault), + string(AutomaticTuningServerReasonDisabled), + } +} + +func (s *AutomaticTuningServerReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomaticTuningServerReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomaticTuningServerReason(input string) (*AutomaticTuningServerReason, error) { + vals := map[string]AutomaticTuningServerReason{ + "autoconfigured": AutomaticTuningServerReasonAutoConfigured, + "default": AutomaticTuningServerReasonDefault, + "disabled": AutomaticTuningServerReasonDisabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomaticTuningServerReason(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/method_get.go b/resource-manager/sql/2023-08-01/serverautomatictuning/method_get.go new file mode 100644 index 00000000000..f33223e7cb8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/method_get.go @@ -0,0 +1,55 @@ +package serverautomatictuning + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerAutomaticTuning +} + +// Get ... +func (c ServerAutomaticTuningClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/automaticTuning/current", 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 ServerAutomaticTuning + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/method_update.go b/resource-manager/sql/2023-08-01/serverautomatictuning/method_update.go new file mode 100644 index 00000000000..7be0bdc82e9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/method_update.go @@ -0,0 +1,59 @@ +package serverautomatictuning + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerAutomaticTuning +} + +// Update ... +func (c ServerAutomaticTuningClient) Update(ctx context.Context, id commonids.SqlServerId, input ServerAutomaticTuning) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/automaticTuning/current", 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 ServerAutomaticTuning + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserveroptions.go b/resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserveroptions.go new file mode 100644 index 00000000000..e173b09ada1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserveroptions.go @@ -0,0 +1,11 @@ +package serverautomatictuning + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomaticTuningServerOptions struct { + ActualState *AutomaticTuningOptionModeActual `json:"actualState,omitempty"` + DesiredState *AutomaticTuningOptionModeDesired `json:"desiredState,omitempty"` + ReasonCode *int64 `json:"reasonCode,omitempty"` + ReasonDesc *AutomaticTuningServerReason `json:"reasonDesc,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserverproperties.go b/resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserverproperties.go new file mode 100644 index 00000000000..efa12094c69 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/model_automatictuningserverproperties.go @@ -0,0 +1,10 @@ +package serverautomatictuning + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomaticTuningServerProperties struct { + ActualState *AutomaticTuningServerMode `json:"actualState,omitempty"` + DesiredState *AutomaticTuningServerMode `json:"desiredState,omitempty"` + Options *map[string]AutomaticTuningServerOptions `json:"options,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/model_serverautomatictuning.go b/resource-manager/sql/2023-08-01/serverautomatictuning/model_serverautomatictuning.go new file mode 100644 index 00000000000..e8e830acd0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/model_serverautomatictuning.go @@ -0,0 +1,11 @@ +package serverautomatictuning + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerAutomaticTuning struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AutomaticTuningServerProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverautomatictuning/version.go b/resource-manager/sql/2023-08-01/serverautomatictuning/version.go new file mode 100644 index 00000000000..1036e9da36b --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverautomatictuning/version.go @@ -0,0 +1,10 @@ +package serverautomatictuning + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverautomatictuning/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/README.md b/resource-manager/sql/2023-08-01/serverazureadadministrators/README.md new file mode 100644 index 00000000000..4a5de47dea1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverazureadadministrators` Documentation + +The `serverazureadadministrators` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverazureadadministrators" +``` + + +### Client Initialization + +```go +client := serverazureadadministrators.NewServerAzureADAdministratorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAzureADAdministratorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serverazureadadministrators.ServerAzureADAdministrator{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADAdministratorsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADAdministratorsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerAzureADAdministratorsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/client.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/client.go new file mode 100644 index 00000000000..47d3cf27389 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/client.go @@ -0,0 +1,26 @@ +package serverazureadadministrators + +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 ServerAzureADAdministratorsClient struct { + Client *resourcemanager.Client +} + +func NewServerAzureADAdministratorsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerAzureADAdministratorsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverazureadadministrators", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerAzureADAdministratorsClient: %+v", err) + } + + return &ServerAzureADAdministratorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/constants.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/constants.go new file mode 100644 index 00000000000..8b02f254afd --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/constants.go @@ -0,0 +1,48 @@ +package serverazureadadministrators + +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 AdministratorType string + +const ( + AdministratorTypeActiveDirectory AdministratorType = "ActiveDirectory" +) + +func PossibleValuesForAdministratorType() []string { + return []string{ + string(AdministratorTypeActiveDirectory), + } +} + +func (s *AdministratorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdministratorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdministratorType(input string) (*AdministratorType, error) { + vals := map[string]AdministratorType{ + "activedirectory": AdministratorTypeActiveDirectory, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdministratorType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/method_createorupdate.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_createorupdate.go new file mode 100644 index 00000000000..36bca724ae9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_createorupdate.go @@ -0,0 +1,77 @@ +package serverazureadadministrators + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerAzureADAdministrator +} + +// CreateOrUpdate ... +func (c ServerAzureADAdministratorsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerAzureADAdministrator) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/administrators/ActiveDirectory", 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 ServerAzureADAdministratorsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerAzureADAdministrator) 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/sql/2023-08-01/serverazureadadministrators/method_delete.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_delete.go new file mode 100644 index 00000000000..1c6ebf93d73 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_delete.go @@ -0,0 +1,72 @@ +package serverazureadadministrators + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ServerAzureADAdministratorsClient) Delete(ctx context.Context, id commonids.SqlServerId) (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/administrators/ActiveDirectory", 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 ServerAzureADAdministratorsClient) DeleteThenPoll(ctx context.Context, id commonids.SqlServerId) 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/sql/2023-08-01/serverazureadadministrators/method_get.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_get.go new file mode 100644 index 00000000000..98ead18b09a --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_get.go @@ -0,0 +1,55 @@ +package serverazureadadministrators + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerAzureADAdministrator +} + +// Get ... +func (c ServerAzureADAdministratorsClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/administrators/ActiveDirectory", 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 ServerAzureADAdministrator + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/method_listbyserver.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_listbyserver.go new file mode 100644 index 00000000000..e6a4b34dac5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/method_listbyserver.go @@ -0,0 +1,106 @@ +package serverazureadadministrators + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerAzureADAdministrator +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerAzureADAdministrator +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerAzureADAdministratorsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/administrators", 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 *[]ServerAzureADAdministrator `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerAzureADAdministratorsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerAzureADAdministratorOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerAzureADAdministratorsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerAzureADAdministratorOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerAzureADAdministrator, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/model_administratorproperties.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/model_administratorproperties.go new file mode 100644 index 00000000000..b98b705d824 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/model_administratorproperties.go @@ -0,0 +1,12 @@ +package serverazureadadministrators + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AdministratorProperties struct { + AdministratorType *AdministratorType `json:"administratorType,omitempty"` + AzureADOnlyAuthentication *bool `json:"azureADOnlyAuthentication,omitempty"` + Login string `json:"login"` + Sid string `json:"sid"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/model_serverazureadadministrator.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/model_serverazureadadministrator.go new file mode 100644 index 00000000000..22154139efd --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/model_serverazureadadministrator.go @@ -0,0 +1,11 @@ +package serverazureadadministrators + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerAzureADAdministrator struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AdministratorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverazureadadministrators/predicates.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/predicates.go new file mode 100644 index 00000000000..8049433d6c4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/predicates.go @@ -0,0 +1,27 @@ +package serverazureadadministrators + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerAzureADAdministratorOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerAzureADAdministratorOperationPredicate) Matches(input ServerAzureADAdministrator) 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/sql/2023-08-01/serverazureadadministrators/version.go b/resource-manager/sql/2023-08-01/serverazureadadministrators/version.go new file mode 100644 index 00000000000..fe7c3d90412 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadadministrators/version.go @@ -0,0 +1,10 @@ +package serverazureadadministrators + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverazureadadministrators/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/README.md b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/README.md new file mode 100644 index 00000000000..f996e3701ae --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverazureadonlyauthentications` Documentation + +The `serverazureadonlyauthentications` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverazureadonlyauthentications" +``` + + +### Client Initialization + +```go +client := serverazureadonlyauthentications.NewServerAzureADOnlyAuthenticationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAzureADOnlyAuthenticationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serverazureadonlyauthentications.ServerAzureADOnlyAuthentication{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADOnlyAuthenticationsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADOnlyAuthenticationsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerAzureADOnlyAuthenticationsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/client.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/client.go new file mode 100644 index 00000000000..14d36937a75 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/client.go @@ -0,0 +1,26 @@ +package serverazureadonlyauthentications + +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 ServerAzureADOnlyAuthenticationsClient struct { + Client *resourcemanager.Client +} + +func NewServerAzureADOnlyAuthenticationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerAzureADOnlyAuthenticationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverazureadonlyauthentications", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerAzureADOnlyAuthenticationsClient: %+v", err) + } + + return &ServerAzureADOnlyAuthenticationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_createorupdate.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_createorupdate.go new file mode 100644 index 00000000000..634157b810c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_createorupdate.go @@ -0,0 +1,77 @@ +package serverazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerAzureADOnlyAuthentication +} + +// CreateOrUpdate ... +func (c ServerAzureADOnlyAuthenticationsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerAzureADOnlyAuthentication) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ServerAzureADOnlyAuthenticationsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerAzureADOnlyAuthentication) 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/sql/2023-08-01/serverazureadonlyauthentications/method_delete.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_delete.go new file mode 100644 index 00000000000..d047fcc355e --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_delete.go @@ -0,0 +1,72 @@ +package serverazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ServerAzureADOnlyAuthenticationsClient) Delete(ctx context.Context, id commonids.SqlServerId) (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/azureADOnlyAuthentications/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 ServerAzureADOnlyAuthenticationsClient) DeleteThenPoll(ctx context.Context, id commonids.SqlServerId) 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/sql/2023-08-01/serverazureadonlyauthentications/method_get.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_get.go new file mode 100644 index 00000000000..937c73a5697 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_get.go @@ -0,0 +1,55 @@ +package serverazureadonlyauthentications + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerAzureADOnlyAuthentication +} + +// Get ... +func (c ServerAzureADOnlyAuthenticationsClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications/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 ServerAzureADOnlyAuthentication + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_listbyserver.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_listbyserver.go new file mode 100644 index 00000000000..96d5964f0ee --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/method_listbyserver.go @@ -0,0 +1,106 @@ +package serverazureadonlyauthentications + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerAzureADOnlyAuthentication +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerAzureADOnlyAuthentication +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerAzureADOnlyAuthenticationsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications", 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 *[]ServerAzureADOnlyAuthentication `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerAzureADOnlyAuthenticationsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerAzureADOnlyAuthenticationOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerAzureADOnlyAuthenticationsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerAzureADOnlyAuthenticationOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerAzureADOnlyAuthentication, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_azureadonlyauthproperties.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_azureadonlyauthproperties.go new file mode 100644 index 00000000000..62270a32363 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_azureadonlyauthproperties.go @@ -0,0 +1,8 @@ +package serverazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthProperties struct { + AzureADOnlyAuthentication bool `json:"azureADOnlyAuthentication"` +} diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go new file mode 100644 index 00000000000..814643ee633 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go @@ -0,0 +1,11 @@ +package serverazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerAzureADOnlyAuthentication struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureADOnlyAuthProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/predicates.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/predicates.go new file mode 100644 index 00000000000..fa774ebe409 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/predicates.go @@ -0,0 +1,27 @@ +package serverazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerAzureADOnlyAuthenticationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerAzureADOnlyAuthenticationOperationPredicate) Matches(input ServerAzureADOnlyAuthentication) 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/sql/2023-08-01/serverazureadonlyauthentications/version.go b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/version.go new file mode 100644 index 00000000000..5adca239876 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverazureadonlyauthentications/version.go @@ -0,0 +1,10 @@ +package serverazureadonlyauthentications + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverazureadonlyauthentications/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/README.md b/resource-manager/sql/2023-08-01/serverconfigurationoptions/README.md new file mode 100644 index 00000000000..221fda33a7a --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverconfigurationoptions` Documentation + +The `serverconfigurationoptions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverconfigurationoptions" +``` + + +### Client Initialization + +```go +client := serverconfigurationoptions.NewServerConfigurationOptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerConfigurationOptionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := serverconfigurationoptions.ServerConfigurationOption{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerConfigurationOptionsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `ServerConfigurationOptionsClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByManagedInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByManagedInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/client.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/client.go new file mode 100644 index 00000000000..18fdd2d4b4c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/client.go @@ -0,0 +1,26 @@ +package serverconfigurationoptions + +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 ServerConfigurationOptionsClient struct { + Client *resourcemanager.Client +} + +func NewServerConfigurationOptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerConfigurationOptionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverconfigurationoptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerConfigurationOptionsClient: %+v", err) + } + + return &ServerConfigurationOptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/constants.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/constants.go new file mode 100644 index 00000000000..df7a45c0b50 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/constants.go @@ -0,0 +1,60 @@ +package serverconfigurationoptions + +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 ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateFailed), + string(ProvisioningStateInProgress), + 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{ + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "failed": ProvisioningStateFailed, + "inprogress": ProvisioningStateInProgress, + "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 +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_createorupdate.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_createorupdate.go new file mode 100644 index 00000000000..8f168b906fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_createorupdate.go @@ -0,0 +1,75 @@ +package serverconfigurationoptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerConfigurationOption +} + +// CreateOrUpdate ... +func (c ServerConfigurationOptionsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input ServerConfigurationOption) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/serverConfigurationOptions/allowPolybaseExport", 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 ServerConfigurationOptionsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlManagedInstanceId, input ServerConfigurationOption) 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/sql/2023-08-01/serverconfigurationoptions/method_get.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_get.go new file mode 100644 index 00000000000..6ed76291506 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_get.go @@ -0,0 +1,55 @@ +package serverconfigurationoptions + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerConfigurationOption +} + +// Get ... +func (c ServerConfigurationOptionsClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/serverConfigurationOptions/allowPolybaseExport", 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 ServerConfigurationOption + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_listbymanagedinstance.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_listbymanagedinstance.go new file mode 100644 index 00000000000..eb3f3fe6a8d --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/method_listbymanagedinstance.go @@ -0,0 +1,106 @@ +package serverconfigurationoptions + +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 ListByManagedInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerConfigurationOption +} + +type ListByManagedInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerConfigurationOption +} + +type ListByManagedInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByManagedInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByManagedInstance ... +func (c ServerConfigurationOptionsClient) ListByManagedInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByManagedInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByManagedInstanceCustomPager{}, + Path: fmt.Sprintf("%s/serverConfigurationOptions", 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 *[]ServerConfigurationOption `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByManagedInstanceComplete retrieves all the results into a single object +func (c ServerConfigurationOptionsClient) ListByManagedInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByManagedInstanceCompleteResult, error) { + return c.ListByManagedInstanceCompleteMatchingPredicate(ctx, id, ServerConfigurationOptionOperationPredicate{}) +} + +// ListByManagedInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerConfigurationOptionsClient) ListByManagedInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ServerConfigurationOptionOperationPredicate) (result ListByManagedInstanceCompleteResult, err error) { + items := make([]ServerConfigurationOption, 0) + + resp, err := c.ListByManagedInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByManagedInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoption.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoption.go new file mode 100644 index 00000000000..1e8da4d92d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoption.go @@ -0,0 +1,11 @@ +package serverconfigurationoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConfigurationOption struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerConfigurationOptionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoptionproperties.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoptionproperties.go new file mode 100644 index 00000000000..c93370f6b20 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/model_serverconfigurationoptionproperties.go @@ -0,0 +1,9 @@ +package serverconfigurationoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConfigurationOptionProperties struct { + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ServerConfigurationOptionValue int64 `json:"serverConfigurationOptionValue"` +} diff --git a/resource-manager/sql/2023-08-01/serverconfigurationoptions/predicates.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/predicates.go new file mode 100644 index 00000000000..827eda2a4df --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/predicates.go @@ -0,0 +1,27 @@ +package serverconfigurationoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConfigurationOptionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerConfigurationOptionOperationPredicate) Matches(input ServerConfigurationOption) 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/sql/2023-08-01/serverconfigurationoptions/version.go b/resource-manager/sql/2023-08-01/serverconfigurationoptions/version.go new file mode 100644 index 00000000000..ee296f56dfa --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconfigurationoptions/version.go @@ -0,0 +1,10 @@ +package serverconfigurationoptions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverconfigurationoptions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/README.md b/resource-manager/sql/2023-08-01/serverconnectionpolicies/README.md new file mode 100644 index 00000000000..26af077761f --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverconnectionpolicies` Documentation + +The `serverconnectionpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverconnectionpolicies" +``` + + +### Client Initialization + +```go +client := serverconnectionpolicies.NewServerConnectionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerConnectionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serverconnectionpolicies.ServerConnectionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerConnectionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerConnectionPoliciesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/client.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/client.go new file mode 100644 index 00000000000..a4b5aa95d54 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/client.go @@ -0,0 +1,26 @@ +package serverconnectionpolicies + +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 ServerConnectionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewServerConnectionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerConnectionPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverconnectionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerConnectionPoliciesClient: %+v", err) + } + + return &ServerConnectionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/constants.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/constants.go new file mode 100644 index 00000000000..1236871f47b --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/constants.go @@ -0,0 +1,54 @@ +package serverconnectionpolicies + +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 ServerConnectionType string + +const ( + ServerConnectionTypeDefault ServerConnectionType = "Default" + ServerConnectionTypeProxy ServerConnectionType = "Proxy" + ServerConnectionTypeRedirect ServerConnectionType = "Redirect" +) + +func PossibleValuesForServerConnectionType() []string { + return []string{ + string(ServerConnectionTypeDefault), + string(ServerConnectionTypeProxy), + string(ServerConnectionTypeRedirect), + } +} + +func (s *ServerConnectionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerConnectionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerConnectionType(input string) (*ServerConnectionType, error) { + vals := map[string]ServerConnectionType{ + "default": ServerConnectionTypeDefault, + "proxy": ServerConnectionTypeProxy, + "redirect": ServerConnectionTypeRedirect, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerConnectionType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..dced265b945 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package serverconnectionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerConnectionPolicy +} + +// CreateOrUpdate ... +func (c ServerConnectionPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerConnectionPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/connectionPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ServerConnectionPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerConnectionPolicy) 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/sql/2023-08-01/serverconnectionpolicies/method_get.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_get.go new file mode 100644 index 00000000000..48f33b38281 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_get.go @@ -0,0 +1,55 @@ +package serverconnectionpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerConnectionPolicy +} + +// Get ... +func (c ServerConnectionPoliciesClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/connectionPolicies/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 ServerConnectionPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_listbyserver.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_listbyserver.go new file mode 100644 index 00000000000..0eb69736366 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/method_listbyserver.go @@ -0,0 +1,106 @@ +package serverconnectionpolicies + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerConnectionPolicy +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerConnectionPolicy +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerConnectionPoliciesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/connectionPolicies", 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 *[]ServerConnectionPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerConnectionPoliciesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerConnectionPolicyOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerConnectionPoliciesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerConnectionPolicyOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerConnectionPolicy, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicy.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicy.go new file mode 100644 index 00000000000..7a9ebda7b43 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicy.go @@ -0,0 +1,13 @@ +package serverconnectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConnectionPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerConnectionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicyproperties.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicyproperties.go new file mode 100644 index 00000000000..9926fa202cb --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/model_serverconnectionpolicyproperties.go @@ -0,0 +1,8 @@ +package serverconnectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConnectionPolicyProperties struct { + ConnectionType ServerConnectionType `json:"connectionType"` +} diff --git a/resource-manager/sql/2023-08-01/serverconnectionpolicies/predicates.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/predicates.go new file mode 100644 index 00000000000..4a6e9697786 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/predicates.go @@ -0,0 +1,37 @@ +package serverconnectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerConnectionPolicyOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ServerConnectionPolicyOperationPredicate) Matches(input ServerConnectionPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/serverconnectionpolicies/version.go b/resource-manager/sql/2023-08-01/serverconnectionpolicies/version.go new file mode 100644 index 00000000000..37c2f6aff91 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverconnectionpolicies/version.go @@ -0,0 +1,10 @@ +package serverconnectionpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverconnectionpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/README.md b/resource-manager/sql/2023-08-01/serverdevopsaudit/README.md new file mode 100644 index 00000000000..a44302d5f65 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverdevopsaudit` Documentation + +The `serverdevopsaudit` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverdevopsaudit" +``` + + +### Client Initialization + +```go +client := serverdevopsaudit.NewServerDevOpsAuditClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerDevOpsAuditClient.SettingsCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serverdevopsaudit.ServerDevOpsAuditingSettings{ + // ... +} + + +if err := client.SettingsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerDevOpsAuditClient.SettingsGet` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.SettingsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerDevOpsAuditClient.SettingsListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.SettingsListByServer(ctx, id)` can be used to do batched pagination +items, err := client.SettingsListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/client.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/client.go new file mode 100644 index 00000000000..5e560080c0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/client.go @@ -0,0 +1,26 @@ +package serverdevopsaudit + +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 ServerDevOpsAuditClient struct { + Client *resourcemanager.Client +} + +func NewServerDevOpsAuditClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerDevOpsAuditClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverdevopsaudit", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerDevOpsAuditClient: %+v", err) + } + + return &ServerDevOpsAuditClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/constants.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/constants.go new file mode 100644 index 00000000000..12a7c65bebf --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/constants.go @@ -0,0 +1,51 @@ +package serverdevopsaudit + +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 BlobAuditingPolicyState string + +const ( + BlobAuditingPolicyStateDisabled BlobAuditingPolicyState = "Disabled" + BlobAuditingPolicyStateEnabled BlobAuditingPolicyState = "Enabled" +) + +func PossibleValuesForBlobAuditingPolicyState() []string { + return []string{ + string(BlobAuditingPolicyStateDisabled), + string(BlobAuditingPolicyStateEnabled), + } +} + +func (s *BlobAuditingPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobAuditingPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBlobAuditingPolicyState(input string) (*BlobAuditingPolicyState, error) { + vals := map[string]BlobAuditingPolicyState{ + "disabled": BlobAuditingPolicyStateDisabled, + "enabled": BlobAuditingPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BlobAuditingPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingscreateorupdate.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingscreateorupdate.go new file mode 100644 index 00000000000..7d3029ef8ed --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingscreateorupdate.go @@ -0,0 +1,76 @@ +package serverdevopsaudit + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SettingsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerDevOpsAuditingSettings +} + +// SettingsCreateOrUpdate ... +func (c ServerDevOpsAuditClient) SettingsCreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerDevOpsAuditingSettings) (result SettingsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/devOpsAuditingSettings/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SettingsCreateOrUpdateThenPoll performs SettingsCreateOrUpdate then polls until it's completed +func (c ServerDevOpsAuditClient) SettingsCreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerDevOpsAuditingSettings) error { + result, err := c.SettingsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SettingsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SettingsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingsget.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingsget.go new file mode 100644 index 00000000000..6f6c514f848 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingsget.go @@ -0,0 +1,55 @@ +package serverdevopsaudit + +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 SettingsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerDevOpsAuditingSettings +} + +// SettingsGet ... +func (c ServerDevOpsAuditClient) SettingsGet(ctx context.Context, id commonids.SqlServerId) (result SettingsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devOpsAuditingSettings/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 ServerDevOpsAuditingSettings + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingslistbyserver.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingslistbyserver.go new file mode 100644 index 00000000000..39e50f7940a --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/method_settingslistbyserver.go @@ -0,0 +1,106 @@ +package serverdevopsaudit + +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 SettingsListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerDevOpsAuditingSettings +} + +type SettingsListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerDevOpsAuditingSettings +} + +type SettingsListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *SettingsListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// SettingsListByServer ... +func (c ServerDevOpsAuditClient) SettingsListByServer(ctx context.Context, id commonids.SqlServerId) (result SettingsListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &SettingsListByServerCustomPager{}, + Path: fmt.Sprintf("%s/devOpsAuditingSettings", 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 *[]ServerDevOpsAuditingSettings `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SettingsListByServerComplete retrieves all the results into a single object +func (c ServerDevOpsAuditClient) SettingsListByServerComplete(ctx context.Context, id commonids.SqlServerId) (SettingsListByServerCompleteResult, error) { + return c.SettingsListByServerCompleteMatchingPredicate(ctx, id, ServerDevOpsAuditingSettingsOperationPredicate{}) +} + +// SettingsListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerDevOpsAuditClient) SettingsListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerDevOpsAuditingSettingsOperationPredicate) (result SettingsListByServerCompleteResult, err error) { + items := make([]ServerDevOpsAuditingSettings, 0) + + resp, err := c.SettingsListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SettingsListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditingsettings.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditingsettings.go new file mode 100644 index 00000000000..c62032b1adc --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditingsettings.go @@ -0,0 +1,16 @@ +package serverdevopsaudit + +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 ServerDevOpsAuditingSettings struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerDevOpsAuditSettingsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go new file mode 100644 index 00000000000..bfed39b175b --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go @@ -0,0 +1,13 @@ +package serverdevopsaudit + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerDevOpsAuditSettingsProperties struct { + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsManagedIdentityInUse *bool `json:"isManagedIdentityInUse,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverdevopsaudit/predicates.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/predicates.go new file mode 100644 index 00000000000..249e3853d29 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/predicates.go @@ -0,0 +1,27 @@ +package serverdevopsaudit + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerDevOpsAuditingSettingsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerDevOpsAuditingSettingsOperationPredicate) Matches(input ServerDevOpsAuditingSettings) 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/sql/2023-08-01/serverdevopsaudit/version.go b/resource-manager/sql/2023-08-01/serverdevopsaudit/version.go new file mode 100644 index 00000000000..a368672be60 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdevopsaudit/version.go @@ -0,0 +1,10 @@ +package serverdevopsaudit + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverdevopsaudit/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/README.md b/resource-manager/sql/2023-08-01/serverdnsaliases/README.md new file mode 100644 index 00000000000..7369b5b4554 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/README.md @@ -0,0 +1,95 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverdnsaliases` Documentation + +The `serverdnsaliases` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverdnsaliases" +``` + + +### Client Initialization + +```go +client := serverdnsaliases.NewServerDnsAliasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerDnsAliasesClient.Acquire` + +```go +ctx := context.TODO() +id := serverdnsaliases.NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "dnsAliasName") + +payload := serverdnsaliases.ServerDnsAliasAcquisition{ + // ... +} + + +if err := client.AcquireThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerDnsAliasesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serverdnsaliases.NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "dnsAliasName") + +if err := client.CreateOrUpdateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerDnsAliasesClient.Delete` + +```go +ctx := context.TODO() +id := serverdnsaliases.NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "dnsAliasName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerDnsAliasesClient.Get` + +```go +ctx := context.TODO() +id := serverdnsaliases.NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "dnsAliasName") + +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: `ServerDnsAliasesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/client.go b/resource-manager/sql/2023-08-01/serverdnsaliases/client.go new file mode 100644 index 00000000000..7f03630ea40 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/client.go @@ -0,0 +1,26 @@ +package serverdnsaliases + +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 ServerDnsAliasesClient struct { + Client *resourcemanager.Client +} + +func NewServerDnsAliasesClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerDnsAliasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverdnsaliases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerDnsAliasesClient: %+v", err) + } + + return &ServerDnsAliasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias.go b/resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias.go new file mode 100644 index 00000000000..ffc5b029ee0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias.go @@ -0,0 +1,139 @@ +package serverdnsaliases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DnsAliasId{}) +} + +var _ resourceids.ResourceId = &DnsAliasId{} + +// DnsAliasId is a struct representing the Resource ID for a Dns Alias +type DnsAliasId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DnsAliasName string +} + +// NewDnsAliasID returns a new DnsAliasId struct +func NewDnsAliasID(subscriptionId string, resourceGroupName string, serverName string, dnsAliasName string) DnsAliasId { + return DnsAliasId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DnsAliasName: dnsAliasName, + } +} + +// ParseDnsAliasID parses 'input' into a DnsAliasId +func ParseDnsAliasID(input string) (*DnsAliasId, error) { + parser := resourceids.NewParserFromResourceIdType(&DnsAliasId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DnsAliasId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDnsAliasIDInsensitively parses 'input' case-insensitively into a DnsAliasId +// note: this method should only be used for API response data and not user input +func ParseDnsAliasIDInsensitively(input string) (*DnsAliasId, error) { + parser := resourceids.NewParserFromResourceIdType(&DnsAliasId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DnsAliasId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DnsAliasId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DnsAliasName, ok = input.Parsed["dnsAliasName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dnsAliasName", input) + } + + return nil +} + +// ValidateDnsAliasID checks that 'input' can be parsed as a Dns Alias ID +func ValidateDnsAliasID(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 := ParseDnsAliasID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dns Alias ID +func (id DnsAliasId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/dnsAliases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DnsAliasName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dns Alias ID +func (id DnsAliasId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDnsAliases", "dnsAliases", "dnsAliases"), + resourceids.UserSpecifiedSegment("dnsAliasName", "dnsAliasName"), + } +} + +// String returns a human-readable description of this Dns Alias ID +func (id DnsAliasId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Dns Alias Name: %q", id.DnsAliasName), + } + return fmt.Sprintf("Dns Alias (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias_test.go b/resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias_test.go new file mode 100644 index 00000000000..bc2f4c01f4d --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/id_dnsalias_test.go @@ -0,0 +1,327 @@ +package serverdnsaliases + +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 = &DnsAliasId{} + +func TestNewDnsAliasID(t *testing.T) { + id := NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "dnsAliasName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DnsAliasName != "dnsAliasName" { + t.Fatalf("Expected %q but got %q for Segment 'DnsAliasName'", id.DnsAliasName, "dnsAliasName") + } +} + +func TestFormatDnsAliasID(t *testing.T) { + actual := NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "dnsAliasName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases/dnsAliasName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDnsAliasID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DnsAliasId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases/dnsAliasName", + Expected: &DnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DnsAliasName: "dnsAliasName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases/dnsAliasName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDnsAliasID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DnsAliasName != v.Expected.DnsAliasName { + t.Fatalf("Expected %q but got %q for DnsAliasName", v.Expected.DnsAliasName, actual.DnsAliasName) + } + + } +} + +func TestParseDnsAliasIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DnsAliasId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dNsAlIaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases/dnsAliasName", + Expected: &DnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DnsAliasName: "dnsAliasName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/dnsAliases/dnsAliasName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dNsAlIaSeS/dNsAlIaSnAmE", + Expected: &DnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DnsAliasName: "dNsAlIaSnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dNsAlIaSeS/dNsAlIaSnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDnsAliasIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DnsAliasName != v.Expected.DnsAliasName { + t.Fatalf("Expected %q but got %q for DnsAliasName", v.Expected.DnsAliasName, actual.DnsAliasName) + } + + } +} + +func TestSegmentsForDnsAliasId(t *testing.T) { + segments := DnsAliasId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DnsAliasId 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/sql/2023-08-01/serverdnsaliases/method_acquire.go b/resource-manager/sql/2023-08-01/serverdnsaliases/method_acquire.go new file mode 100644 index 00000000000..eb2da929734 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/method_acquire.go @@ -0,0 +1,75 @@ +package serverdnsaliases + +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 AcquireOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerDnsAlias +} + +// Acquire ... +func (c ServerDnsAliasesClient) Acquire(ctx context.Context, id DnsAliasId, input ServerDnsAliasAcquisition) (result AcquireOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/acquire", 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 +} + +// AcquireThenPoll performs Acquire then polls until it's completed +func (c ServerDnsAliasesClient) AcquireThenPoll(ctx context.Context, id DnsAliasId, input ServerDnsAliasAcquisition) error { + result, err := c.Acquire(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Acquire: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Acquire: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/method_createorupdate.go b/resource-manager/sql/2023-08-01/serverdnsaliases/method_createorupdate.go new file mode 100644 index 00000000000..e8bb8910198 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/method_createorupdate.go @@ -0,0 +1,72 @@ +package serverdnsaliases + +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 *ServerDnsAlias +} + +// CreateOrUpdate ... +func (c ServerDnsAliasesClient) CreateOrUpdate(ctx context.Context, id DnsAliasId) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ServerDnsAliasesClient) CreateOrUpdateThenPoll(ctx context.Context, id DnsAliasId) error { + result, err := c.CreateOrUpdate(ctx, id) + 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/sql/2023-08-01/serverdnsaliases/method_delete.go b/resource-manager/sql/2023-08-01/serverdnsaliases/method_delete.go new file mode 100644 index 00000000000..3e1cb44e1e8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/method_delete.go @@ -0,0 +1,71 @@ +package serverdnsaliases + +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 ServerDnsAliasesClient) Delete(ctx context.Context, id DnsAliasId) (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 ServerDnsAliasesClient) DeleteThenPoll(ctx context.Context, id DnsAliasId) 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/sql/2023-08-01/serverdnsaliases/method_get.go b/resource-manager/sql/2023-08-01/serverdnsaliases/method_get.go new file mode 100644 index 00000000000..7c3666bd13e --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/method_get.go @@ -0,0 +1,53 @@ +package serverdnsaliases + +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 *ServerDnsAlias +} + +// Get ... +func (c ServerDnsAliasesClient) Get(ctx context.Context, id DnsAliasId) (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 ServerDnsAlias + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/method_listbyserver.go b/resource-manager/sql/2023-08-01/serverdnsaliases/method_listbyserver.go new file mode 100644 index 00000000000..b67f67765b7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/method_listbyserver.go @@ -0,0 +1,106 @@ +package serverdnsaliases + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerDnsAlias +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerDnsAlias +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerDnsAliasesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/dnsAliases", 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 *[]ServerDnsAlias `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerDnsAliasesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerDnsAliasOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerDnsAliasesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerDnsAliasOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerDnsAlias, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsalias.go b/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsalias.go new file mode 100644 index 00000000000..8c713338298 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsalias.go @@ -0,0 +1,11 @@ +package serverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerDnsAlias struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerDnsAliasProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasacquisition.go b/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasacquisition.go new file mode 100644 index 00000000000..c8a5279af6e --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasacquisition.go @@ -0,0 +1,8 @@ +package serverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerDnsAliasAcquisition struct { + OldServerDnsAliasId string `json:"oldServerDnsAliasId"` +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasproperties.go b/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasproperties.go new file mode 100644 index 00000000000..a65b002fdf4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/model_serverdnsaliasproperties.go @@ -0,0 +1,8 @@ +package serverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerDnsAliasProperties struct { + AzureDnsRecord *string `json:"azureDnsRecord,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverdnsaliases/predicates.go b/resource-manager/sql/2023-08-01/serverdnsaliases/predicates.go new file mode 100644 index 00000000000..964f164db6c --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/predicates.go @@ -0,0 +1,27 @@ +package serverdnsaliases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerDnsAliasOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerDnsAliasOperationPredicate) Matches(input ServerDnsAlias) 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/sql/2023-08-01/serverdnsaliases/version.go b/resource-manager/sql/2023-08-01/serverdnsaliases/version.go new file mode 100644 index 00000000000..9639b38ef39 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverdnsaliases/version.go @@ -0,0 +1,10 @@ +package serverdnsaliases + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverdnsaliases/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/README.md b/resource-manager/sql/2023-08-01/serverkeys/README.md new file mode 100644 index 00000000000..eeb370863d9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverkeys` Documentation + +The `serverkeys` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverkeys" +``` + + +### Client Initialization + +```go +client := serverkeys.NewServerKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerKeysClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serverkeys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "keyName") + +payload := serverkeys.ServerKey{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerKeysClient.Delete` + +```go +ctx := context.TODO() +id := serverkeys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "keyName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerKeysClient.Get` + +```go +ctx := context.TODO() +id := serverkeys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "keyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerKeysClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverkeys/client.go b/resource-manager/sql/2023-08-01/serverkeys/client.go new file mode 100644 index 00000000000..0616b182cbb --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/client.go @@ -0,0 +1,26 @@ +package serverkeys + +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 ServerKeysClient struct { + Client *resourcemanager.Client +} + +func NewServerKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerKeysClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverkeys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerKeysClient: %+v", err) + } + + return &ServerKeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/constants.go b/resource-manager/sql/2023-08-01/serverkeys/constants.go new file mode 100644 index 00000000000..4166b27bcac --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/constants.go @@ -0,0 +1,51 @@ +package serverkeys + +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 ServerKeyType string + +const ( + ServerKeyTypeAzureKeyVault ServerKeyType = "AzureKeyVault" + ServerKeyTypeServiceManaged ServerKeyType = "ServiceManaged" +) + +func PossibleValuesForServerKeyType() []string { + return []string{ + string(ServerKeyTypeAzureKeyVault), + string(ServerKeyTypeServiceManaged), + } +} + +func (s *ServerKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerKeyType(input string) (*ServerKeyType, error) { + vals := map[string]ServerKeyType{ + "azurekeyvault": ServerKeyTypeAzureKeyVault, + "servicemanaged": ServerKeyTypeServiceManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/id_key.go b/resource-manager/sql/2023-08-01/serverkeys/id_key.go new file mode 100644 index 00000000000..916ff4d3059 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/id_key.go @@ -0,0 +1,139 @@ +package serverkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&KeyId{}) +} + +var _ resourceids.ResourceId = &KeyId{} + +// KeyId is a struct representing the Resource ID for a Key +type KeyId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + KeyName string +} + +// NewKeyID returns a new KeyId struct +func NewKeyID(subscriptionId string, resourceGroupName string, serverName string, keyName string) KeyId { + return KeyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + KeyName: keyName, + } +} + +// ParseKeyID parses 'input' into a KeyId +func ParseKeyID(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&KeyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := KeyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseKeyIDInsensitively parses 'input' case-insensitively into a KeyId +// note: this method should only be used for API response data and not user input +func ParseKeyIDInsensitively(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&KeyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := KeyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *KeyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.KeyName, ok = input.Parsed["keyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "keyName", input) + } + + return nil +} + +// ValidateKeyID checks that 'input' can be parsed as a Key ID +func ValidateKeyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseKeyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Key ID +func (id KeyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/keys/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.KeyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Key ID +func (id KeyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyName"), + } +} + +// String returns a human-readable description of this Key ID +func (id KeyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Key Name: %q", id.KeyName), + } + return fmt.Sprintf("Key (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/id_key_test.go b/resource-manager/sql/2023-08-01/serverkeys/id_key_test.go new file mode 100644 index 00000000000..41c9f1503cb --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/id_key_test.go @@ -0,0 +1,327 @@ +package serverkeys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &KeyId{} + +func TestNewKeyID(t *testing.T) { + id := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "keyName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.KeyName != "keyName" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyName") + } +} + +func TestFormatKeyID(t *testing.T) { + actual := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "keyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys/keyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseKeyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys/keyName", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + KeyName: "keyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys/keyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestParseKeyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys/keyName", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + KeyName: "keyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/keys/keyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/kEyS/kEyNaMe", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + KeyName: "kEyNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/kEyS/kEyNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestSegmentsForKeyId(t *testing.T) { + segments := KeyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("KeyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/method_createorupdate.go b/resource-manager/sql/2023-08-01/serverkeys/method_createorupdate.go new file mode 100644 index 00000000000..ff91afb47f7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/method_createorupdate.go @@ -0,0 +1,76 @@ +package serverkeys + +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 *ServerKey +} + +// CreateOrUpdate ... +func (c ServerKeysClient) CreateOrUpdate(ctx context.Context, id KeyId, input ServerKey) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ServerKeysClient) CreateOrUpdateThenPoll(ctx context.Context, id KeyId, input ServerKey) 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/sql/2023-08-01/serverkeys/method_delete.go b/resource-manager/sql/2023-08-01/serverkeys/method_delete.go new file mode 100644 index 00000000000..29eafab24a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/method_delete.go @@ -0,0 +1,71 @@ +package serverkeys + +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 ServerKeysClient) Delete(ctx context.Context, id KeyId) (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 ServerKeysClient) DeleteThenPoll(ctx context.Context, id KeyId) 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/sql/2023-08-01/serverkeys/method_get.go b/resource-manager/sql/2023-08-01/serverkeys/method_get.go new file mode 100644 index 00000000000..e6b4acc396a --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/method_get.go @@ -0,0 +1,53 @@ +package serverkeys + +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 *ServerKey +} + +// Get ... +func (c ServerKeysClient) Get(ctx context.Context, id KeyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ServerKey + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/method_listbyserver.go b/resource-manager/sql/2023-08-01/serverkeys/method_listbyserver.go new file mode 100644 index 00000000000..221552cd13f --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/method_listbyserver.go @@ -0,0 +1,106 @@ +package serverkeys + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerKey +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerKey +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerKeysClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/keys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ServerKey `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerKeysClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerKeyOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerKeysClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerKeyOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerKey, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/model_serverkey.go b/resource-manager/sql/2023-08-01/serverkeys/model_serverkey.go new file mode 100644 index 00000000000..6f1037f22bd --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/model_serverkey.go @@ -0,0 +1,13 @@ +package serverkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerKey struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerKeyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/model_serverkeyproperties.go b/resource-manager/sql/2023-08-01/serverkeys/model_serverkeyproperties.go new file mode 100644 index 00000000000..217a269c6ab --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/model_serverkeyproperties.go @@ -0,0 +1,31 @@ +package serverkeys + +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 ServerKeyProperties struct { + AutoRotationEnabled *bool `json:"autoRotationEnabled,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + ServerKeyType ServerKeyType `json:"serverKeyType"` + Subregion *string `json:"subregion,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Uri *string `json:"uri,omitempty"` +} + +func (o *ServerKeyProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ServerKeyProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serverkeys/predicates.go b/resource-manager/sql/2023-08-01/serverkeys/predicates.go new file mode 100644 index 00000000000..e0882f7257e --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/predicates.go @@ -0,0 +1,37 @@ +package serverkeys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerKeyOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ServerKeyOperationPredicate) Matches(input ServerKey) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/serverkeys/version.go b/resource-manager/sql/2023-08-01/serverkeys/version.go new file mode 100644 index 00000000000..31ec9d451dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverkeys/version.go @@ -0,0 +1,10 @@ +package serverkeys + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverkeys/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serveroperations/README.md b/resource-manager/sql/2023-08-01/serveroperations/README.md new file mode 100644 index 00000000000..1ab0d5dcd0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveroperations` Documentation + +The `serveroperations` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serveroperations" +``` + + +### Client Initialization + +```go +client := serveroperations.NewServerOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerOperationsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serveroperations/client.go b/resource-manager/sql/2023-08-01/serveroperations/client.go new file mode 100644 index 00000000000..52624fb5f18 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/client.go @@ -0,0 +1,26 @@ +package serveroperations + +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 ServerOperationsClient struct { + Client *resourcemanager.Client +} + +func NewServerOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerOperationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serveroperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerOperationsClient: %+v", err) + } + + return &ServerOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serveroperations/constants.go b/resource-manager/sql/2023-08-01/serveroperations/constants.go new file mode 100644 index 00000000000..ed2f89c21e7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/constants.go @@ -0,0 +1,63 @@ +package serveroperations + +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 ManagementOperationState string + +const ( + ManagementOperationStateCancelInProgress ManagementOperationState = "CancelInProgress" + ManagementOperationStateCancelled ManagementOperationState = "Cancelled" + ManagementOperationStateFailed ManagementOperationState = "Failed" + ManagementOperationStateInProgress ManagementOperationState = "InProgress" + ManagementOperationStatePending ManagementOperationState = "Pending" + ManagementOperationStateSucceeded ManagementOperationState = "Succeeded" +) + +func PossibleValuesForManagementOperationState() []string { + return []string{ + string(ManagementOperationStateCancelInProgress), + string(ManagementOperationStateCancelled), + string(ManagementOperationStateFailed), + string(ManagementOperationStateInProgress), + string(ManagementOperationStatePending), + string(ManagementOperationStateSucceeded), + } +} + +func (s *ManagementOperationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagementOperationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagementOperationState(input string) (*ManagementOperationState, error) { + vals := map[string]ManagementOperationState{ + "cancelinprogress": ManagementOperationStateCancelInProgress, + "cancelled": ManagementOperationStateCancelled, + "failed": ManagementOperationStateFailed, + "inprogress": ManagementOperationStateInProgress, + "pending": ManagementOperationStatePending, + "succeeded": ManagementOperationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagementOperationState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serveroperations/method_listbyserver.go b/resource-manager/sql/2023-08-01/serveroperations/method_listbyserver.go new file mode 100644 index 00000000000..5eac4638595 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/method_listbyserver.go @@ -0,0 +1,106 @@ +package serveroperations + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerOperation +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerOperation +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerOperationsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/operations", 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 *[]ServerOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerOperationsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerOperationOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerOperationsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerOperationOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerOperation, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serveroperations/model_serveroperation.go b/resource-manager/sql/2023-08-01/serveroperations/model_serveroperation.go new file mode 100644 index 00000000000..5582b368762 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/model_serveroperation.go @@ -0,0 +1,11 @@ +package serveroperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerOperation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerOperationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serveroperations/model_serveroperationproperties.go b/resource-manager/sql/2023-08-01/serveroperations/model_serveroperationproperties.go new file mode 100644 index 00000000000..b9314f3a014 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/model_serveroperationproperties.go @@ -0,0 +1,50 @@ +package serveroperations + +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 ServerOperationProperties struct { + Description *string `json:"description,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorDescription *string `json:"errorDescription,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + EstimatedCompletionTime *string `json:"estimatedCompletionTime,omitempty"` + IsCancellable *bool `json:"isCancellable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Operation *string `json:"operation,omitempty"` + OperationFriendlyName *string `json:"operationFriendlyName,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + ServerName *string `json:"serverName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *ManagementOperationState `json:"state,omitempty"` +} + +func (o *ServerOperationProperties) GetEstimatedCompletionTimeAsTime() (*time.Time, error) { + if o.EstimatedCompletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EstimatedCompletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ServerOperationProperties) SetEstimatedCompletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EstimatedCompletionTime = &formatted +} + +func (o *ServerOperationProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ServerOperationProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serveroperations/predicates.go b/resource-manager/sql/2023-08-01/serveroperations/predicates.go new file mode 100644 index 00000000000..c23369f7156 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/predicates.go @@ -0,0 +1,27 @@ +package serveroperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerOperationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerOperationOperationPredicate) Matches(input ServerOperation) 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/sql/2023-08-01/serveroperations/version.go b/resource-manager/sql/2023-08-01/serveroperations/version.go new file mode 100644 index 00000000000..1b59715c854 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serveroperations/version.go @@ -0,0 +1,10 @@ +package serveroperations + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serveroperations/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/servers/README.md b/resource-manager/sql/2023-08-01/servers/README.md new file mode 100644 index 00000000000..b63b28c8c6d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/README.md @@ -0,0 +1,167 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servers` Documentation + +The `servers` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servers" +``` + + +### Client Initialization + +```go +client := servers.NewServersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServersClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := servers.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := servers.Server{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.Get(ctx, id, servers.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServersClient.ImportDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := servers.ImportNewDatabaseDefinition{ + // ... +} + + +if err := client.ImportDatabaseThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, servers.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, servers.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ServersClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, servers.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, servers.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ServersClient.RefreshStatus` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +if err := client.RefreshStatusThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := servers.ServerUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/servers/client.go b/resource-manager/sql/2023-08-01/servers/client.go new file mode 100644 index 00000000000..806c9525000 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/client.go @@ -0,0 +1,26 @@ +package servers + +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 ServersClient struct { + Client *resourcemanager.Client +} + +func NewServersClientWithBaseURI(sdkApi sdkEnv.Api) (*ServersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "servers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServersClient: %+v", err) + } + + return &ServersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/servers/constants.go b/resource-manager/sql/2023-08-01/servers/constants.go new file mode 100644 index 00000000000..782da45a033 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/constants.go @@ -0,0 +1,564 @@ +package servers + +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 AdministratorType string + +const ( + AdministratorTypeActiveDirectory AdministratorType = "ActiveDirectory" +) + +func PossibleValuesForAdministratorType() []string { + return []string{ + string(AdministratorTypeActiveDirectory), + } +} + +func (s *AdministratorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAdministratorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAdministratorType(input string) (*AdministratorType, error) { + vals := map[string]AdministratorType{ + "activedirectory": AdministratorTypeActiveDirectory, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AdministratorType(input) + return &out, nil +} + +type CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} + +type CheckNameAvailabilityResourceType string + +const ( + CheckNameAvailabilityResourceTypeMicrosoftPointSqlServers CheckNameAvailabilityResourceType = "Microsoft.Sql/servers" +) + +func PossibleValuesForCheckNameAvailabilityResourceType() []string { + return []string{ + string(CheckNameAvailabilityResourceTypeMicrosoftPointSqlServers), + } +} + +func (s *CheckNameAvailabilityResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityResourceType(input string) (*CheckNameAvailabilityResourceType, error) { + vals := map[string]CheckNameAvailabilityResourceType{ + "microsoft.sql/servers": CheckNameAvailabilityResourceTypeMicrosoftPointSqlServers, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityResourceType(input) + return &out, nil +} + +type ExternalGovernanceStatus string + +const ( + ExternalGovernanceStatusDisabled ExternalGovernanceStatus = "Disabled" + ExternalGovernanceStatusEnabled ExternalGovernanceStatus = "Enabled" +) + +func PossibleValuesForExternalGovernanceStatus() []string { + return []string{ + string(ExternalGovernanceStatusDisabled), + string(ExternalGovernanceStatusEnabled), + } +} + +func (s *ExternalGovernanceStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExternalGovernanceStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExternalGovernanceStatus(input string) (*ExternalGovernanceStatus, error) { + vals := map[string]ExternalGovernanceStatus{ + "disabled": ExternalGovernanceStatusDisabled, + "enabled": ExternalGovernanceStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExternalGovernanceStatus(input) + return &out, nil +} + +type MinimalTlsVersion string + +const ( + MinimalTlsVersionNone MinimalTlsVersion = "None" + MinimalTlsVersionOnePointOne MinimalTlsVersion = "1.1" + MinimalTlsVersionOnePointThree MinimalTlsVersion = "1.3" + MinimalTlsVersionOnePointTwo MinimalTlsVersion = "1.2" + MinimalTlsVersionOnePointZero MinimalTlsVersion = "1.0" +) + +func PossibleValuesForMinimalTlsVersion() []string { + return []string{ + string(MinimalTlsVersionNone), + string(MinimalTlsVersionOnePointOne), + string(MinimalTlsVersionOnePointThree), + string(MinimalTlsVersionOnePointTwo), + string(MinimalTlsVersionOnePointZero), + } +} + +func (s *MinimalTlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMinimalTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMinimalTlsVersion(input string) (*MinimalTlsVersion, error) { + vals := map[string]MinimalTlsVersion{ + "none": MinimalTlsVersionNone, + "1.1": MinimalTlsVersionOnePointOne, + "1.3": MinimalTlsVersionOnePointThree, + "1.2": MinimalTlsVersionOnePointTwo, + "1.0": MinimalTlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MinimalTlsVersion(input) + return &out, nil +} + +type PrincipalType string + +const ( + PrincipalTypeApplication PrincipalType = "Application" + PrincipalTypeGroup PrincipalType = "Group" + PrincipalTypeUser PrincipalType = "User" +) + +func PossibleValuesForPrincipalType() []string { + return []string{ + string(PrincipalTypeApplication), + string(PrincipalTypeGroup), + string(PrincipalTypeUser), + } +} + +func (s *PrincipalType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrincipalType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrincipalType(input string) (*PrincipalType, error) { + vals := map[string]PrincipalType{ + "application": PrincipalTypeApplication, + "group": PrincipalTypeGroup, + "user": PrincipalTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrincipalType(input) + return &out, nil +} + +type PrivateEndpointProvisioningState string + +const ( + PrivateEndpointProvisioningStateApproving PrivateEndpointProvisioningState = "Approving" + PrivateEndpointProvisioningStateDropping PrivateEndpointProvisioningState = "Dropping" + PrivateEndpointProvisioningStateFailed PrivateEndpointProvisioningState = "Failed" + PrivateEndpointProvisioningStateReady PrivateEndpointProvisioningState = "Ready" + PrivateEndpointProvisioningStateRejecting PrivateEndpointProvisioningState = "Rejecting" +) + +func PossibleValuesForPrivateEndpointProvisioningState() []string { + return []string{ + string(PrivateEndpointProvisioningStateApproving), + string(PrivateEndpointProvisioningStateDropping), + string(PrivateEndpointProvisioningStateFailed), + string(PrivateEndpointProvisioningStateReady), + string(PrivateEndpointProvisioningStateRejecting), + } +} + +func (s *PrivateEndpointProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointProvisioningState(input string) (*PrivateEndpointProvisioningState, error) { + vals := map[string]PrivateEndpointProvisioningState{ + "approving": PrivateEndpointProvisioningStateApproving, + "dropping": PrivateEndpointProvisioningStateDropping, + "failed": PrivateEndpointProvisioningStateFailed, + "ready": PrivateEndpointProvisioningStateReady, + "rejecting": PrivateEndpointProvisioningStateRejecting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointProvisioningState(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStateActionsRequire string + +const ( + PrivateLinkServiceConnectionStateActionsRequireNone PrivateLinkServiceConnectionStateActionsRequire = "None" +) + +func PossibleValuesForPrivateLinkServiceConnectionStateActionsRequire() []string { + return []string{ + string(PrivateLinkServiceConnectionStateActionsRequireNone), + } +} + +func (s *PrivateLinkServiceConnectionStateActionsRequire) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateLinkServiceConnectionStateActionsRequire(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateLinkServiceConnectionStateActionsRequire(input string) (*PrivateLinkServiceConnectionStateActionsRequire, error) { + vals := map[string]PrivateLinkServiceConnectionStateActionsRequire{ + "none": PrivateLinkServiceConnectionStateActionsRequireNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStateActionsRequire(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStateStatus string + +const ( + PrivateLinkServiceConnectionStateStatusApproved PrivateLinkServiceConnectionStateStatus = "Approved" + PrivateLinkServiceConnectionStateStatusDisconnected PrivateLinkServiceConnectionStateStatus = "Disconnected" + PrivateLinkServiceConnectionStateStatusPending PrivateLinkServiceConnectionStateStatus = "Pending" + PrivateLinkServiceConnectionStateStatusRejected PrivateLinkServiceConnectionStateStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStateStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStateStatusApproved), + string(PrivateLinkServiceConnectionStateStatusDisconnected), + string(PrivateLinkServiceConnectionStateStatusPending), + string(PrivateLinkServiceConnectionStateStatusRejected), + } +} + +func (s *PrivateLinkServiceConnectionStateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateLinkServiceConnectionStateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateLinkServiceConnectionStateStatus(input string) (*PrivateLinkServiceConnectionStateStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStateStatus{ + "approved": PrivateLinkServiceConnectionStateStatusApproved, + "disconnected": PrivateLinkServiceConnectionStateStatusDisconnected, + "pending": PrivateLinkServiceConnectionStateStatusPending, + "rejected": PrivateLinkServiceConnectionStateStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStateStatus(input) + return &out, nil +} + +type ServerNetworkAccessFlag string + +const ( + ServerNetworkAccessFlagDisabled ServerNetworkAccessFlag = "Disabled" + ServerNetworkAccessFlagEnabled ServerNetworkAccessFlag = "Enabled" +) + +func PossibleValuesForServerNetworkAccessFlag() []string { + return []string{ + string(ServerNetworkAccessFlagDisabled), + string(ServerNetworkAccessFlagEnabled), + } +} + +func (s *ServerNetworkAccessFlag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerNetworkAccessFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerNetworkAccessFlag(input string) (*ServerNetworkAccessFlag, error) { + vals := map[string]ServerNetworkAccessFlag{ + "disabled": ServerNetworkAccessFlagDisabled, + "enabled": ServerNetworkAccessFlagEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerNetworkAccessFlag(input) + return &out, nil +} + +type ServerPublicNetworkAccessFlag string + +const ( + ServerPublicNetworkAccessFlagDisabled ServerPublicNetworkAccessFlag = "Disabled" + ServerPublicNetworkAccessFlagEnabled ServerPublicNetworkAccessFlag = "Enabled" + ServerPublicNetworkAccessFlagSecuredByPerimeter ServerPublicNetworkAccessFlag = "SecuredByPerimeter" +) + +func PossibleValuesForServerPublicNetworkAccessFlag() []string { + return []string{ + string(ServerPublicNetworkAccessFlagDisabled), + string(ServerPublicNetworkAccessFlagEnabled), + string(ServerPublicNetworkAccessFlagSecuredByPerimeter), + } +} + +func (s *ServerPublicNetworkAccessFlag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerPublicNetworkAccessFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerPublicNetworkAccessFlag(input string) (*ServerPublicNetworkAccessFlag, error) { + vals := map[string]ServerPublicNetworkAccessFlag{ + "disabled": ServerPublicNetworkAccessFlagDisabled, + "enabled": ServerPublicNetworkAccessFlagEnabled, + "securedbyperimeter": ServerPublicNetworkAccessFlagSecuredByPerimeter, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerPublicNetworkAccessFlag(input) + return &out, nil +} + +type ServerWorkspaceFeature string + +const ( + ServerWorkspaceFeatureConnected ServerWorkspaceFeature = "Connected" + ServerWorkspaceFeatureDisconnected ServerWorkspaceFeature = "Disconnected" +) + +func PossibleValuesForServerWorkspaceFeature() []string { + return []string{ + string(ServerWorkspaceFeatureConnected), + string(ServerWorkspaceFeatureDisconnected), + } +} + +func (s *ServerWorkspaceFeature) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerWorkspaceFeature(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerWorkspaceFeature(input string) (*ServerWorkspaceFeature, error) { + vals := map[string]ServerWorkspaceFeature{ + "connected": ServerWorkspaceFeatureConnected, + "disconnected": ServerWorkspaceFeatureDisconnected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerWorkspaceFeature(input) + return &out, nil +} + +type StorageKeyType string + +const ( + StorageKeyTypeSharedAccessKey StorageKeyType = "SharedAccessKey" + StorageKeyTypeStorageAccessKey StorageKeyType = "StorageAccessKey" +) + +func PossibleValuesForStorageKeyType() []string { + return []string{ + string(StorageKeyTypeSharedAccessKey), + string(StorageKeyTypeStorageAccessKey), + } +} + +func (s *StorageKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageKeyType(input string) (*StorageKeyType, error) { + vals := map[string]StorageKeyType{ + "sharedaccesskey": StorageKeyTypeSharedAccessKey, + "storageaccesskey": StorageKeyTypeStorageAccessKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageKeyType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/servers/method_checknameavailability.go b/resource-manager/sql/2023-08-01/servers/method_checknameavailability.go new file mode 100644 index 00000000000..d4dc423607a --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_checknameavailability.go @@ -0,0 +1,59 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// CheckNameAvailability ... +func (c ServersClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servers/method_createorupdate.go b/resource-manager/sql/2023-08-01/servers/method_createorupdate.go new file mode 100644 index 00000000000..f31a561824c --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_createorupdate.go @@ -0,0 +1,77 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Server +} + +// CreateOrUpdate ... +func (c ServersClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input Server) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ServersClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input Server) 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/sql/2023-08-01/servers/method_delete.go b/resource-manager/sql/2023-08-01/servers/method_delete.go new file mode 100644 index 00000000000..04af34b7ea6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_delete.go @@ -0,0 +1,72 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ServersClient) Delete(ctx context.Context, id commonids.SqlServerId) (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 ServersClient) DeleteThenPoll(ctx context.Context, id commonids.SqlServerId) 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/sql/2023-08-01/servers/method_get.go b/resource-manager/sql/2023-08-01/servers/method_get.go new file mode 100644 index 00000000000..186e44d6c15 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_get.go @@ -0,0 +1,84 @@ +package servers + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Server +} + +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 ServersClient) Get(ctx context.Context, id commonids.SqlServerId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 Server + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servers/method_importdatabase.go b/resource-manager/sql/2023-08-01/servers/method_importdatabase.go new file mode 100644 index 00000000000..f1bc904907d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_importdatabase.go @@ -0,0 +1,76 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportDatabaseOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ImportExportOperationResult +} + +// ImportDatabase ... +func (c ServersClient) ImportDatabase(ctx context.Context, id commonids.SqlServerId, input ImportNewDatabaseDefinition) (result ImportDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/import", 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 +} + +// ImportDatabaseThenPoll performs ImportDatabase then polls until it's completed +func (c ServersClient) ImportDatabaseThenPoll(ctx context.Context, id commonids.SqlServerId, input ImportNewDatabaseDefinition) error { + result, err := c.ImportDatabase(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ImportDatabase: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ImportDatabase: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/servers/method_list.go b/resource-manager/sql/2023-08-01/servers/method_list.go new file mode 100644 index 00000000000..7c8dc454f0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_list.go @@ -0,0 +1,135 @@ +package servers + +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 *[]Server +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Server +} + +type ListOperationOptions struct { + Expand *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ServersClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/servers", 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 *[]Server `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 ServersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ServerOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ServerOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Server, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/servers/method_listbyresourcegroup.go b/resource-manager/sql/2023-08-01/servers/method_listbyresourcegroup.go new file mode 100644 index 00000000000..9ded1776fd1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_listbyresourcegroup.go @@ -0,0 +1,135 @@ +package servers + +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 *[]Server +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Server +} + +type ListByResourceGroupOperationOptions struct { + Expand *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ServersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/servers", 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 *[]Server `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 ServersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, ServerOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate ServerOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Server, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/servers/method_refreshstatus.go b/resource-manager/sql/2023-08-01/servers/method_refreshstatus.go new file mode 100644 index 00000000000..b2cc41720fb --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_refreshstatus.go @@ -0,0 +1,72 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshStatusOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RefreshExternalGovernanceStatusOperationResult +} + +// RefreshStatus ... +func (c ServersClient) RefreshStatus(ctx context.Context, id commonids.SqlServerId) (result RefreshStatusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshExternalGovernanceStatus", 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 +} + +// RefreshStatusThenPoll performs RefreshStatus then polls until it's completed +func (c ServersClient) RefreshStatusThenPoll(ctx context.Context, id commonids.SqlServerId) error { + result, err := c.RefreshStatus(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshStatus: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RefreshStatus: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/servers/method_update.go b/resource-manager/sql/2023-08-01/servers/method_update.go new file mode 100644 index 00000000000..982e7722042 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/method_update.go @@ -0,0 +1,76 @@ +package servers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Server +} + +// Update ... +func (c ServersClient) Update(ctx context.Context, id commonids.SqlServerId, input ServerUpdate) (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 ServersClient) UpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerUpdate) 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/sql/2023-08-01/servers/model_checknameavailabilityrequest.go b/resource-manager/sql/2023-08-01/servers/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..6ca0e7d6706 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name string `json:"name"` + Type CheckNameAvailabilityResourceType `json:"type"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_checknameavailabilityresponse.go b/resource-manager/sql/2023-08-01/servers/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..4fe08127495 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_checknameavailabilityresponse.go @@ -0,0 +1,11 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Available *bool `json:"available,omitempty"` + Message *string `json:"message,omitempty"` + Name *string `json:"name,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_importexportoperationresult.go b/resource-manager/sql/2023-08-01/servers/model_importexportoperationresult.go new file mode 100644 index 00000000000..103ab7cf634 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_importexportoperationresult.go @@ -0,0 +1,11 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImportExportOperationResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_importexportoperationresultproperties.go b/resource-manager/sql/2023-08-01/servers/model_importexportoperationresultproperties.go new file mode 100644 index 00000000000..33007b9475f --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_importexportoperationresultproperties.go @@ -0,0 +1,17 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportExportOperationResultProperties struct { + BlobUri *string `json:"blobUri,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + LastModifiedTime *string `json:"lastModifiedTime,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnectionRequestStatus `json:"privateEndpointConnections,omitempty"` + QueuedTime *string `json:"queuedTime,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestType *string `json:"requestType,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_importnewdatabasedefinition.go b/resource-manager/sql/2023-08-01/servers/model_importnewdatabasedefinition.go new file mode 100644 index 00000000000..6b4d80d3b8a --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_importnewdatabasedefinition.go @@ -0,0 +1,18 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportNewDatabaseDefinition struct { + AdministratorLogin string `json:"administratorLogin"` + AdministratorLoginPassword string `json:"administratorLoginPassword"` + AuthenticationType *string `json:"authenticationType,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + Edition *string `json:"edition,omitempty"` + MaxSizeBytes *string `json:"maxSizeBytes,omitempty"` + NetworkIsolation *NetworkIsolationSettings `json:"networkIsolation,omitempty"` + ServiceObjectiveName *string `json:"serviceObjectiveName,omitempty"` + StorageKey string `json:"storageKey"` + StorageKeyType StorageKeyType `json:"storageKeyType"` + StorageUri string `json:"storageUri"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_networkisolationsettings.go b/resource-manager/sql/2023-08-01/servers/model_networkisolationsettings.go new file mode 100644 index 00000000000..0770988ad0a --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_networkisolationsettings.go @@ -0,0 +1,9 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkIsolationSettings struct { + SqlServerResourceId *string `json:"sqlServerResourceId,omitempty"` + StorageAccountResourceId *string `json:"storageAccountResourceId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionproperties.go b/resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..870fa50199d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpointProperty `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionStateProperty `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *PrivateEndpointProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionrequeststatus.go b/resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionrequeststatus.go new file mode 100644 index 00000000000..a4ff6872adb --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_privateendpointconnectionrequeststatus.go @@ -0,0 +1,10 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionRequestStatus struct { + PrivateEndpointConnectionName *string `json:"privateEndpointConnectionName,omitempty"` + PrivateLinkServiceId *string `json:"privateLinkServiceId,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_privateendpointproperty.go b/resource-manager/sql/2023-08-01/servers/model_privateendpointproperty.go new file mode 100644 index 00000000000..6b1eab772d2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_privateendpointproperty.go @@ -0,0 +1,8 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointProperty struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_privatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-08-01/servers/model_privatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..f991bf100af --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_privatelinkserviceconnectionstateproperty.go @@ -0,0 +1,10 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionStateProperty struct { + ActionsRequired *PrivateLinkServiceConnectionStateActionsRequire `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status PrivateLinkServiceConnectionStateStatus `json:"status"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresult.go b/resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresult.go new file mode 100644 index 00000000000..6ac4a6afdb2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresult.go @@ -0,0 +1,11 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshExternalGovernanceStatusOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RefreshExternalGovernanceStatusOperationResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresultproperties.go b/resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresultproperties.go new file mode 100644 index 00000000000..e252305ecac --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_refreshexternalgovernancestatusoperationresultproperties.go @@ -0,0 +1,13 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshExternalGovernanceStatusOperationResultProperties struct { + ErrorMessage *string `json:"errorMessage,omitempty"` + QueuedTime *string `json:"queuedTime,omitempty"` + RequestId *string `json:"requestId,omitempty"` + RequestType *string `json:"requestType,omitempty"` + ServerName *string `json:"serverName,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_server.go b/resource-manager/sql/2023-08-01/servers/model_server.go new file mode 100644 index 00000000000..6d2b997b608 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_server.go @@ -0,0 +1,19 @@ +package servers + +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 Server struct { + Id *string `json:"id,omitempty"` + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ServerProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_serverexternaladministrator.go b/resource-manager/sql/2023-08-01/servers/model_serverexternaladministrator.go new file mode 100644 index 00000000000..4eca22208ca --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_serverexternaladministrator.go @@ -0,0 +1,13 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerExternalAdministrator struct { + AdministratorType *AdministratorType `json:"administratorType,omitempty"` + AzureADOnlyAuthentication *bool `json:"azureADOnlyAuthentication,omitempty"` + Login *string `json:"login,omitempty"` + PrincipalType *PrincipalType `json:"principalType,omitempty"` + Sid *string `json:"sid,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_serverprivateendpointconnection.go b/resource-manager/sql/2023-08-01/servers/model_serverprivateendpointconnection.go new file mode 100644 index 00000000000..ad26a4aedce --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_serverprivateendpointconnection.go @@ -0,0 +1,9 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerPrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_serverproperties.go b/resource-manager/sql/2023-08-01/servers/model_serverproperties.go new file mode 100644 index 00000000000..8429ca3813c --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_serverproperties.go @@ -0,0 +1,23 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerProperties struct { + AdministratorLogin *string `json:"administratorLogin,omitempty"` + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + Administrators *ServerExternalAdministrator `json:"administrators,omitempty"` + ExternalGovernanceStatus *ExternalGovernanceStatus `json:"externalGovernanceStatus,omitempty"` + FederatedClientId *string `json:"federatedClientId,omitempty"` + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty"` + IsIPv6Enabled *ServerNetworkAccessFlag `json:"isIPv6Enabled,omitempty"` + KeyId *string `json:"keyId,omitempty"` + MinimalTlsVersion *MinimalTlsVersion `json:"minimalTlsVersion,omitempty"` + PrimaryUserAssignedIdentityId *string `json:"primaryUserAssignedIdentityId,omitempty"` + PrivateEndpointConnections *[]ServerPrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + PublicNetworkAccess *ServerPublicNetworkAccessFlag `json:"publicNetworkAccess,omitempty"` + RestrictOutboundNetworkAccess *ServerNetworkAccessFlag `json:"restrictOutboundNetworkAccess,omitempty"` + State *string `json:"state,omitempty"` + Version *string `json:"version,omitempty"` + WorkspaceFeature *ServerWorkspaceFeature `json:"workspaceFeature,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/model_serverupdate.go b/resource-manager/sql/2023-08-01/servers/model_serverupdate.go new file mode 100644 index 00000000000..2c87fb81f0c --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/model_serverupdate.go @@ -0,0 +1,14 @@ +package servers + +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 ServerUpdate struct { + Identity *identity.LegacySystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ServerProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servers/predicates.go b/resource-manager/sql/2023-08-01/servers/predicates.go new file mode 100644 index 00000000000..c6dce7be40c --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/predicates.go @@ -0,0 +1,37 @@ +package servers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ServerOperationPredicate) Matches(input Server) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/sql/2023-08-01/servers/version.go b/resource-manager/sql/2023-08-01/servers/version.go new file mode 100644 index 00000000000..f2706837d9b --- /dev/null +++ b/resource-manager/sql/2023-08-01/servers/version.go @@ -0,0 +1,10 @@ +package servers + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/servers/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/README.md b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/README.md new file mode 100644 index 00000000000..6c3e6299cfb --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serversecurityalertpolicies` Documentation + +The `serversecurityalertpolicies` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serversecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := serversecurityalertpolicies.NewServerSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := serversecurityalertpolicies.ServerSecurityAlertPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerSecurityAlertPoliciesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerSecurityAlertPoliciesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/client.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/client.go new file mode 100644 index 00000000000..cb80188b500 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/client.go @@ -0,0 +1,26 @@ +package serversecurityalertpolicies + +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 ServerSecurityAlertPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewServerSecurityAlertPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerSecurityAlertPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serversecurityalertpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerSecurityAlertPoliciesClient: %+v", err) + } + + return &ServerSecurityAlertPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/constants.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/constants.go new file mode 100644 index 00000000000..bf719a66789 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/constants.go @@ -0,0 +1,51 @@ +package serversecurityalertpolicies + +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 SecurityAlertsPolicyState string + +const ( + SecurityAlertsPolicyStateDisabled SecurityAlertsPolicyState = "Disabled" + SecurityAlertsPolicyStateEnabled SecurityAlertsPolicyState = "Enabled" +) + +func PossibleValuesForSecurityAlertsPolicyState() []string { + return []string{ + string(SecurityAlertsPolicyStateDisabled), + string(SecurityAlertsPolicyStateEnabled), + } +} + +func (s *SecurityAlertsPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityAlertsPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityAlertsPolicyState(input string) (*SecurityAlertsPolicyState, error) { + vals := map[string]SecurityAlertsPolicyState{ + "disabled": SecurityAlertsPolicyStateDisabled, + "enabled": SecurityAlertsPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityAlertsPolicyState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..c4a460af54a --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_createorupdate.go @@ -0,0 +1,76 @@ +package serversecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerSecurityAlertPolicy +} + +// CreateOrUpdate ... +func (c ServerSecurityAlertPoliciesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerSecurityAlertPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ServerSecurityAlertPoliciesClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlServerId, input ServerSecurityAlertPolicy) 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/sql/2023-08-01/serversecurityalertpolicies/method_get.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..b7f63c8bb22 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_get.go @@ -0,0 +1,55 @@ +package serversecurityalertpolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerSecurityAlertPolicy +} + +// Get ... +func (c ServerSecurityAlertPoliciesClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies/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 ServerSecurityAlertPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_listbyserver.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_listbyserver.go new file mode 100644 index 00000000000..50b8635f5a0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/method_listbyserver.go @@ -0,0 +1,106 @@ +package serversecurityalertpolicies + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerSecurityAlertPolicy +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerSecurityAlertPolicy +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerSecurityAlertPoliciesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/securityAlertPolicies", 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 *[]ServerSecurityAlertPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerSecurityAlertPoliciesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerSecurityAlertPolicyOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerSecurityAlertPoliciesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerSecurityAlertPolicyOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerSecurityAlertPolicy, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_securityalertspolicyproperties.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_securityalertspolicyproperties.go new file mode 100644 index 00000000000..f4e86aa1451 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_securityalertspolicyproperties.go @@ -0,0 +1,33 @@ +package serversecurityalertpolicies + +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 SecurityAlertsPolicyProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + DisabledAlerts *[]string `json:"disabledAlerts,omitempty"` + EmailAccountAdmins *bool `json:"emailAccountAdmins,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State SecurityAlertsPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} + +func (o *SecurityAlertsPolicyProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertsPolicyProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_serversecurityalertpolicy.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_serversecurityalertpolicy.go new file mode 100644 index 00000000000..f3fa4bd4208 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/model_serversecurityalertpolicy.go @@ -0,0 +1,16 @@ +package serversecurityalertpolicies + +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 ServerSecurityAlertPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityAlertsPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serversecurityalertpolicies/predicates.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..ff213a5f292 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/predicates.go @@ -0,0 +1,27 @@ +package serversecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerSecurityAlertPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerSecurityAlertPolicyOperationPredicate) Matches(input ServerSecurityAlertPolicy) 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/sql/2023-08-01/serversecurityalertpolicies/version.go b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/version.go new file mode 100644 index 00000000000..5846e232782 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serversecurityalertpolicies/version.go @@ -0,0 +1,10 @@ +package serversecurityalertpolicies + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serversecurityalertpolicies/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/README.md b/resource-manager/sql/2023-08-01/servertrustcertificates/README.md new file mode 100644 index 00000000000..ee2fa8fe9bc --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servertrustcertificates` Documentation + +The `servertrustcertificates` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servertrustcertificates" +``` + + +### Client Initialization + +```go +client := servertrustcertificates.NewServerTrustCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerTrustCertificatesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := servertrustcertificates.NewServerTrustCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "serverTrustCertificateName") + +payload := servertrustcertificates.ServerTrustCertificate{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerTrustCertificatesClient.Delete` + +```go +ctx := context.TODO() +id := servertrustcertificates.NewServerTrustCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "serverTrustCertificateName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerTrustCertificatesClient.Get` + +```go +ctx := context.TODO() +id := servertrustcertificates.NewServerTrustCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "serverTrustCertificateName") + +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: `ServerTrustCertificatesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/client.go b/resource-manager/sql/2023-08-01/servertrustcertificates/client.go new file mode 100644 index 00000000000..1754d2f466c --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/client.go @@ -0,0 +1,26 @@ +package servertrustcertificates + +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 ServerTrustCertificatesClient struct { + Client *resourcemanager.Client +} + +func NewServerTrustCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerTrustCertificatesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "servertrustcertificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerTrustCertificatesClient: %+v", err) + } + + return &ServerTrustCertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate.go b/resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate.go new file mode 100644 index 00000000000..d9cd22edd26 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate.go @@ -0,0 +1,139 @@ +package servertrustcertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServerTrustCertificateId{}) +} + +var _ resourceids.ResourceId = &ServerTrustCertificateId{} + +// ServerTrustCertificateId is a struct representing the Resource ID for a Server Trust Certificate +type ServerTrustCertificateId struct { + SubscriptionId string + ResourceGroupName string + ManagedInstanceName string + ServerTrustCertificateName string +} + +// NewServerTrustCertificateID returns a new ServerTrustCertificateId struct +func NewServerTrustCertificateID(subscriptionId string, resourceGroupName string, managedInstanceName string, serverTrustCertificateName string) ServerTrustCertificateId { + return ServerTrustCertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ManagedInstanceName: managedInstanceName, + ServerTrustCertificateName: serverTrustCertificateName, + } +} + +// ParseServerTrustCertificateID parses 'input' into a ServerTrustCertificateId +func ParseServerTrustCertificateID(input string) (*ServerTrustCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServerTrustCertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServerTrustCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServerTrustCertificateIDInsensitively parses 'input' case-insensitively into a ServerTrustCertificateId +// note: this method should only be used for API response data and not user input +func ParseServerTrustCertificateIDInsensitively(input string) (*ServerTrustCertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServerTrustCertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServerTrustCertificateId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServerTrustCertificateId) 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.ManagedInstanceName, ok = input.Parsed["managedInstanceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "managedInstanceName", input) + } + + if id.ServerTrustCertificateName, ok = input.Parsed["serverTrustCertificateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverTrustCertificateName", input) + } + + return nil +} + +// ValidateServerTrustCertificateID checks that 'input' can be parsed as a Server Trust Certificate ID +func ValidateServerTrustCertificateID(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 := ParseServerTrustCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Trust Certificate ID +func (id ServerTrustCertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/serverTrustCertificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ManagedInstanceName, id.ServerTrustCertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Trust Certificate ID +func (id ServerTrustCertificateId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticManagedInstances", "managedInstances", "managedInstances"), + resourceids.UserSpecifiedSegment("managedInstanceName", "managedInstanceName"), + resourceids.StaticSegment("staticServerTrustCertificates", "serverTrustCertificates", "serverTrustCertificates"), + resourceids.UserSpecifiedSegment("serverTrustCertificateName", "serverTrustCertificateName"), + } +} + +// String returns a human-readable description of this Server Trust Certificate ID +func (id ServerTrustCertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Managed Instance Name: %q", id.ManagedInstanceName), + fmt.Sprintf("Server Trust Certificate Name: %q", id.ServerTrustCertificateName), + } + return fmt.Sprintf("Server Trust Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate_test.go b/resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate_test.go new file mode 100644 index 00000000000..d74b6b91dba --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/id_servertrustcertificate_test.go @@ -0,0 +1,327 @@ +package servertrustcertificates + +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 = &ServerTrustCertificateId{} + +func TestNewServerTrustCertificateID(t *testing.T) { + id := NewServerTrustCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "serverTrustCertificateName") + + 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.ManagedInstanceName != "managedInstanceName" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceName") + } + + if id.ServerTrustCertificateName != "serverTrustCertificateName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerTrustCertificateName'", id.ServerTrustCertificateName, "serverTrustCertificateName") + } +} + +func TestFormatServerTrustCertificateID(t *testing.T) { + actual := NewServerTrustCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName", "serverTrustCertificateName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates/serverTrustCertificateName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerTrustCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerTrustCertificateId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates/serverTrustCertificateName", + Expected: &ServerTrustCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + ServerTrustCertificateName: "serverTrustCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates/serverTrustCertificateName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerTrustCertificateID(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.ServerTrustCertificateName != v.Expected.ServerTrustCertificateName { + t.Fatalf("Expected %q but got %q for ServerTrustCertificateName", v.Expected.ServerTrustCertificateName, actual.ServerTrustCertificateName) + } + + } +} + +func TestParseServerTrustCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerTrustCertificateId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/sErVeRtRuStCeRtIfIcAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates/serverTrustCertificateName", + Expected: &ServerTrustCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceName", + ServerTrustCertificateName: "serverTrustCertificateName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceName/serverTrustCertificates/serverTrustCertificateName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/sErVeRtRuStCeRtIfIcAtEs/sErVeRtRuStCeRtIfIcAtEnAmE", + Expected: &ServerTrustCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeNaMe", + ServerTrustCertificateName: "sErVeRtRuStCeRtIfIcAtEnAmE", + }, + }, + { + // 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.sQl/mAnAgEdInStAnCeS/mAnAgEdInStAnCeNaMe/sErVeRtRuStCeRtIfIcAtEs/sErVeRtRuStCeRtIfIcAtEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerTrustCertificateIDInsensitively(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.ManagedInstanceName != v.Expected.ManagedInstanceName { + t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName) + } + + if actual.ServerTrustCertificateName != v.Expected.ServerTrustCertificateName { + t.Fatalf("Expected %q but got %q for ServerTrustCertificateName", v.Expected.ServerTrustCertificateName, actual.ServerTrustCertificateName) + } + + } +} + +func TestSegmentsForServerTrustCertificateId(t *testing.T) { + segments := ServerTrustCertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerTrustCertificateId 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/sql/2023-08-01/servertrustcertificates/method_createorupdate.go b/resource-manager/sql/2023-08-01/servertrustcertificates/method_createorupdate.go new file mode 100644 index 00000000000..a693862b4fc --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/method_createorupdate.go @@ -0,0 +1,76 @@ +package servertrustcertificates + +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 *ServerTrustCertificate +} + +// CreateOrUpdate ... +func (c ServerTrustCertificatesClient) CreateOrUpdate(ctx context.Context, id ServerTrustCertificateId, input ServerTrustCertificate) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ServerTrustCertificatesClient) CreateOrUpdateThenPoll(ctx context.Context, id ServerTrustCertificateId, input ServerTrustCertificate) 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/sql/2023-08-01/servertrustcertificates/method_delete.go b/resource-manager/sql/2023-08-01/servertrustcertificates/method_delete.go new file mode 100644 index 00000000000..1017f9f4585 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/method_delete.go @@ -0,0 +1,71 @@ +package servertrustcertificates + +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 ServerTrustCertificatesClient) Delete(ctx context.Context, id ServerTrustCertificateId) (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 ServerTrustCertificatesClient) DeleteThenPoll(ctx context.Context, id ServerTrustCertificateId) 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/sql/2023-08-01/servertrustcertificates/method_get.go b/resource-manager/sql/2023-08-01/servertrustcertificates/method_get.go new file mode 100644 index 00000000000..26bfaa5dde5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/method_get.go @@ -0,0 +1,53 @@ +package servertrustcertificates + +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 *ServerTrustCertificate +} + +// Get ... +func (c ServerTrustCertificatesClient) Get(ctx context.Context, id ServerTrustCertificateId) (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 ServerTrustCertificate + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/method_listbyinstance.go b/resource-manager/sql/2023-08-01/servertrustcertificates/method_listbyinstance.go new file mode 100644 index 00000000000..17f4bf95e19 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/method_listbyinstance.go @@ -0,0 +1,106 @@ +package servertrustcertificates + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerTrustCertificate +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerTrustCertificate +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ServerTrustCertificatesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/serverTrustCertificates", 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 *[]ServerTrustCertificate `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ServerTrustCertificatesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ServerTrustCertificateOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerTrustCertificatesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ServerTrustCertificateOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ServerTrustCertificate, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificate.go b/resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificate.go new file mode 100644 index 00000000000..6c046705f5d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificate.go @@ -0,0 +1,11 @@ +package servertrustcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerTrustCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerTrustCertificateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificateproperties.go b/resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificateproperties.go new file mode 100644 index 00000000000..63c0123ac8d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/model_servertrustcertificateproperties.go @@ -0,0 +1,10 @@ +package servertrustcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerTrustCertificateProperties struct { + CertificateName *string `json:"certificateName,omitempty"` + PublicBlob *string `json:"publicBlob,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servertrustcertificates/predicates.go b/resource-manager/sql/2023-08-01/servertrustcertificates/predicates.go new file mode 100644 index 00000000000..81cc0b4c36a --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/predicates.go @@ -0,0 +1,27 @@ +package servertrustcertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerTrustCertificateOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerTrustCertificateOperationPredicate) Matches(input ServerTrustCertificate) 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/sql/2023-08-01/servertrustcertificates/version.go b/resource-manager/sql/2023-08-01/servertrustcertificates/version.go new file mode 100644 index 00000000000..e556872249a --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustcertificates/version.go @@ -0,0 +1,10 @@ +package servertrustcertificates + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/servertrustcertificates/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/README.md b/resource-manager/sql/2023-08-01/servertrustgroups/README.md new file mode 100644 index 00000000000..fe2ab6795df --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/README.md @@ -0,0 +1,100 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servertrustgroups` Documentation + +The `servertrustgroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servertrustgroups" +``` + + +### Client Initialization + +```go +client := servertrustgroups.NewServerTrustGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerTrustGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := servertrustgroups.NewServerTrustGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "serverTrustGroupName") + +payload := servertrustgroups.ServerTrustGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerTrustGroupsClient.Delete` + +```go +ctx := context.TODO() +id := servertrustgroups.NewServerTrustGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "serverTrustGroupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerTrustGroupsClient.Get` + +```go +ctx := context.TODO() +id := servertrustgroups.NewServerTrustGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "serverTrustGroupName") + +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: `ServerTrustGroupsClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ServerTrustGroupsClient.ListByLocation` + +```go +ctx := context.TODO() +id := servertrustgroups.NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/client.go b/resource-manager/sql/2023-08-01/servertrustgroups/client.go new file mode 100644 index 00000000000..175c668a349 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/client.go @@ -0,0 +1,26 @@ +package servertrustgroups + +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 ServerTrustGroupsClient struct { + Client *resourcemanager.Client +} + +func NewServerTrustGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerTrustGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "servertrustgroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerTrustGroupsClient: %+v", err) + } + + return &ServerTrustGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/constants.go b/resource-manager/sql/2023-08-01/servertrustgroups/constants.go new file mode 100644 index 00000000000..2d314782254 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/constants.go @@ -0,0 +1,51 @@ +package servertrustgroups + +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 TrustScope string + +const ( + TrustScopeGlobalTransactions TrustScope = "GlobalTransactions" + TrustScopeServiceBroker TrustScope = "ServiceBroker" +) + +func PossibleValuesForTrustScope() []string { + return []string{ + string(TrustScopeGlobalTransactions), + string(TrustScopeServiceBroker), + } +} + +func (s *TrustScope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTrustScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTrustScope(input string) (*TrustScope, error) { + vals := map[string]TrustScope{ + "globaltransactions": TrustScopeGlobalTransactions, + "servicebroker": TrustScopeServiceBroker, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TrustScope(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation.go b/resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation.go new file mode 100644 index 00000000000..1b26114df6f --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation.go @@ -0,0 +1,130 @@ +package servertrustgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderLocationId{}) +} + +var _ resourceids.ResourceId = &ProviderLocationId{} + +// ProviderLocationId is a struct representing the Resource ID for a Provider Location +type ProviderLocationId struct { + SubscriptionId string + ResourceGroupName string + LocationName string +} + +// NewProviderLocationID returns a new ProviderLocationId struct +func NewProviderLocationID(subscriptionId string, resourceGroupName string, locationName string) ProviderLocationId { + return ProviderLocationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + } +} + +// ParseProviderLocationID parses 'input' into a ProviderLocationId +func ParseProviderLocationID(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderLocationIDInsensitively parses 'input' case-insensitively into a ProviderLocationId +// note: this method should only be used for API response data and not user input +func ParseProviderLocationIDInsensitively(input string) (*ProviderLocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderLocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderLocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderLocationId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateProviderLocationID checks that 'input' can be parsed as a Provider Location ID +func ValidateProviderLocationID(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 := ParseProviderLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Location ID +func (id ProviderLocationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Location ID +func (id ProviderLocationId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Provider Location ID +func (id ProviderLocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Provider Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation_test.go b/resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation_test.go new file mode 100644 index 00000000000..b57c14aadb5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/id_providerlocation_test.go @@ -0,0 +1,282 @@ +package servertrustgroups + +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 = &ProviderLocationId{} + +func TestNewProviderLocationID(t *testing.T) { + id := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseProviderLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderLocationId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForProviderLocationId(t *testing.T) { + segments := ProviderLocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderLocationId 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/sql/2023-08-01/servertrustgroups/id_servertrustgroup.go b/resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup.go new file mode 100644 index 00000000000..8d48d02ab45 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup.go @@ -0,0 +1,139 @@ +package servertrustgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServerTrustGroupId{}) +} + +var _ resourceids.ResourceId = &ServerTrustGroupId{} + +// ServerTrustGroupId is a struct representing the Resource ID for a Server Trust Group +type ServerTrustGroupId struct { + SubscriptionId string + ResourceGroupName string + LocationName string + ServerTrustGroupName string +} + +// NewServerTrustGroupID returns a new ServerTrustGroupId struct +func NewServerTrustGroupID(subscriptionId string, resourceGroupName string, locationName string, serverTrustGroupName string) ServerTrustGroupId { + return ServerTrustGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + LocationName: locationName, + ServerTrustGroupName: serverTrustGroupName, + } +} + +// ParseServerTrustGroupID parses 'input' into a ServerTrustGroupId +func ParseServerTrustGroupID(input string) (*ServerTrustGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServerTrustGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServerTrustGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServerTrustGroupIDInsensitively parses 'input' case-insensitively into a ServerTrustGroupId +// note: this method should only be used for API response data and not user input +func ParseServerTrustGroupIDInsensitively(input string) (*ServerTrustGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServerTrustGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServerTrustGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServerTrustGroupId) 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.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.ServerTrustGroupName, ok = input.Parsed["serverTrustGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverTrustGroupName", input) + } + + return nil +} + +// ValidateServerTrustGroupID checks that 'input' can be parsed as a Server Trust Group ID +func ValidateServerTrustGroupID(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 := ParseServerTrustGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Server Trust Group ID +func (id ServerTrustGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/locations/%s/serverTrustGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.LocationName, id.ServerTrustGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Server Trust Group ID +func (id ServerTrustGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticServerTrustGroups", "serverTrustGroups", "serverTrustGroups"), + resourceids.UserSpecifiedSegment("serverTrustGroupName", "serverTrustGroupName"), + } +} + +// String returns a human-readable description of this Server Trust Group ID +func (id ServerTrustGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Server Trust Group Name: %q", id.ServerTrustGroupName), + } + return fmt.Sprintf("Server Trust Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup_test.go b/resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup_test.go new file mode 100644 index 00000000000..80cad8b88bc --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/id_servertrustgroup_test.go @@ -0,0 +1,327 @@ +package servertrustgroups + +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 = &ServerTrustGroupId{} + +func TestNewServerTrustGroupID(t *testing.T) { + id := NewServerTrustGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "serverTrustGroupName") + + 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.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.ServerTrustGroupName != "serverTrustGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerTrustGroupName'", id.ServerTrustGroupName, "serverTrustGroupName") + } +} + +func TestFormatServerTrustGroupID(t *testing.T) { + actual := NewServerTrustGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationName", "serverTrustGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups/serverTrustGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseServerTrustGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerTrustGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups/serverTrustGroupName", + Expected: &ServerTrustGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + ServerTrustGroupName: "serverTrustGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups/serverTrustGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerTrustGroupID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.ServerTrustGroupName != v.Expected.ServerTrustGroupName { + t.Fatalf("Expected %q but got %q for ServerTrustGroupName", v.Expected.ServerTrustGroupName, actual.ServerTrustGroupName) + } + + } +} + +func TestParseServerTrustGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ServerTrustGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/sErVeRtRuStGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups/serverTrustGroupName", + Expected: &ServerTrustGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationName", + ServerTrustGroupName: "serverTrustGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationName/serverTrustGroups/serverTrustGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/sErVeRtRuStGrOuPs/sErVeRtRuStGrOuPnAmE", + Expected: &ServerTrustGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNnAmE", + ServerTrustGroupName: "sErVeRtRuStGrOuPnAmE", + }, + }, + { + // 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.sQl/lOcAtIoNs/lOcAtIoNnAmE/sErVeRtRuStGrOuPs/sErVeRtRuStGrOuPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseServerTrustGroupIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.ServerTrustGroupName != v.Expected.ServerTrustGroupName { + t.Fatalf("Expected %q but got %q for ServerTrustGroupName", v.Expected.ServerTrustGroupName, actual.ServerTrustGroupName) + } + + } +} + +func TestSegmentsForServerTrustGroupId(t *testing.T) { + segments := ServerTrustGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ServerTrustGroupId 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/sql/2023-08-01/servertrustgroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/servertrustgroups/method_createorupdate.go new file mode 100644 index 00000000000..c1377e94e74 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/method_createorupdate.go @@ -0,0 +1,76 @@ +package servertrustgroups + +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 *ServerTrustGroup +} + +// CreateOrUpdate ... +func (c ServerTrustGroupsClient) CreateOrUpdate(ctx context.Context, id ServerTrustGroupId, input ServerTrustGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 ServerTrustGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id ServerTrustGroupId, input ServerTrustGroup) 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/sql/2023-08-01/servertrustgroups/method_delete.go b/resource-manager/sql/2023-08-01/servertrustgroups/method_delete.go new file mode 100644 index 00000000000..24fdacf3d9f --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/method_delete.go @@ -0,0 +1,71 @@ +package servertrustgroups + +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 ServerTrustGroupsClient) Delete(ctx context.Context, id ServerTrustGroupId) (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 ServerTrustGroupsClient) DeleteThenPoll(ctx context.Context, id ServerTrustGroupId) 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/sql/2023-08-01/servertrustgroups/method_get.go b/resource-manager/sql/2023-08-01/servertrustgroups/method_get.go new file mode 100644 index 00000000000..b9d7d3201ae --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/method_get.go @@ -0,0 +1,53 @@ +package servertrustgroups + +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 *ServerTrustGroup +} + +// Get ... +func (c ServerTrustGroupsClient) Get(ctx context.Context, id ServerTrustGroupId) (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 ServerTrustGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/method_listbyinstance.go b/resource-manager/sql/2023-08-01/servertrustgroups/method_listbyinstance.go new file mode 100644 index 00000000000..eeaeeb3876f --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/method_listbyinstance.go @@ -0,0 +1,106 @@ +package servertrustgroups + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerTrustGroup +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerTrustGroup +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c ServerTrustGroupsClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/serverTrustGroups", 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 *[]ServerTrustGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c ServerTrustGroupsClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, ServerTrustGroupOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerTrustGroupsClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate ServerTrustGroupOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]ServerTrustGroup, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/method_listbylocation.go b/resource-manager/sql/2023-08-01/servertrustgroups/method_listbylocation.go new file mode 100644 index 00000000000..8bad6d43f77 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/method_listbylocation.go @@ -0,0 +1,105 @@ +package servertrustgroups + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerTrustGroup +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerTrustGroup +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c ServerTrustGroupsClient) ListByLocation(ctx context.Context, id ProviderLocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/serverTrustGroups", 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 *[]ServerTrustGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c ServerTrustGroupsClient) ListByLocationComplete(ctx context.Context, id ProviderLocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, ServerTrustGroupOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerTrustGroupsClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id ProviderLocationId, predicate ServerTrustGroupOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]ServerTrustGroup, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/model_serverinfo.go b/resource-manager/sql/2023-08-01/servertrustgroups/model_serverinfo.go new file mode 100644 index 00000000000..958b3c00237 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/model_serverinfo.go @@ -0,0 +1,8 @@ +package servertrustgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerInfo struct { + ServerId string `json:"serverId"` +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroup.go b/resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroup.go new file mode 100644 index 00000000000..569b0be13e6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroup.go @@ -0,0 +1,11 @@ +package servertrustgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerTrustGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerTrustGroupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroupproperties.go b/resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroupproperties.go new file mode 100644 index 00000000000..8f628115904 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/model_servertrustgroupproperties.go @@ -0,0 +1,9 @@ +package servertrustgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerTrustGroupProperties struct { + GroupMembers []ServerInfo `json:"groupMembers"` + TrustScopes []TrustScope `json:"trustScopes"` +} diff --git a/resource-manager/sql/2023-08-01/servertrustgroups/predicates.go b/resource-manager/sql/2023-08-01/servertrustgroups/predicates.go new file mode 100644 index 00000000000..92b66b22438 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/predicates.go @@ -0,0 +1,27 @@ +package servertrustgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerTrustGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerTrustGroupOperationPredicate) Matches(input ServerTrustGroup) 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/sql/2023-08-01/servertrustgroups/version.go b/resource-manager/sql/2023-08-01/servertrustgroups/version.go new file mode 100644 index 00000000000..0076fb4cb39 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servertrustgroups/version.go @@ -0,0 +1,10 @@ +package servertrustgroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/servertrustgroups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/serverusages/README.md b/resource-manager/sql/2023-08-01/serverusages/README.md new file mode 100644 index 00000000000..0a7cdde4e48 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverusages` Documentation + +The `serverusages` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/serverusages" +``` + + +### Client Initialization + +```go +client := serverusages.NewServerUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerUsagesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/serverusages/client.go b/resource-manager/sql/2023-08-01/serverusages/client.go new file mode 100644 index 00000000000..16666bee036 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/client.go @@ -0,0 +1,26 @@ +package serverusages + +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 ServerUsagesClient struct { + Client *resourcemanager.Client +} + +func NewServerUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerUsagesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "serverusages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerUsagesClient: %+v", err) + } + + return &ServerUsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/serverusages/method_listbyserver.go b/resource-manager/sql/2023-08-01/serverusages/method_listbyserver.go new file mode 100644 index 00000000000..8c6774ff80d --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/method_listbyserver.go @@ -0,0 +1,106 @@ +package serverusages + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerUsage +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerUsage +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerUsagesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ServerUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerUsagesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerUsageOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerUsagesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerUsageOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerUsage, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/serverusages/model_serverusage.go b/resource-manager/sql/2023-08-01/serverusages/model_serverusage.go new file mode 100644 index 00000000000..37a73811e44 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/model_serverusage.go @@ -0,0 +1,11 @@ +package serverusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerUsage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerUsageProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverusages/model_serverusageproperties.go b/resource-manager/sql/2023-08-01/serverusages/model_serverusageproperties.go new file mode 100644 index 00000000000..71eaa27c4d9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/model_serverusageproperties.go @@ -0,0 +1,11 @@ +package serverusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerUsageProperties struct { + CurrentValue *float64 `json:"currentValue,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/serverusages/predicates.go b/resource-manager/sql/2023-08-01/serverusages/predicates.go new file mode 100644 index 00000000000..086c2bd1918 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/predicates.go @@ -0,0 +1,27 @@ +package serverusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerUsageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerUsageOperationPredicate) Matches(input ServerUsage) 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/sql/2023-08-01/serverusages/version.go b/resource-manager/sql/2023-08-01/serverusages/version.go new file mode 100644 index 00000000000..f76994f9d84 --- /dev/null +++ b/resource-manager/sql/2023-08-01/serverusages/version.go @@ -0,0 +1,10 @@ +package serverusages + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/serverusages/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/README.md b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/README.md new file mode 100644 index 00000000000..443b13f439d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servervulnerabilityassessments` Documentation + +The `servervulnerabilityassessments` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/servervulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := servervulnerabilityassessments.NewServerVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := servervulnerabilityassessments.ServerVulnerabilityAssessment{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `ServerVulnerabilityAssessmentsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/client.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/client.go new file mode 100644 index 00000000000..e7d2ead0545 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/client.go @@ -0,0 +1,26 @@ +package servervulnerabilityassessments + +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 ServerVulnerabilityAssessmentsClient struct { + Client *resourcemanager.Client +} + +func NewServerVulnerabilityAssessmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*ServerVulnerabilityAssessmentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "servervulnerabilityassessments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ServerVulnerabilityAssessmentsClient: %+v", err) + } + + return &ServerVulnerabilityAssessmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..9b468796ec2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,60 @@ +package servervulnerabilityassessments + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerVulnerabilityAssessment +} + +// CreateOrUpdate ... +func (c ServerVulnerabilityAssessmentsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input ServerVulnerabilityAssessment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 ServerVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..946d840fe59 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_delete.go @@ -0,0 +1,48 @@ +package servervulnerabilityassessments + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ServerVulnerabilityAssessmentsClient) Delete(ctx context.Context, id commonids.SqlServerId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_get.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..09f63e48019 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_get.go @@ -0,0 +1,55 @@ +package servervulnerabilityassessments + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerVulnerabilityAssessment +} + +// Get ... +func (c ServerVulnerabilityAssessmentsClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/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 ServerVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_listbyserver.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_listbyserver.go new file mode 100644 index 00000000000..49dc3296c3b --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/method_listbyserver.go @@ -0,0 +1,106 @@ +package servervulnerabilityassessments + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerVulnerabilityAssessment +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerVulnerabilityAssessment +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c ServerVulnerabilityAssessmentsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/vulnerabilityAssessments", 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 *[]ServerVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c ServerVulnerabilityAssessmentsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, ServerVulnerabilityAssessmentOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ServerVulnerabilityAssessmentsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate ServerVulnerabilityAssessmentOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]ServerVulnerabilityAssessment, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessment.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessment.go new file mode 100644 index 00000000000..7d2d82491b0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessment.go @@ -0,0 +1,11 @@ +package servervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..2627932f4a6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package servervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath string `json:"storageContainerPath"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..d2153ee760d --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package servervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/servervulnerabilityassessments/predicates.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..cba9908c5fe --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/predicates.go @@ -0,0 +1,27 @@ +package servervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerVulnerabilityAssessmentOperationPredicate) Matches(input ServerVulnerabilityAssessment) 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/sql/2023-08-01/servervulnerabilityassessments/version.go b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/version.go new file mode 100644 index 00000000000..5bfe64803e0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/servervulnerabilityassessments/version.go @@ -0,0 +1,10 @@ +package servervulnerabilityassessments + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/servervulnerabilityassessments/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/README.md b/resource-manager/sql/2023-08-01/sqlagent/README.md new file mode 100644 index 00000000000..73a7254aa17 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlagent` Documentation + +The `sqlagent` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlagent" +``` + + +### Client Initialization + +```go +client := sqlagent.NewSqlAgentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlAgentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := sqlagent.SqlAgentConfiguration{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlAgentClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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 +} +``` diff --git a/resource-manager/sql/2023-08-01/sqlagent/client.go b/resource-manager/sql/2023-08-01/sqlagent/client.go new file mode 100644 index 00000000000..27e9195f8bc --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/client.go @@ -0,0 +1,26 @@ +package sqlagent + +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 SqlAgentClient struct { + Client *resourcemanager.Client +} + +func NewSqlAgentClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlAgentClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlagent", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlAgentClient: %+v", err) + } + + return &SqlAgentClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/constants.go b/resource-manager/sql/2023-08-01/sqlagent/constants.go new file mode 100644 index 00000000000..e4b59620df5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/constants.go @@ -0,0 +1,51 @@ +package sqlagent + +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 SqlAgentState string + +const ( + SqlAgentStateDisabled SqlAgentState = "Disabled" + SqlAgentStateEnabled SqlAgentState = "Enabled" +) + +func PossibleValuesForSqlAgentState() []string { + return []string{ + string(SqlAgentStateDisabled), + string(SqlAgentStateEnabled), + } +} + +func (s *SqlAgentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlAgentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSqlAgentState(input string) (*SqlAgentState, error) { + vals := map[string]SqlAgentState{ + "disabled": SqlAgentStateDisabled, + "enabled": SqlAgentStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SqlAgentState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/method_createorupdate.go b/resource-manager/sql/2023-08-01/sqlagent/method_createorupdate.go new file mode 100644 index 00000000000..cd83669aefa --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/method_createorupdate.go @@ -0,0 +1,59 @@ +package sqlagent + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlAgentConfiguration +} + +// CreateOrUpdate ... +func (c SqlAgentClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input SqlAgentConfiguration) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sqlAgent/current", 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 SqlAgentConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/method_get.go b/resource-manager/sql/2023-08-01/sqlagent/method_get.go new file mode 100644 index 00000000000..eb20d2e2e4b --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/method_get.go @@ -0,0 +1,55 @@ +package sqlagent + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlAgentConfiguration +} + +// Get ... +func (c SqlAgentClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlAgent/current", 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 SqlAgentConfiguration + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfiguration.go b/resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfiguration.go new file mode 100644 index 00000000000..941811c4244 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfiguration.go @@ -0,0 +1,11 @@ +package sqlagent + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlAgentConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlAgentConfigurationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfigurationproperties.go b/resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfigurationproperties.go new file mode 100644 index 00000000000..9f1177bd9f4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/model_sqlagentconfigurationproperties.go @@ -0,0 +1,8 @@ +package sqlagent + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlAgentConfigurationProperties struct { + State *SqlAgentState `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlagent/version.go b/resource-manager/sql/2023-08-01/sqlagent/version.go new file mode 100644 index 00000000000..6776aea933d --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlagent/version.go @@ -0,0 +1,10 @@ +package sqlagent + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlagent/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/README.md b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/README.md new file mode 100644 index 00000000000..36bf87067ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline` Documentation + +The `sqlvulnerabilityassessmentbaseline` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentbaseline.NewSqlVulnerabilityAssessmentBaselineClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentBaselineClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := sqlvulnerabilityassessmentbaseline.DatabaseSqlVulnerabilityAssessmentRuleBaselineListInput{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, sqlvulnerabilityassessmentbaseline.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentBaselineClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.Get(ctx, id, sqlvulnerabilityassessmentbaseline.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentBaselineClient.ListBySqlVulnerabilityAssessment` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListBySqlVulnerabilityAssessment(ctx, id, sqlvulnerabilityassessmentbaseline.DefaultListBySqlVulnerabilityAssessmentOperationOptions())` can be used to do batched pagination +items, err := client.ListBySqlVulnerabilityAssessmentComplete(ctx, id, sqlvulnerabilityassessmentbaseline.DefaultListBySqlVulnerabilityAssessmentOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/client.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/client.go new file mode 100644 index 00000000000..1e818dc798f --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/client.go @@ -0,0 +1,26 @@ +package sqlvulnerabilityassessmentbaseline + +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 SqlVulnerabilityAssessmentBaselineClient struct { + Client *resourcemanager.Client +} + +func NewSqlVulnerabilityAssessmentBaselineClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVulnerabilityAssessmentBaselineClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlvulnerabilityassessmentbaseline", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVulnerabilityAssessmentBaselineClient: %+v", err) + } + + return &SqlVulnerabilityAssessmentBaselineClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/constants.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/constants.go new file mode 100644 index 00000000000..5e61d87e116 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/constants.go @@ -0,0 +1,48 @@ +package sqlvulnerabilityassessmentbaseline + +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 VulnerabilityAssessmentSystemDatabaseName string + +const ( + VulnerabilityAssessmentSystemDatabaseNameMaster VulnerabilityAssessmentSystemDatabaseName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentSystemDatabaseName() []string { + return []string{ + string(VulnerabilityAssessmentSystemDatabaseNameMaster), + } +} + +func (s *VulnerabilityAssessmentSystemDatabaseName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentSystemDatabaseName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentSystemDatabaseName(input string) (*VulnerabilityAssessmentSystemDatabaseName, error) { + vals := map[string]VulnerabilityAssessmentSystemDatabaseName{ + "master": VulnerabilityAssessmentSystemDatabaseNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentSystemDatabaseName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_createorupdate.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_createorupdate.go new file mode 100644 index 00000000000..5134e7ba381 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_createorupdate.go @@ -0,0 +1,88 @@ +package sqlvulnerabilityassessmentbaseline + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +type CreateOrUpdateOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// CreateOrUpdate ... +func (c SqlVulnerabilityAssessmentBaselineClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input DatabaseSqlVulnerabilityAssessmentRuleBaselineListInput, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/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 DatabaseSqlVulnerabilityAssessmentBaselineSet + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_get.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_get.go new file mode 100644 index 00000000000..d3dc6e72e80 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_get.go @@ -0,0 +1,84 @@ +package sqlvulnerabilityassessmentbaseline + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +type GetOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +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.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// Get ... +func (c SqlVulnerabilityAssessmentBaselineClient) Get(ctx context.Context, id commonids.SqlServerId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/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 DatabaseSqlVulnerabilityAssessmentBaselineSet + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go new file mode 100644 index 00000000000..c66768fe7e8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go @@ -0,0 +1,135 @@ +package sqlvulnerabilityassessmentbaseline + +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 ListBySqlVulnerabilityAssessmentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +type ListBySqlVulnerabilityAssessmentCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseSqlVulnerabilityAssessmentBaselineSet +} + +type ListBySqlVulnerabilityAssessmentOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultListBySqlVulnerabilityAssessmentOperationOptions() ListBySqlVulnerabilityAssessmentOperationOptions { + return ListBySqlVulnerabilityAssessmentOperationOptions{} +} + +func (o ListBySqlVulnerabilityAssessmentOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySqlVulnerabilityAssessmentOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySqlVulnerabilityAssessmentOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +type ListBySqlVulnerabilityAssessmentCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySqlVulnerabilityAssessmentCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySqlVulnerabilityAssessment ... +func (c SqlVulnerabilityAssessmentBaselineClient) ListBySqlVulnerabilityAssessment(ctx context.Context, id commonids.SqlServerId, options ListBySqlVulnerabilityAssessmentOperationOptions) (result ListBySqlVulnerabilityAssessmentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySqlVulnerabilityAssessmentCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines", 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 *[]DatabaseSqlVulnerabilityAssessmentBaselineSet `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySqlVulnerabilityAssessmentComplete retrieves all the results into a single object +func (c SqlVulnerabilityAssessmentBaselineClient) ListBySqlVulnerabilityAssessmentComplete(ctx context.Context, id commonids.SqlServerId, options ListBySqlVulnerabilityAssessmentOperationOptions) (ListBySqlVulnerabilityAssessmentCompleteResult, error) { + return c.ListBySqlVulnerabilityAssessmentCompleteMatchingPredicate(ctx, id, options, DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate{}) +} + +// ListBySqlVulnerabilityAssessmentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVulnerabilityAssessmentBaselineClient) ListBySqlVulnerabilityAssessmentCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, options ListBySqlVulnerabilityAssessmentOperationOptions, predicate DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate) (result ListBySqlVulnerabilityAssessmentCompleteResult, err error) { + items := make([]DatabaseSqlVulnerabilityAssessmentBaselineSet, 0) + + resp, err := c.ListBySqlVulnerabilityAssessment(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySqlVulnerabilityAssessmentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go new file mode 100644 index 00000000000..fa600b3a994 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentbaseline + +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 DatabaseSqlVulnerabilityAssessmentBaselineSet struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentBaselineSetProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go new file mode 100644 index 00000000000..d416788e082 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go @@ -0,0 +1,8 @@ +package sqlvulnerabilityassessmentbaseline + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentBaselineSetProperties struct { + Results map[string][][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go new file mode 100644 index 00000000000..81c28830b78 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentbaseline + +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 DatabaseSqlVulnerabilityAssessmentRuleBaselineListInput struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentRuleBaselineListInputProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go new file mode 100644 index 00000000000..9e526631947 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go @@ -0,0 +1,9 @@ +package sqlvulnerabilityassessmentbaseline + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineListInputProperties struct { + LatestScan bool `json:"latestScan"` + Results map[string][][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/predicates.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/predicates.go new file mode 100644 index 00000000000..44e30273ae7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/predicates.go @@ -0,0 +1,27 @@ +package sqlvulnerabilityassessmentbaseline + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseSqlVulnerabilityAssessmentBaselineSetOperationPredicate) Matches(input DatabaseSqlVulnerabilityAssessmentBaselineSet) 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/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/version.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/version.go new file mode 100644 index 00000000000..cd85e0fff5d --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentbaseline/version.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentbaseline + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlvulnerabilityassessmentbaseline/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/client.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/client.go new file mode 100644 index 00000000000..7630b387bae --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/client.go @@ -0,0 +1,26 @@ +package sqlvulnerabilityassessmentexecutescan + +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 SqlVulnerabilityAssessmentExecuteScanClient struct { + Client *resourcemanager.Client +} + +func NewSqlVulnerabilityAssessmentExecuteScanClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVulnerabilityAssessmentExecuteScanClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlvulnerabilityassessmentexecutescan", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVulnerabilityAssessmentExecuteScanClient: %+v", err) + } + + return &SqlVulnerabilityAssessmentExecuteScanClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/constants.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/constants.go new file mode 100644 index 00000000000..b7cf5e2e180 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/constants.go @@ -0,0 +1,48 @@ +package sqlvulnerabilityassessmentexecutescan + +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 VulnerabilityAssessmentSystemDatabaseName string + +const ( + VulnerabilityAssessmentSystemDatabaseNameMaster VulnerabilityAssessmentSystemDatabaseName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentSystemDatabaseName() []string { + return []string{ + string(VulnerabilityAssessmentSystemDatabaseNameMaster), + } +} + +func (s *VulnerabilityAssessmentSystemDatabaseName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentSystemDatabaseName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentSystemDatabaseName(input string) (*VulnerabilityAssessmentSystemDatabaseName, error) { + vals := map[string]VulnerabilityAssessmentSystemDatabaseName{ + "master": VulnerabilityAssessmentSystemDatabaseNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentSystemDatabaseName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/method_execute.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/method_execute.go new file mode 100644 index 00000000000..3c6a1925406 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/method_execute.go @@ -0,0 +1,100 @@ +package sqlvulnerabilityassessmentexecutescan + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExecuteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +type ExecuteOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultExecuteOperationOptions() ExecuteOperationOptions { + return ExecuteOperationOptions{} +} + +func (o ExecuteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ExecuteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ExecuteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// Execute ... +func (c SqlVulnerabilityAssessmentExecuteScanClient) Execute(ctx context.Context, id commonids.SqlServerId, options ExecuteOperationOptions) (result ExecuteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/initiateScan", 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 +} + +// ExecuteThenPoll performs Execute then polls until it's completed +func (c SqlVulnerabilityAssessmentExecuteScanClient) ExecuteThenPoll(ctx context.Context, id commonids.SqlServerId, options ExecuteOperationOptions) error { + result, err := c.Execute(ctx, id, options) + if err != nil { + return fmt.Errorf("performing Execute: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Execute: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/version.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/version.go new file mode 100644 index 00000000000..b68abf8cb95 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentexecutescan/version.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentexecutescan + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlvulnerabilityassessmentexecutescan/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/README.md b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/README.md new file mode 100644 index 00000000000..1494f524640 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline` Documentation + +The `sqlvulnerabilityassessmentrulebaseline` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentrulebaseline.NewSqlVulnerabilityAssessmentRuleBaselineClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentRuleBaselineClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentrulebaseline.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ruleId") + +payload := sqlvulnerabilityassessmentrulebaseline.DatabaseSqlVulnerabilityAssessmentRuleBaselineInput{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, sqlvulnerabilityassessmentrulebaseline.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentRuleBaselineClient.Delete` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentrulebaseline.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ruleId") + +read, err := client.Delete(ctx, id, sqlvulnerabilityassessmentrulebaseline.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentRuleBaselineClient.Get` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentrulebaseline.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ruleId") + +read, err := client.Get(ctx, id, sqlvulnerabilityassessmentrulebaseline.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentRuleBaselineClient.ListByBaseline` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByBaseline(ctx, id, sqlvulnerabilityassessmentrulebaseline.DefaultListByBaselineOperationOptions())` can be used to do batched pagination +items, err := client.ListByBaselineComplete(ctx, id, sqlvulnerabilityassessmentrulebaseline.DefaultListByBaselineOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/client.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/client.go new file mode 100644 index 00000000000..fc8f0110ab3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/client.go @@ -0,0 +1,26 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 SqlVulnerabilityAssessmentRuleBaselineClient struct { + Client *resourcemanager.Client +} + +func NewSqlVulnerabilityAssessmentRuleBaselineClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVulnerabilityAssessmentRuleBaselineClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlvulnerabilityassessmentrulebaseline", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVulnerabilityAssessmentRuleBaselineClient: %+v", err) + } + + return &SqlVulnerabilityAssessmentRuleBaselineClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/constants.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/constants.go new file mode 100644 index 00000000000..83ba984694b --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/constants.go @@ -0,0 +1,48 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 VulnerabilityAssessmentSystemDatabaseName string + +const ( + VulnerabilityAssessmentSystemDatabaseNameMaster VulnerabilityAssessmentSystemDatabaseName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentSystemDatabaseName() []string { + return []string{ + string(VulnerabilityAssessmentSystemDatabaseNameMaster), + } +} + +func (s *VulnerabilityAssessmentSystemDatabaseName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentSystemDatabaseName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentSystemDatabaseName(input string) (*VulnerabilityAssessmentSystemDatabaseName, error) { + vals := map[string]VulnerabilityAssessmentSystemDatabaseName{ + "master": VulnerabilityAssessmentSystemDatabaseNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentSystemDatabaseName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule.go new file mode 100644 index 00000000000..66924181db5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule.go @@ -0,0 +1,143 @@ +package sqlvulnerabilityassessmentrulebaseline + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RuleId{}) +} + +var _ resourceids.ResourceId = &RuleId{} + +// RuleId is a struct representing the Resource ID for a Rule +type RuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + RuleId string +} + +// NewRuleID returns a new RuleId struct +func NewRuleID(subscriptionId string, resourceGroupName string, serverName string, ruleId string) RuleId { + return RuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + RuleId: ruleId, + } +} + +// ParseRuleID parses 'input' into a RuleId +func ParseRuleID(input string) (*RuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRuleIDInsensitively parses 'input' case-insensitively into a RuleId +// note: this method should only be used for API response data and not user input +func ParseRuleIDInsensitively(input string) (*RuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + return nil +} + +// ValidateRuleID checks that 'input' can be parsed as a Rule ID +func ValidateRuleID(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 := ParseRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rule ID +func (id RuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/sqlVulnerabilityAssessments/default/baselines/default/rules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.RuleId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rule ID +func (id RuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.StaticSegment("baselineName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleId"), + } +} + +// String returns a human-readable description of this Rule ID +func (id RuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Rule: %q", id.RuleId), + } + return fmt.Sprintf("Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go new file mode 100644 index 00000000000..5f2e4d8c6d4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go @@ -0,0 +1,387 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 = &RuleId{} + +func TestNewRuleID(t *testing.T) { + id := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ruleId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.RuleId != "ruleId" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleId") + } +} + +func TestFormatRuleID(t *testing.T) { + actual := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "ruleId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + RuleId: "ruleId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestParseRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + RuleId: "ruleId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiD", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + RuleId: "rUlEiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestSegmentsForRuleId(t *testing.T) { + segments := RuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RuleId 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/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go new file mode 100644 index 00000000000..183bef4b1c9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go @@ -0,0 +1,87 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +type CreateOrUpdateOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// CreateOrUpdate ... +func (c SqlVulnerabilityAssessmentRuleBaselineClient) CreateOrUpdate(ctx context.Context, id RuleId, input DatabaseSqlVulnerabilityAssessmentRuleBaselineInput, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + 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 DatabaseSqlVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_delete.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_delete.go new file mode 100644 index 00000000000..59cc6704c63 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_delete.go @@ -0,0 +1,77 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// Delete ... +func (c SqlVulnerabilityAssessmentRuleBaselineClient) Delete(ctx context.Context, id RuleId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_get.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_get.go new file mode 100644 index 00000000000..cf61914333c --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_get.go @@ -0,0 +1,83 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 *DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +type GetOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +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.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// Get ... +func (c SqlVulnerabilityAssessmentRuleBaselineClient) Get(ctx context.Context, id RuleId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 DatabaseSqlVulnerabilityAssessmentRuleBaseline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go new file mode 100644 index 00000000000..3a74f8a6c2e --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go @@ -0,0 +1,135 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 ListByBaselineOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +type ListByBaselineCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatabaseSqlVulnerabilityAssessmentRuleBaseline +} + +type ListByBaselineOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultListByBaselineOperationOptions() ListByBaselineOperationOptions { + return ListByBaselineOperationOptions{} +} + +func (o ListByBaselineOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByBaselineOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByBaselineOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +type ListByBaselineCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByBaselineCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByBaseline ... +func (c SqlVulnerabilityAssessmentRuleBaselineClient) ListByBaseline(ctx context.Context, id commonids.SqlServerId, options ListByBaselineOperationOptions) (result ListByBaselineOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByBaselineCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/default/rules", 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 *[]DatabaseSqlVulnerabilityAssessmentRuleBaseline `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByBaselineComplete retrieves all the results into a single object +func (c SqlVulnerabilityAssessmentRuleBaselineClient) ListByBaselineComplete(ctx context.Context, id commonids.SqlServerId, options ListByBaselineOperationOptions) (ListByBaselineCompleteResult, error) { + return c.ListByBaselineCompleteMatchingPredicate(ctx, id, options, DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate{}) +} + +// ListByBaselineCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVulnerabilityAssessmentRuleBaselineClient) ListByBaselineCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, options ListByBaselineOperationOptions, predicate DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate) (result ListByBaselineCompleteResult, err error) { + items := make([]DatabaseSqlVulnerabilityAssessmentRuleBaseline, 0) + + resp, err := c.ListByBaseline(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByBaselineCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..45f5daf543e --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 DatabaseSqlVulnerabilityAssessmentRuleBaseline struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentRuleBaselineProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go new file mode 100644 index 00000000000..089779a40e8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentrulebaseline + +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 DatabaseSqlVulnerabilityAssessmentRuleBaselineInput struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseSqlVulnerabilityAssessmentRuleBaselineInputProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go new file mode 100644 index 00000000000..a971b121ac1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go @@ -0,0 +1,9 @@ +package sqlvulnerabilityassessmentrulebaseline + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineInputProperties struct { + LatestScan bool `json:"latestScan"` + Results [][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..86e599aa279 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go @@ -0,0 +1,8 @@ +package sqlvulnerabilityassessmentrulebaseline + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineProperties struct { + Results [][]string `json:"results"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/predicates.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/predicates.go new file mode 100644 index 00000000000..3a316472e5d --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/predicates.go @@ -0,0 +1,27 @@ +package sqlvulnerabilityassessmentrulebaseline + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseSqlVulnerabilityAssessmentRuleBaselineOperationPredicate) Matches(input DatabaseSqlVulnerabilityAssessmentRuleBaseline) 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/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/version.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/version.go new file mode 100644 index 00000000000..ca35e9826da --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentrulebaseline/version.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentrulebaseline + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlvulnerabilityassessmentrulebaseline/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/README.md b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/README.md new file mode 100644 index 00000000000..e191bf70cbb --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult` Documentation + +The `sqlvulnerabilityassessmentscanresult` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentscanresult.NewSqlVulnerabilityAssessmentScanResultClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentScanResultClient.Get` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentscanresult.NewScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId", "scanResultId") + +read, err := client.Get(ctx, id, sqlvulnerabilityassessmentscanresult.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentScanResultClient.ListByScan` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentscanresult.NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId") + +// alternatively `client.ListByScan(ctx, id, sqlvulnerabilityassessmentscanresult.DefaultListByScanOperationOptions())` can be used to do batched pagination +items, err := client.ListByScanComplete(ctx, id, sqlvulnerabilityassessmentscanresult.DefaultListByScanOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/client.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/client.go new file mode 100644 index 00000000000..f0907cdc0c0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/client.go @@ -0,0 +1,26 @@ +package sqlvulnerabilityassessmentscanresult + +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 SqlVulnerabilityAssessmentScanResultClient struct { + Client *resourcemanager.Client +} + +func NewSqlVulnerabilityAssessmentScanResultClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVulnerabilityAssessmentScanResultClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlvulnerabilityassessmentscanresult", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVulnerabilityAssessmentScanResultClient: %+v", err) + } + + return &SqlVulnerabilityAssessmentScanResultClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/constants.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/constants.go new file mode 100644 index 00000000000..e5ebfd1043d --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/constants.go @@ -0,0 +1,189 @@ +package sqlvulnerabilityassessmentscanresult + +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 RuleSeverity string + +const ( + RuleSeverityHigh RuleSeverity = "High" + RuleSeverityInformational RuleSeverity = "Informational" + RuleSeverityLow RuleSeverity = "Low" + RuleSeverityMedium RuleSeverity = "Medium" + RuleSeverityObsolete RuleSeverity = "Obsolete" +) + +func PossibleValuesForRuleSeverity() []string { + return []string{ + string(RuleSeverityHigh), + string(RuleSeverityInformational), + string(RuleSeverityLow), + string(RuleSeverityMedium), + string(RuleSeverityObsolete), + } +} + +func (s *RuleSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleSeverity(input string) (*RuleSeverity, error) { + vals := map[string]RuleSeverity{ + "high": RuleSeverityHigh, + "informational": RuleSeverityInformational, + "low": RuleSeverityLow, + "medium": RuleSeverityMedium, + "obsolete": RuleSeverityObsolete, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleSeverity(input) + return &out, nil +} + +type RuleStatus string + +const ( + RuleStatusFinding RuleStatus = "Finding" + RuleStatusInternalError RuleStatus = "InternalError" + RuleStatusNonFinding RuleStatus = "NonFinding" +) + +func PossibleValuesForRuleStatus() []string { + return []string{ + string(RuleStatusFinding), + string(RuleStatusInternalError), + string(RuleStatusNonFinding), + } +} + +func (s *RuleStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleStatus(input string) (*RuleStatus, error) { + vals := map[string]RuleStatus{ + "finding": RuleStatusFinding, + "internalerror": RuleStatusInternalError, + "nonfinding": RuleStatusNonFinding, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleStatus(input) + return &out, nil +} + +type RuleType string + +const ( + RuleTypeBaselineExpected RuleType = "BaselineExpected" + RuleTypeBinary RuleType = "Binary" + RuleTypeNegativeList RuleType = "NegativeList" + RuleTypePositiveList RuleType = "PositiveList" +) + +func PossibleValuesForRuleType() []string { + return []string{ + string(RuleTypeBaselineExpected), + string(RuleTypeBinary), + string(RuleTypeNegativeList), + string(RuleTypePositiveList), + } +} + +func (s *RuleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleType(input string) (*RuleType, error) { + vals := map[string]RuleType{ + "baselineexpected": RuleTypeBaselineExpected, + "binary": RuleTypeBinary, + "negativelist": RuleTypeNegativeList, + "positivelist": RuleTypePositiveList, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleType(input) + return &out, nil +} + +type VulnerabilityAssessmentSystemDatabaseName string + +const ( + VulnerabilityAssessmentSystemDatabaseNameMaster VulnerabilityAssessmentSystemDatabaseName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentSystemDatabaseName() []string { + return []string{ + string(VulnerabilityAssessmentSystemDatabaseNameMaster), + } +} + +func (s *VulnerabilityAssessmentSystemDatabaseName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentSystemDatabaseName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentSystemDatabaseName(input string) (*VulnerabilityAssessmentSystemDatabaseName, error) { + vals := map[string]VulnerabilityAssessmentSystemDatabaseName{ + "master": VulnerabilityAssessmentSystemDatabaseNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentSystemDatabaseName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan.go new file mode 100644 index 00000000000..ff8b35dbbaa --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan.go @@ -0,0 +1,141 @@ +package sqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScanId{}) +} + +var _ resourceids.ResourceId = &ScanId{} + +// ScanId is a struct representing the Resource ID for a Scan +type ScanId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + ScanId string +} + +// NewScanID returns a new ScanId struct +func NewScanID(subscriptionId string, resourceGroupName string, serverName string, scanId string) ScanId { + return ScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + ScanId: scanId, + } +} + +// ParseScanID parses 'input' into a ScanId +func ParseScanID(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanIDInsensitively parses 'input' case-insensitively into a ScanId +// note: this method should only be used for API response data and not user input +func ParseScanIDInsensitively(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateScanID checks that 'input' can be parsed as a Scan ID +func ValidateScanID(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 := ParseScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan ID +func (id ScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/sqlVulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan ID +func (id ScanId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + } +} + +// String returns a human-readable description of this Scan ID +func (id ScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan_test.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan_test.go new file mode 100644 index 00000000000..7c9cc1075ff --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scan_test.go @@ -0,0 +1,357 @@ +package sqlvulnerabilityassessmentscanresult + +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 = &ScanId{} + +func TestNewScanID(t *testing.T) { + id := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + ScanId: "sCaNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForScanId(t *testing.T) { + segments := ScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanId 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/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult.go new file mode 100644 index 00000000000..eabe056c25b --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult.go @@ -0,0 +1,150 @@ +package sqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScanResultId{}) +} + +var _ resourceids.ResourceId = &ScanResultId{} + +// ScanResultId is a struct representing the Resource ID for a Scan Result +type ScanResultId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + ScanId string + ScanResultId string +} + +// NewScanResultID returns a new ScanResultId struct +func NewScanResultID(subscriptionId string, resourceGroupName string, serverName string, scanId string, scanResultId string) ScanResultId { + return ScanResultId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + ScanId: scanId, + ScanResultId: scanResultId, + } +} + +// ParseScanResultID parses 'input' into a ScanResultId +func ParseScanResultID(input string) (*ScanResultId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanResultId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanResultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanResultIDInsensitively parses 'input' case-insensitively into a ScanResultId +// note: this method should only be used for API response data and not user input +func ParseScanResultIDInsensitively(input string) (*ScanResultId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanResultId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanResultId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanResultId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + if id.ScanResultId, ok = input.Parsed["scanResultId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanResultId", input) + } + + return nil +} + +// ValidateScanResultID checks that 'input' can be parsed as a Scan Result ID +func ValidateScanResultID(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 := ParseScanResultID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan Result ID +func (id ScanResultId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/sqlVulnerabilityAssessments/default/scans/%s/scanResults/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.ScanId, id.ScanResultId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan Result ID +func (id ScanResultId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + resourceids.StaticSegment("staticScanResults", "scanResults", "scanResults"), + resourceids.UserSpecifiedSegment("scanResultId", "scanResultId"), + } +} + +// String returns a human-readable description of this Scan Result ID +func (id ScanResultId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Scan: %q", id.ScanId), + fmt.Sprintf("Scan Result: %q", id.ScanResultId), + } + return fmt.Sprintf("Scan Result (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go new file mode 100644 index 00000000000..4d3fc090a22 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go @@ -0,0 +1,402 @@ +package sqlvulnerabilityassessmentscanresult + +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 = &ScanResultId{} + +func TestNewScanResultID(t *testing.T) { + id := NewScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId", "scanResultId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } + + if id.ScanResultId != "scanResultId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanResultId'", id.ScanResultId, "scanResultId") + } +} + +func TestFormatScanResultID(t *testing.T) { + actual := NewScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId", "scanResultId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanResultID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanResultId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId", + Expected: &ScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ScanId: "scanId", + ScanResultId: "scanResultId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanResultID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + if actual.ScanResultId != v.Expected.ScanResultId { + t.Fatalf("Expected %q but got %q for ScanResultId", v.Expected.ScanResultId, actual.ScanResultId) + } + + } +} + +func TestParseScanResultIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanResultId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/sCaNrEsUlTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId", + Expected: &ScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ScanId: "scanId", + ScanResultId: "scanResultId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/scanResults/scanResultId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/sCaNrEsUlTs/sCaNrEsUlTiD", + Expected: &ScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + ScanId: "sCaNiD", + ScanResultId: "sCaNrEsUlTiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/sCaNrEsUlTs/sCaNrEsUlTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanResultIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + if actual.ScanResultId != v.Expected.ScanResultId { + t.Fatalf("Expected %q but got %q for ScanResultId", v.Expected.ScanResultId, actual.ScanResultId) + } + + } +} + +func TestSegmentsForScanResultId(t *testing.T) { + segments := ScanResultId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanResultId 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/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_get.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_get.go new file mode 100644 index 00000000000..082625df697 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_get.go @@ -0,0 +1,83 @@ +package sqlvulnerabilityassessmentscanresult + +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 *SqlVulnerabilityAssessmentScanResults +} + +type GetOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +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.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// Get ... +func (c SqlVulnerabilityAssessmentScanResultClient) Get(ctx context.Context, id ScanResultId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 SqlVulnerabilityAssessmentScanResults + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_listbyscan.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_listbyscan.go new file mode 100644 index 00000000000..c893fd92bda --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/method_listbyscan.go @@ -0,0 +1,134 @@ +package sqlvulnerabilityassessmentscanresult + +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 ListByScanOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVulnerabilityAssessmentScanResults +} + +type ListByScanCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVulnerabilityAssessmentScanResults +} + +type ListByScanOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultListByScanOperationOptions() ListByScanOperationOptions { + return ListByScanOperationOptions{} +} + +func (o ListByScanOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByScanOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByScanOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +type ListByScanCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByScanCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByScan ... +func (c SqlVulnerabilityAssessmentScanResultClient) ListByScan(ctx context.Context, id ScanId, options ListByScanOperationOptions) (result ListByScanOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByScanCustomPager{}, + Path: fmt.Sprintf("%s/scanResults", 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 *[]SqlVulnerabilityAssessmentScanResults `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByScanComplete retrieves all the results into a single object +func (c SqlVulnerabilityAssessmentScanResultClient) ListByScanComplete(ctx context.Context, id ScanId, options ListByScanOperationOptions) (ListByScanCompleteResult, error) { + return c.ListByScanCompleteMatchingPredicate(ctx, id, options, SqlVulnerabilityAssessmentScanResultsOperationPredicate{}) +} + +// ListByScanCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVulnerabilityAssessmentScanResultClient) ListByScanCompleteMatchingPredicate(ctx context.Context, id ScanId, options ListByScanOperationOptions, predicate SqlVulnerabilityAssessmentScanResultsOperationPredicate) (result ListByScanCompleteResult, err error) { + items := make([]SqlVulnerabilityAssessmentScanResults, 0) + + resp, err := c.ListByScan(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByScanCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baseline.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baseline.go new file mode 100644 index 00000000000..b6753e09cf9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baseline.go @@ -0,0 +1,27 @@ +package sqlvulnerabilityassessmentscanresult + +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 Baseline struct { + ExpectedResults *[][]string `json:"expectedResults,omitempty"` + UpdatedTime *string `json:"updatedTime,omitempty"` +} + +func (o *Baseline) GetUpdatedTimeAsTime() (*time.Time, error) { + if o.UpdatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *Baseline) SetUpdatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go new file mode 100644 index 00000000000..43b730d3189 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go @@ -0,0 +1,11 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BaselineAdjustedResult struct { + Baseline *Baseline `json:"baseline,omitempty"` + ResultsNotInBaseline *[][]string `json:"resultsNotInBaseline,omitempty"` + ResultsOnlyInBaseline *[][]string `json:"resultsOnlyInBaseline,omitempty"` + Status *RuleStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go new file mode 100644 index 00000000000..35183264a3f --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go @@ -0,0 +1,9 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenchmarkReference struct { + Benchmark *string `json:"benchmark,omitempty"` + Reference *string `json:"reference,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_querycheck.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_querycheck.go new file mode 100644 index 00000000000..5ff2a48ca6c --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_querycheck.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryCheck struct { + ColumnNames *[]string `json:"columnNames,omitempty"` + ExpectedResult *[][]string `json:"expectedResult,omitempty"` + Query *string `json:"query,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_remediation.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_remediation.go new file mode 100644 index 00000000000..47242cdd78a --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_remediation.go @@ -0,0 +1,11 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Remediation struct { + Automated *bool `json:"automated,omitempty"` + Description *string `json:"description,omitempty"` + PortalLink *string `json:"portalLink,omitempty"` + Scripts *[]string `json:"scripts,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go new file mode 100644 index 00000000000..11ffa2656d9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go @@ -0,0 +1,15 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanResultProperties struct { + BaselineAdjustedResult *BaselineAdjustedResult `json:"baselineAdjustedResult,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + IsTrimmed *bool `json:"isTrimmed,omitempty"` + QueryResults *[][]string `json:"queryResults,omitempty"` + Remediation *Remediation `json:"remediation,omitempty"` + RuleId *string `json:"ruleId,omitempty"` + RuleMetadata *VaRule `json:"ruleMetadata,omitempty"` + Status *RuleStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go new file mode 100644 index 00000000000..3666bc9bd38 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentscanresult + +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 SqlVulnerabilityAssessmentScanResults struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlVulnerabilityAssessmentScanResultProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_varule.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_varule.go new file mode 100644 index 00000000000..19d7caae09c --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/model_varule.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VaRule struct { + BenchmarkReferences *[]BenchmarkReference `json:"benchmarkReferences,omitempty"` + Category *string `json:"category,omitempty"` + Description *string `json:"description,omitempty"` + QueryCheck *QueryCheck `json:"queryCheck,omitempty"` + Rationale *string `json:"rationale,omitempty"` + RuleId *string `json:"ruleId,omitempty"` + RuleType *RuleType `json:"ruleType,omitempty"` + Severity *RuleSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/predicates.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/predicates.go new file mode 100644 index 00000000000..9e077ad7c5e --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/predicates.go @@ -0,0 +1,27 @@ +package sqlvulnerabilityassessmentscanresult + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanResultsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlVulnerabilityAssessmentScanResultsOperationPredicate) Matches(input SqlVulnerabilityAssessmentScanResults) 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/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/version.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/version.go new file mode 100644 index 00000000000..c37e2e6c356 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscanresult/version.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentscanresult + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlvulnerabilityassessmentscanresult/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..d6966cd0299 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans` Documentation + +The `sqlvulnerabilityassessmentscans` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentscans.NewSqlVulnerabilityAssessmentScansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentScansClient.Get` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentscans.NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId") + +read, err := client.Get(ctx, id, sqlvulnerabilityassessmentscans.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentScansClient.ListBySqlVulnerabilityAssessments` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListBySqlVulnerabilityAssessments(ctx, id, sqlvulnerabilityassessmentscans.DefaultListBySqlVulnerabilityAssessmentsOperationOptions())` can be used to do batched pagination +items, err := client.ListBySqlVulnerabilityAssessmentsComplete(ctx, id, sqlvulnerabilityassessmentscans.DefaultListBySqlVulnerabilityAssessmentsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..6022bf8ed93 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/client.go @@ -0,0 +1,26 @@ +package sqlvulnerabilityassessmentscans + +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 SqlVulnerabilityAssessmentScansClient struct { + Client *resourcemanager.Client +} + +func NewSqlVulnerabilityAssessmentScansClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVulnerabilityAssessmentScansClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlvulnerabilityassessmentscans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVulnerabilityAssessmentScansClient: %+v", err) + } + + return &SqlVulnerabilityAssessmentScansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..273bc96eb12 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/constants.go @@ -0,0 +1,136 @@ +package sqlvulnerabilityassessmentscans + +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 VulnerabilityAssessmentScanState string + +const ( + VulnerabilityAssessmentScanStateFailed VulnerabilityAssessmentScanState = "Failed" + VulnerabilityAssessmentScanStateFailedToRun VulnerabilityAssessmentScanState = "FailedToRun" + VulnerabilityAssessmentScanStateInProgress VulnerabilityAssessmentScanState = "InProgress" + VulnerabilityAssessmentScanStatePassed VulnerabilityAssessmentScanState = "Passed" +) + +func PossibleValuesForVulnerabilityAssessmentScanState() []string { + return []string{ + string(VulnerabilityAssessmentScanStateFailed), + string(VulnerabilityAssessmentScanStateFailedToRun), + string(VulnerabilityAssessmentScanStateInProgress), + string(VulnerabilityAssessmentScanStatePassed), + } +} + +func (s *VulnerabilityAssessmentScanState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanState(input string) (*VulnerabilityAssessmentScanState, error) { + vals := map[string]VulnerabilityAssessmentScanState{ + "failed": VulnerabilityAssessmentScanStateFailed, + "failedtorun": VulnerabilityAssessmentScanStateFailedToRun, + "inprogress": VulnerabilityAssessmentScanStateInProgress, + "passed": VulnerabilityAssessmentScanStatePassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanState(input) + return &out, nil +} + +type VulnerabilityAssessmentScanTriggerType string + +const ( + VulnerabilityAssessmentScanTriggerTypeOnDemand VulnerabilityAssessmentScanTriggerType = "OnDemand" + VulnerabilityAssessmentScanTriggerTypeRecurring VulnerabilityAssessmentScanTriggerType = "Recurring" +) + +func PossibleValuesForVulnerabilityAssessmentScanTriggerType() []string { + return []string{ + string(VulnerabilityAssessmentScanTriggerTypeOnDemand), + string(VulnerabilityAssessmentScanTriggerTypeRecurring), + } +} + +func (s *VulnerabilityAssessmentScanTriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanTriggerType(input string) (*VulnerabilityAssessmentScanTriggerType, error) { + vals := map[string]VulnerabilityAssessmentScanTriggerType{ + "ondemand": VulnerabilityAssessmentScanTriggerTypeOnDemand, + "recurring": VulnerabilityAssessmentScanTriggerTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanTriggerType(input) + return &out, nil +} + +type VulnerabilityAssessmentSystemDatabaseName string + +const ( + VulnerabilityAssessmentSystemDatabaseNameMaster VulnerabilityAssessmentSystemDatabaseName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentSystemDatabaseName() []string { + return []string{ + string(VulnerabilityAssessmentSystemDatabaseNameMaster), + } +} + +func (s *VulnerabilityAssessmentSystemDatabaseName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentSystemDatabaseName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentSystemDatabaseName(input string) (*VulnerabilityAssessmentSystemDatabaseName, error) { + vals := map[string]VulnerabilityAssessmentSystemDatabaseName{ + "master": VulnerabilityAssessmentSystemDatabaseNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentSystemDatabaseName(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan.go new file mode 100644 index 00000000000..ad54ac886e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan.go @@ -0,0 +1,141 @@ +package sqlvulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScanId{}) +} + +var _ resourceids.ResourceId = &ScanId{} + +// ScanId is a struct representing the Resource ID for a Scan +type ScanId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + ScanId string +} + +// NewScanID returns a new ScanId struct +func NewScanID(subscriptionId string, resourceGroupName string, serverName string, scanId string) ScanId { + return ScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + ScanId: scanId, + } +} + +// ParseScanID parses 'input' into a ScanId +func ParseScanID(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanIDInsensitively parses 'input' case-insensitively into a ScanId +// note: this method should only be used for API response data and not user input +func ParseScanIDInsensitively(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateScanID checks that 'input' can be parsed as a Scan ID +func ValidateScanID(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 := ParseScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan ID +func (id ScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/sqlVulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan ID +func (id ScanId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanId"), + } +} + +// String returns a human-readable description of this Scan ID +func (id ScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan_test.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan_test.go new file mode 100644 index 00000000000..1d974fb5f07 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/id_scan_test.go @@ -0,0 +1,357 @@ +package sqlvulnerabilityassessmentscans + +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 = &ScanId{} + +func TestNewScanID(t *testing.T) { + id := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.ScanId != "scanId" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanId") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "scanId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + ScanId: "scanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/sqlVulnerabilityAssessments/default/scans/scanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + ScanId: "sCaNiD", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForScanId(t *testing.T) { + segments := ScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanId 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/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..111ac936214 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_get.go @@ -0,0 +1,83 @@ +package sqlvulnerabilityassessmentscans + +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 *SqlVulnerabilityAssessmentScanRecord +} + +type GetOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +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.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +// Get ... +func (c SqlVulnerabilityAssessmentScansClient) Get(ctx context.Context, id ScanId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + 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 SqlVulnerabilityAssessmentScanRecord + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go new file mode 100644 index 00000000000..1aee57eba1e --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go @@ -0,0 +1,135 @@ +package sqlvulnerabilityassessmentscans + +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 ListBySqlVulnerabilityAssessmentsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVulnerabilityAssessmentScanRecord +} + +type ListBySqlVulnerabilityAssessmentsCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVulnerabilityAssessmentScanRecord +} + +type ListBySqlVulnerabilityAssessmentsOperationOptions struct { + SystemDatabaseName *VulnerabilityAssessmentSystemDatabaseName +} + +func DefaultListBySqlVulnerabilityAssessmentsOperationOptions() ListBySqlVulnerabilityAssessmentsOperationOptions { + return ListBySqlVulnerabilityAssessmentsOperationOptions{} +} + +func (o ListBySqlVulnerabilityAssessmentsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySqlVulnerabilityAssessmentsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySqlVulnerabilityAssessmentsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.SystemDatabaseName != nil { + out.Append("systemDatabaseName", fmt.Sprintf("%v", *o.SystemDatabaseName)) + } + return &out +} + +type ListBySqlVulnerabilityAssessmentsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySqlVulnerabilityAssessmentsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySqlVulnerabilityAssessments ... +func (c SqlVulnerabilityAssessmentScansClient) ListBySqlVulnerabilityAssessments(ctx context.Context, id commonids.SqlServerId, options ListBySqlVulnerabilityAssessmentsOperationOptions) (result ListBySqlVulnerabilityAssessmentsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySqlVulnerabilityAssessmentsCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/scans", 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 *[]SqlVulnerabilityAssessmentScanRecord `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySqlVulnerabilityAssessmentsComplete retrieves all the results into a single object +func (c SqlVulnerabilityAssessmentScansClient) ListBySqlVulnerabilityAssessmentsComplete(ctx context.Context, id commonids.SqlServerId, options ListBySqlVulnerabilityAssessmentsOperationOptions) (ListBySqlVulnerabilityAssessmentsCompleteResult, error) { + return c.ListBySqlVulnerabilityAssessmentsCompleteMatchingPredicate(ctx, id, options, SqlVulnerabilityAssessmentScanRecordOperationPredicate{}) +} + +// ListBySqlVulnerabilityAssessmentsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVulnerabilityAssessmentScansClient) ListBySqlVulnerabilityAssessmentsCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, options ListBySqlVulnerabilityAssessmentsOperationOptions, predicate SqlVulnerabilityAssessmentScanRecordOperationPredicate) (result ListBySqlVulnerabilityAssessmentsCompleteResult, err error) { + items := make([]SqlVulnerabilityAssessmentScanRecord, 0) + + resp, err := c.ListBySqlVulnerabilityAssessments(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySqlVulnerabilityAssessmentsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..0193e07c133 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go @@ -0,0 +1,9 @@ +package sqlvulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..445f634ac7d --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentscans + +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 SqlVulnerabilityAssessmentScanRecord struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlVulnerabilityAssessmentScanRecordProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..193f20cd4fd --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go @@ -0,0 +1,66 @@ +package sqlvulnerabilityassessmentscans + +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 SqlVulnerabilityAssessmentScanRecordProperties struct { + Database *string `json:"database,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Errors *[]SqlVulnerabilityAssessmentScanError `json:"errors,omitempty"` + HighSeverityFailedRulesCount *int64 `json:"highSeverityFailedRulesCount,omitempty"` + IsBaselineApplied *bool `json:"isBaselineApplied,omitempty"` + LastScanTime *string `json:"lastScanTime,omitempty"` + LowSeverityFailedRulesCount *int64 `json:"lowSeverityFailedRulesCount,omitempty"` + MediumSeverityFailedRulesCount *int64 `json:"mediumSeverityFailedRulesCount,omitempty"` + ScanId *string `json:"scanId,omitempty"` + Server *string `json:"server,omitempty"` + SqlVersion *string `json:"sqlVersion,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *VulnerabilityAssessmentScanState `json:"state,omitempty"` + TotalFailedRulesCount *int64 `json:"totalFailedRulesCount,omitempty"` + TotalPassedRulesCount *int64 `json:"totalPassedRulesCount,omitempty"` + TotalRulesCount *int64 `json:"totalRulesCount,omitempty"` + TriggerType *VulnerabilityAssessmentScanTriggerType `json:"triggerType,omitempty"` +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) GetLastScanTimeAsTime() (*time.Time, error) { + if o.LastScanTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastScanTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) SetLastScanTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastScanTime = &formatted +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlVulnerabilityAssessmentScanRecordProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..841a4654ae5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/predicates.go @@ -0,0 +1,27 @@ +package sqlvulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentScanRecordOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlVulnerabilityAssessmentScanRecordOperationPredicate) Matches(input SqlVulnerabilityAssessmentScanRecord) 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/sql/2023-08-01/sqlvulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..a7e72df7bea --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentscans/version.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentscans + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlvulnerabilityassessmentscans/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/README.md b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/README.md new file mode 100644 index 00000000000..d0ac826b938 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings` Documentation + +The `sqlvulnerabilityassessmentssettings` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentssettings.NewSqlVulnerabilityAssessmentsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentsSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := sqlvulnerabilityassessmentssettings.SqlVulnerabilityAssessment{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentsSettingsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +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: `SqlVulnerabilityAssessmentsSettingsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlVulnerabilityAssessmentsSettingsClient.SqlVulnerabilityAssessmentsDelete` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +read, err := client.SqlVulnerabilityAssessmentsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/client.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/client.go new file mode 100644 index 00000000000..bcda5c6d744 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/client.go @@ -0,0 +1,26 @@ +package sqlvulnerabilityassessmentssettings + +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 SqlVulnerabilityAssessmentsSettingsClient struct { + Client *resourcemanager.Client +} + +func NewSqlVulnerabilityAssessmentsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVulnerabilityAssessmentsSettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "sqlvulnerabilityassessmentssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVulnerabilityAssessmentsSettingsClient: %+v", err) + } + + return &SqlVulnerabilityAssessmentsSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/constants.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/constants.go new file mode 100644 index 00000000000..29b7b40e379 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/constants.go @@ -0,0 +1,51 @@ +package sqlvulnerabilityassessmentssettings + +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 SqlVulnerabilityAssessmentState string + +const ( + SqlVulnerabilityAssessmentStateDisabled SqlVulnerabilityAssessmentState = "Disabled" + SqlVulnerabilityAssessmentStateEnabled SqlVulnerabilityAssessmentState = "Enabled" +) + +func PossibleValuesForSqlVulnerabilityAssessmentState() []string { + return []string{ + string(SqlVulnerabilityAssessmentStateDisabled), + string(SqlVulnerabilityAssessmentStateEnabled), + } +} + +func (s *SqlVulnerabilityAssessmentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlVulnerabilityAssessmentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSqlVulnerabilityAssessmentState(input string) (*SqlVulnerabilityAssessmentState, error) { + vals := map[string]SqlVulnerabilityAssessmentState{ + "disabled": SqlVulnerabilityAssessmentStateDisabled, + "enabled": SqlVulnerabilityAssessmentStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SqlVulnerabilityAssessmentState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_createorupdate.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_createorupdate.go new file mode 100644 index 00000000000..f8794b7a57a --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_createorupdate.go @@ -0,0 +1,60 @@ +package sqlvulnerabilityassessmentssettings + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlVulnerabilityAssessment +} + +// CreateOrUpdate ... +func (c SqlVulnerabilityAssessmentsSettingsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlServerId, input SqlVulnerabilityAssessment) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/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 SqlVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_get.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_get.go new file mode 100644 index 00000000000..53e3c99ed3a --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_get.go @@ -0,0 +1,55 @@ +package sqlvulnerabilityassessmentssettings + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlVulnerabilityAssessment +} + +// Get ... +func (c SqlVulnerabilityAssessmentsSettingsClient) Get(ctx context.Context, id commonids.SqlServerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/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 SqlVulnerabilityAssessment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_listbyserver.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_listbyserver.go new file mode 100644 index 00000000000..14bdd4b30ed --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_listbyserver.go @@ -0,0 +1,106 @@ +package sqlvulnerabilityassessmentssettings + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVulnerabilityAssessment +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVulnerabilityAssessment +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c SqlVulnerabilityAssessmentsSettingsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments", 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 *[]SqlVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c SqlVulnerabilityAssessmentsSettingsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, SqlVulnerabilityAssessmentOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVulnerabilityAssessmentsSettingsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate SqlVulnerabilityAssessmentOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]SqlVulnerabilityAssessment, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go new file mode 100644 index 00000000000..75f28b2e157 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go @@ -0,0 +1,49 @@ +package sqlvulnerabilityassessmentssettings + +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 SqlVulnerabilityAssessmentsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlVulnerabilityAssessmentsDelete ... +func (c SqlVulnerabilityAssessmentsSettingsClient) SqlVulnerabilityAssessmentsDelete(ctx context.Context, id commonids.SqlServerId) (result SqlVulnerabilityAssessmentsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go new file mode 100644 index 00000000000..fe3b1f75fc8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go @@ -0,0 +1,16 @@ +package sqlvulnerabilityassessmentssettings + +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 SqlVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlVulnerabilityAssessmentPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go new file mode 100644 index 00000000000..ff16d81dbe1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go @@ -0,0 +1,8 @@ +package sqlvulnerabilityassessmentssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentPolicyProperties struct { + State *SqlVulnerabilityAssessmentState `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/predicates.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/predicates.go new file mode 100644 index 00000000000..ca44a89aef8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/predicates.go @@ -0,0 +1,27 @@ +package sqlvulnerabilityassessmentssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlVulnerabilityAssessmentOperationPredicate) Matches(input SqlVulnerabilityAssessment) 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/sql/2023-08-01/sqlvulnerabilityassessmentssettings/version.go b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/version.go new file mode 100644 index 00000000000..c16aaa56309 --- /dev/null +++ b/resource-manager/sql/2023-08-01/sqlvulnerabilityassessmentssettings/version.go @@ -0,0 +1,10 @@ +package sqlvulnerabilityassessmentssettings + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/sqlvulnerabilityassessmentssettings/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/README.md b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/README.md new file mode 100644 index 00000000000..d0827b1986d --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules` Documentation + +The `startstopmanagedinstanceschedules` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules" +``` + + +### Client Initialization + +```go +client := startstopmanagedinstanceschedules.NewStartStopManagedInstanceSchedulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StartStopManagedInstanceSchedulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +payload := startstopmanagedinstanceschedules.StartStopManagedInstanceSchedule{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StartStopManagedInstanceSchedulesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StartStopManagedInstanceSchedulesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +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: `StartStopManagedInstanceSchedulesClient.ListByInstance` + +```go +ctx := context.TODO() +id := commonids.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceName") + +// alternatively `client.ListByInstance(ctx, id)` can be used to do batched pagination +items, err := client.ListByInstanceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/client.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/client.go new file mode 100644 index 00000000000..aa4c62fed82 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/client.go @@ -0,0 +1,26 @@ +package startstopmanagedinstanceschedules + +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 StartStopManagedInstanceSchedulesClient struct { + Client *resourcemanager.Client +} + +func NewStartStopManagedInstanceSchedulesClientWithBaseURI(sdkApi sdkEnv.Api) (*StartStopManagedInstanceSchedulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "startstopmanagedinstanceschedules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StartStopManagedInstanceSchedulesClient: %+v", err) + } + + return &StartStopManagedInstanceSchedulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/constants.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/constants.go new file mode 100644 index 00000000000..d6f3effb1ef --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/constants.go @@ -0,0 +1,66 @@ +package startstopmanagedinstanceschedules + +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 DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_createorupdate.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_createorupdate.go new file mode 100644 index 00000000000..641d1d37389 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_createorupdate.go @@ -0,0 +1,60 @@ +package startstopmanagedinstanceschedules + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StartStopManagedInstanceSchedule +} + +// CreateOrUpdate ... +func (c StartStopManagedInstanceSchedulesClient) CreateOrUpdate(ctx context.Context, id commonids.SqlManagedInstanceId, input StartStopManagedInstanceSchedule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/startStopSchedules/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 StartStopManagedInstanceSchedule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_delete.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_delete.go new file mode 100644 index 00000000000..c49b841ccb4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_delete.go @@ -0,0 +1,49 @@ +package startstopmanagedinstanceschedules + +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 DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c StartStopManagedInstanceSchedulesClient) Delete(ctx context.Context, id commonids.SqlManagedInstanceId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/startStopSchedules/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 + } + + return +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_get.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_get.go new file mode 100644 index 00000000000..bc3bc1326f9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_get.go @@ -0,0 +1,55 @@ +package startstopmanagedinstanceschedules + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StartStopManagedInstanceSchedule +} + +// Get ... +func (c StartStopManagedInstanceSchedulesClient) Get(ctx context.Context, id commonids.SqlManagedInstanceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/startStopSchedules/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 StartStopManagedInstanceSchedule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_listbyinstance.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_listbyinstance.go new file mode 100644 index 00000000000..ea88a26dfa8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/method_listbyinstance.go @@ -0,0 +1,106 @@ +package startstopmanagedinstanceschedules + +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 ListByInstanceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StartStopManagedInstanceSchedule +} + +type ListByInstanceCompleteResult struct { + LatestHttpResponse *http.Response + Items []StartStopManagedInstanceSchedule +} + +type ListByInstanceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstanceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstance ... +func (c StartStopManagedInstanceSchedulesClient) ListByInstance(ctx context.Context, id commonids.SqlManagedInstanceId) (result ListByInstanceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByInstanceCustomPager{}, + Path: fmt.Sprintf("%s/startStopSchedules", 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 *[]StartStopManagedInstanceSchedule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstanceComplete retrieves all the results into a single object +func (c StartStopManagedInstanceSchedulesClient) ListByInstanceComplete(ctx context.Context, id commonids.SqlManagedInstanceId) (ListByInstanceCompleteResult, error) { + return c.ListByInstanceCompleteMatchingPredicate(ctx, id, StartStopManagedInstanceScheduleOperationPredicate{}) +} + +// ListByInstanceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StartStopManagedInstanceSchedulesClient) ListByInstanceCompleteMatchingPredicate(ctx context.Context, id commonids.SqlManagedInstanceId, predicate StartStopManagedInstanceScheduleOperationPredicate) (result ListByInstanceCompleteResult, err error) { + items := make([]StartStopManagedInstanceSchedule, 0) + + resp, err := c.ListByInstance(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstanceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_scheduleitem.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_scheduleitem.go new file mode 100644 index 00000000000..bea9c28f0f7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_scheduleitem.go @@ -0,0 +1,11 @@ +package startstopmanagedinstanceschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleItem struct { + StartDay DayOfWeek `json:"startDay"` + StartTime string `json:"startTime"` + StopDay DayOfWeek `json:"stopDay"` + StopTime string `json:"stopTime"` +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go new file mode 100644 index 00000000000..eab78ea62f2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go @@ -0,0 +1,16 @@ +package startstopmanagedinstanceschedules + +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 StartStopManagedInstanceSchedule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StartStopManagedInstanceScheduleProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go new file mode 100644 index 00000000000..5e556bd211e --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go @@ -0,0 +1,12 @@ +package startstopmanagedinstanceschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartStopManagedInstanceScheduleProperties struct { + Description *string `json:"description,omitempty"` + NextExecutionTime *string `json:"nextExecutionTime,omitempty"` + NextRunAction *string `json:"nextRunAction,omitempty"` + ScheduleList []ScheduleItem `json:"scheduleList"` + TimeZoneId *string `json:"timeZoneId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/predicates.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/predicates.go new file mode 100644 index 00000000000..60606bc2f22 --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/predicates.go @@ -0,0 +1,27 @@ +package startstopmanagedinstanceschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartStopManagedInstanceScheduleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p StartStopManagedInstanceScheduleOperationPredicate) Matches(input StartStopManagedInstanceSchedule) 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/sql/2023-08-01/startstopmanagedinstanceschedules/version.go b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/version.go new file mode 100644 index 00000000000..fd84b65dcec --- /dev/null +++ b/resource-manager/sql/2023-08-01/startstopmanagedinstanceschedules/version.go @@ -0,0 +1,10 @@ +package startstopmanagedinstanceschedules + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/startstopmanagedinstanceschedules/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/README.md b/resource-manager/sql/2023-08-01/subscriptionusages/README.md new file mode 100644 index 00000000000..c9fcd0bd8a2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/subscriptionusages` Documentation + +The `subscriptionusages` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/subscriptionusages" +``` + + +### Client Initialization + +```go +client := subscriptionusages.NewSubscriptionUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionUsagesClient.Get` + +```go +ctx := context.TODO() +id := subscriptionusages.NewUsageID("12345678-1234-9876-4563-123456789012", "locationName", "usageName") + +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: `SubscriptionUsagesClient.ListByLocation` + +```go +ctx := context.TODO() +id := subscriptionusages.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/client.go b/resource-manager/sql/2023-08-01/subscriptionusages/client.go new file mode 100644 index 00000000000..5829a9a22b0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/client.go @@ -0,0 +1,26 @@ +package subscriptionusages + +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 SubscriptionUsagesClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionUsagesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "subscriptionusages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionUsagesClient: %+v", err) + } + + return &SubscriptionUsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/id_location.go b/resource-manager/sql/2023-08-01/subscriptionusages/id_location.go new file mode 100644 index 00000000000..ea76435a821 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/id_location.go @@ -0,0 +1,121 @@ +package subscriptionusages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/id_location_test.go b/resource-manager/sql/2023-08-01/subscriptionusages/id_location_test.go new file mode 100644 index 00000000000..906599f0629 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/id_location_test.go @@ -0,0 +1,237 @@ +package subscriptionusages + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/subscriptionusages/id_usage.go b/resource-manager/sql/2023-08-01/subscriptionusages/id_usage.go new file mode 100644 index 00000000000..acf2bea2228 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/id_usage.go @@ -0,0 +1,130 @@ +package subscriptionusages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&UsageId{}) +} + +var _ resourceids.ResourceId = &UsageId{} + +// UsageId is a struct representing the Resource ID for a Usage +type UsageId struct { + SubscriptionId string + LocationName string + UsageName string +} + +// NewUsageID returns a new UsageId struct +func NewUsageID(subscriptionId string, locationName string, usageName string) UsageId { + return UsageId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + UsageName: usageName, + } +} + +// ParseUsageID parses 'input' into a UsageId +func ParseUsageID(input string) (*UsageId, error) { + parser := resourceids.NewParserFromResourceIdType(&UsageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UsageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseUsageIDInsensitively parses 'input' case-insensitively into a UsageId +// note: this method should only be used for API response data and not user input +func ParseUsageIDInsensitively(input string) (*UsageId, error) { + parser := resourceids.NewParserFromResourceIdType(&UsageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := UsageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *UsageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.UsageName, ok = input.Parsed["usageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "usageName", input) + } + + return nil +} + +// ValidateUsageID checks that 'input' can be parsed as a Usage ID +func ValidateUsageID(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 := ParseUsageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Usage ID +func (id UsageId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/usages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.UsageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Usage ID +func (id UsageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticUsages", "usages", "usages"), + resourceids.UserSpecifiedSegment("usageName", "usageName"), + } +} + +// String returns a human-readable description of this Usage ID +func (id UsageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Usage Name: %q", id.UsageName), + } + return fmt.Sprintf("Usage (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/id_usage_test.go b/resource-manager/sql/2023-08-01/subscriptionusages/id_usage_test.go new file mode 100644 index 00000000000..cc13dc72f75 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/id_usage_test.go @@ -0,0 +1,282 @@ +package subscriptionusages + +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 = &UsageId{} + +func TestNewUsageID(t *testing.T) { + id := NewUsageID("12345678-1234-9876-4563-123456789012", "locationName", "usageName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.UsageName != "usageName" { + t.Fatalf("Expected %q but got %q for Segment 'UsageName'", id.UsageName, "usageName") + } +} + +func TestFormatUsageID(t *testing.T) { + actual := NewUsageID("12345678-1234-9876-4563-123456789012", "locationName", "usageName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages/usageName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseUsageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UsageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages/usageName", + Expected: &UsageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + UsageName: "usageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages/usageName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUsageID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.UsageName != v.Expected.UsageName { + t.Fatalf("Expected %q but got %q for UsageName", v.Expected.UsageName, actual.UsageName) + } + + } +} + +func TestParseUsageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *UsageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/uSaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages/usageName", + Expected: &UsageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + UsageName: "usageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/usages/usageName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/uSaGeS/uSaGeNaMe", + Expected: &UsageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + UsageName: "uSaGeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/uSaGeS/uSaGeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseUsageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.UsageName != v.Expected.UsageName { + t.Fatalf("Expected %q but got %q for UsageName", v.Expected.UsageName, actual.UsageName) + } + + } +} + +func TestSegmentsForUsageId(t *testing.T) { + segments := UsageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("UsageId 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/sql/2023-08-01/subscriptionusages/method_get.go b/resource-manager/sql/2023-08-01/subscriptionusages/method_get.go new file mode 100644 index 00000000000..41027938a77 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/method_get.go @@ -0,0 +1,53 @@ +package subscriptionusages + +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 *SubscriptionUsage +} + +// Get ... +func (c SubscriptionUsagesClient) Get(ctx context.Context, id UsageId) (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 SubscriptionUsage + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/method_listbylocation.go b/resource-manager/sql/2023-08-01/subscriptionusages/method_listbylocation.go new file mode 100644 index 00000000000..084767e6180 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/method_listbylocation.go @@ -0,0 +1,105 @@ +package subscriptionusages + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SubscriptionUsage +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []SubscriptionUsage +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c SubscriptionUsagesClient) ListByLocation(ctx context.Context, id LocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SubscriptionUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c SubscriptionUsagesClient) ListByLocationComplete(ctx context.Context, id LocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, SubscriptionUsageOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SubscriptionUsagesClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate SubscriptionUsageOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]SubscriptionUsage, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusage.go b/resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusage.go new file mode 100644 index 00000000000..6e8d282ff7d --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusage.go @@ -0,0 +1,11 @@ +package subscriptionusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionUsage struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionUsageProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusageproperties.go b/resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusageproperties.go new file mode 100644 index 00000000000..ab8505b264c --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/model_subscriptionusageproperties.go @@ -0,0 +1,11 @@ +package subscriptionusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionUsageProperties struct { + CurrentValue *float64 `json:"currentValue,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/subscriptionusages/predicates.go b/resource-manager/sql/2023-08-01/subscriptionusages/predicates.go new file mode 100644 index 00000000000..f47c43bd9ee --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/predicates.go @@ -0,0 +1,27 @@ +package subscriptionusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionUsageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SubscriptionUsageOperationPredicate) Matches(input SubscriptionUsage) 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/sql/2023-08-01/subscriptionusages/version.go b/resource-manager/sql/2023-08-01/subscriptionusages/version.go new file mode 100644 index 00000000000..c446789dcd5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/subscriptionusages/version.go @@ -0,0 +1,10 @@ +package subscriptionusages + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/subscriptionusages/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/README.md b/resource-manager/sql/2023-08-01/synapselinkworkspaces/README.md new file mode 100644 index 00000000000..d83a6028e3b --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/synapselinkworkspaces` Documentation + +The `synapselinkworkspaces` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/synapselinkworkspaces" +``` + + +### Client Initialization + +```go +client := synapselinkworkspaces.NewSynapseLinkWorkspacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SynapseLinkWorkspacesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/client.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/client.go new file mode 100644 index 00000000000..cedd10aa1e4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/client.go @@ -0,0 +1,26 @@ +package synapselinkworkspaces + +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 SynapseLinkWorkspacesClient struct { + Client *resourcemanager.Client +} + +func NewSynapseLinkWorkspacesClientWithBaseURI(sdkApi sdkEnv.Api) (*SynapseLinkWorkspacesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "synapselinkworkspaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SynapseLinkWorkspacesClient: %+v", err) + } + + return &SynapseLinkWorkspacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/method_listbydatabase.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/method_listbydatabase.go new file mode 100644 index 00000000000..8444d646633 --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/method_listbydatabase.go @@ -0,0 +1,106 @@ +package synapselinkworkspaces + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SynapseLinkWorkspace +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SynapseLinkWorkspace +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c SynapseLinkWorkspacesClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/linkWorkspaces", 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 *[]SynapseLinkWorkspace `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c SynapseLinkWorkspacesClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, SynapseLinkWorkspaceOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SynapseLinkWorkspacesClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate SynapseLinkWorkspaceOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]SynapseLinkWorkspace, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspace.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspace.go new file mode 100644 index 00000000000..63ac1d2d9b4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspace.go @@ -0,0 +1,11 @@ +package synapselinkworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SynapseLinkWorkspace struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SynapseLinkWorkspaceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go new file mode 100644 index 00000000000..af48429cffb --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go @@ -0,0 +1,9 @@ +package synapselinkworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SynapseLinkWorkspaceInfoProperties struct { + LinkConnectionName *string `json:"linkConnectionName,omitempty"` + WorkspaceId *string `json:"workspaceId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceproperties.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceproperties.go new file mode 100644 index 00000000000..1e2edb488d5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/model_synapselinkworkspaceproperties.go @@ -0,0 +1,8 @@ +package synapselinkworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SynapseLinkWorkspaceProperties struct { + Workspaces *[]SynapseLinkWorkspaceInfoProperties `json:"workspaces,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/synapselinkworkspaces/predicates.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/predicates.go new file mode 100644 index 00000000000..8158a7bb3e3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/predicates.go @@ -0,0 +1,27 @@ +package synapselinkworkspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SynapseLinkWorkspaceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SynapseLinkWorkspaceOperationPredicate) Matches(input SynapseLinkWorkspace) 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/sql/2023-08-01/synapselinkworkspaces/version.go b/resource-manager/sql/2023-08-01/synapselinkworkspaces/version.go new file mode 100644 index 00000000000..e8b67048491 --- /dev/null +++ b/resource-manager/sql/2023-08-01/synapselinkworkspaces/version.go @@ -0,0 +1,10 @@ +package synapselinkworkspaces + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/synapselinkworkspaces/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/syncagents/README.md b/resource-manager/sql/2023-08-01/syncagents/README.md new file mode 100644 index 00000000000..5c47ef147db --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncagents` Documentation + +The `syncagents` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncagents" +``` + + +### Client Initialization + +```go +client := syncagents.NewSyncAgentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SyncAgentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := syncagents.NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName") + +payload := syncagents.SyncAgent{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncAgentsClient.Delete` + +```go +ctx := context.TODO() +id := syncagents.NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncAgentsClient.GenerateKey` + +```go +ctx := context.TODO() +id := syncagents.NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName") + +read, err := client.GenerateKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SyncAgentsClient.Get` + +```go +ctx := context.TODO() +id := syncagents.NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName") + +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: `SyncAgentsClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncAgentsClient.ListLinkedDatabases` + +```go +ctx := context.TODO() +id := syncagents.NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName") + +// alternatively `client.ListLinkedDatabases(ctx, id)` can be used to do batched pagination +items, err := client.ListLinkedDatabasesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/syncagents/client.go b/resource-manager/sql/2023-08-01/syncagents/client.go new file mode 100644 index 00000000000..8f3af4b9f9c --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/client.go @@ -0,0 +1,26 @@ +package syncagents + +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 SyncAgentsClient struct { + Client *resourcemanager.Client +} + +func NewSyncAgentsClientWithBaseURI(sdkApi sdkEnv.Api) (*SyncAgentsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "syncagents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SyncAgentsClient: %+v", err) + } + + return &SyncAgentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/syncagents/constants.go b/resource-manager/sql/2023-08-01/syncagents/constants.go new file mode 100644 index 00000000000..3fecddc1626 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/constants.go @@ -0,0 +1,95 @@ +package syncagents + +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 SyncAgentState string + +const ( + SyncAgentStateNeverConnected SyncAgentState = "NeverConnected" + SyncAgentStateOffline SyncAgentState = "Offline" + SyncAgentStateOnline SyncAgentState = "Online" +) + +func PossibleValuesForSyncAgentState() []string { + return []string{ + string(SyncAgentStateNeverConnected), + string(SyncAgentStateOffline), + string(SyncAgentStateOnline), + } +} + +func (s *SyncAgentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncAgentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncAgentState(input string) (*SyncAgentState, error) { + vals := map[string]SyncAgentState{ + "neverconnected": SyncAgentStateNeverConnected, + "offline": SyncAgentStateOffline, + "online": SyncAgentStateOnline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncAgentState(input) + return &out, nil +} + +type SyncMemberDbType string + +const ( + SyncMemberDbTypeAzureSqlDatabase SyncMemberDbType = "AzureSqlDatabase" + SyncMemberDbTypeSqlServerDatabase SyncMemberDbType = "SqlServerDatabase" +) + +func PossibleValuesForSyncMemberDbType() []string { + return []string{ + string(SyncMemberDbTypeAzureSqlDatabase), + string(SyncMemberDbTypeSqlServerDatabase), + } +} + +func (s *SyncMemberDbType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncMemberDbType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncMemberDbType(input string) (*SyncMemberDbType, error) { + vals := map[string]SyncMemberDbType{ + "azuresqldatabase": SyncMemberDbTypeAzureSqlDatabase, + "sqlserverdatabase": SyncMemberDbTypeSqlServerDatabase, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncMemberDbType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/syncagents/id_syncagent.go b/resource-manager/sql/2023-08-01/syncagents/id_syncagent.go new file mode 100644 index 00000000000..884fb683af3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/id_syncagent.go @@ -0,0 +1,139 @@ +package syncagents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SyncAgentId{}) +} + +var _ resourceids.ResourceId = &SyncAgentId{} + +// SyncAgentId is a struct representing the Resource ID for a Sync Agent +type SyncAgentId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + SyncAgentName string +} + +// NewSyncAgentID returns a new SyncAgentId struct +func NewSyncAgentID(subscriptionId string, resourceGroupName string, serverName string, syncAgentName string) SyncAgentId { + return SyncAgentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + SyncAgentName: syncAgentName, + } +} + +// ParseSyncAgentID parses 'input' into a SyncAgentId +func ParseSyncAgentID(input string) (*SyncAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncAgentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSyncAgentIDInsensitively parses 'input' case-insensitively into a SyncAgentId +// note: this method should only be used for API response data and not user input +func ParseSyncAgentIDInsensitively(input string) (*SyncAgentId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncAgentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncAgentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SyncAgentId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.SyncAgentName, ok = input.Parsed["syncAgentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "syncAgentName", input) + } + + return nil +} + +// ValidateSyncAgentID checks that 'input' can be parsed as a Sync Agent ID +func ValidateSyncAgentID(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 := ParseSyncAgentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sync Agent ID +func (id SyncAgentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/syncAgents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.SyncAgentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sync Agent ID +func (id SyncAgentId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticSyncAgents", "syncAgents", "syncAgents"), + resourceids.UserSpecifiedSegment("syncAgentName", "syncAgentName"), + } +} + +// String returns a human-readable description of this Sync Agent ID +func (id SyncAgentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Sync Agent Name: %q", id.SyncAgentName), + } + return fmt.Sprintf("Sync Agent (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/syncagents/id_syncagent_test.go b/resource-manager/sql/2023-08-01/syncagents/id_syncagent_test.go new file mode 100644 index 00000000000..b972dde5cf3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/id_syncagent_test.go @@ -0,0 +1,327 @@ +package syncagents + +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 = &SyncAgentId{} + +func TestNewSyncAgentID(t *testing.T) { + id := NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.SyncAgentName != "syncAgentName" { + t.Fatalf("Expected %q but got %q for Segment 'SyncAgentName'", id.SyncAgentName, "syncAgentName") + } +} + +func TestFormatSyncAgentID(t *testing.T) { + actual := NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "syncAgentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents/syncAgentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSyncAgentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents/syncAgentName", + Expected: &SyncAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + SyncAgentName: "syncAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents/syncAgentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncAgentID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.SyncAgentName != v.Expected.SyncAgentName { + t.Fatalf("Expected %q but got %q for SyncAgentName", v.Expected.SyncAgentName, actual.SyncAgentName) + } + + } +} + +func TestParseSyncAgentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncAgentId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sYnCaGeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents/syncAgentName", + Expected: &SyncAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + SyncAgentName: "syncAgentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/syncAgents/syncAgentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/sYnCaGeNtS/sYnCaGeNtNaMe", + Expected: &SyncAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + SyncAgentName: "sYnCaGeNtNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/sYnCaGeNtS/sYnCaGeNtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncAgentIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.SyncAgentName != v.Expected.SyncAgentName { + t.Fatalf("Expected %q but got %q for SyncAgentName", v.Expected.SyncAgentName, actual.SyncAgentName) + } + + } +} + +func TestSegmentsForSyncAgentId(t *testing.T) { + segments := SyncAgentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SyncAgentId 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/sql/2023-08-01/syncagents/method_createorupdate.go b/resource-manager/sql/2023-08-01/syncagents/method_createorupdate.go new file mode 100644 index 00000000000..b665e60b190 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/method_createorupdate.go @@ -0,0 +1,76 @@ +package syncagents + +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 *SyncAgent +} + +// CreateOrUpdate ... +func (c SyncAgentsClient) CreateOrUpdate(ctx context.Context, id SyncAgentId, input SyncAgent) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 SyncAgentsClient) CreateOrUpdateThenPoll(ctx context.Context, id SyncAgentId, input SyncAgent) 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/sql/2023-08-01/syncagents/method_delete.go b/resource-manager/sql/2023-08-01/syncagents/method_delete.go new file mode 100644 index 00000000000..2da29594db0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/method_delete.go @@ -0,0 +1,71 @@ +package syncagents + +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 SyncAgentsClient) Delete(ctx context.Context, id SyncAgentId) (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 SyncAgentsClient) DeleteThenPoll(ctx context.Context, id SyncAgentId) 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/sql/2023-08-01/syncagents/method_generatekey.go b/resource-manager/sql/2023-08-01/syncagents/method_generatekey.go new file mode 100644 index 00000000000..3d8fd5b7f4c --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/method_generatekey.go @@ -0,0 +1,54 @@ +package syncagents + +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 GenerateKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SyncAgentKeyProperties +} + +// GenerateKey ... +func (c SyncAgentsClient) GenerateKey(ctx context.Context, id SyncAgentId) (result GenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generateKey", 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 SyncAgentKeyProperties + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/syncagents/method_get.go b/resource-manager/sql/2023-08-01/syncagents/method_get.go new file mode 100644 index 00000000000..82b14cbc685 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/method_get.go @@ -0,0 +1,53 @@ +package syncagents + +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 *SyncAgent +} + +// Get ... +func (c SyncAgentsClient) Get(ctx context.Context, id SyncAgentId) (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 SyncAgent + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/syncagents/method_listbyserver.go b/resource-manager/sql/2023-08-01/syncagents/method_listbyserver.go new file mode 100644 index 00000000000..021f3655ff0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/method_listbyserver.go @@ -0,0 +1,106 @@ +package syncagents + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncAgent +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncAgent +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c SyncAgentsClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/syncAgents", 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 *[]SyncAgent `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c SyncAgentsClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, SyncAgentOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncAgentsClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate SyncAgentOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]SyncAgent, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncagents/method_listlinkeddatabases.go b/resource-manager/sql/2023-08-01/syncagents/method_listlinkeddatabases.go new file mode 100644 index 00000000000..492851acf54 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/method_listlinkeddatabases.go @@ -0,0 +1,105 @@ +package syncagents + +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 ListLinkedDatabasesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncAgentLinkedDatabase +} + +type ListLinkedDatabasesCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncAgentLinkedDatabase +} + +type ListLinkedDatabasesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListLinkedDatabasesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListLinkedDatabases ... +func (c SyncAgentsClient) ListLinkedDatabases(ctx context.Context, id SyncAgentId) (result ListLinkedDatabasesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListLinkedDatabasesCustomPager{}, + Path: fmt.Sprintf("%s/linkedDatabases", 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 *[]SyncAgentLinkedDatabase `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListLinkedDatabasesComplete retrieves all the results into a single object +func (c SyncAgentsClient) ListLinkedDatabasesComplete(ctx context.Context, id SyncAgentId) (ListLinkedDatabasesCompleteResult, error) { + return c.ListLinkedDatabasesCompleteMatchingPredicate(ctx, id, SyncAgentLinkedDatabaseOperationPredicate{}) +} + +// ListLinkedDatabasesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncAgentsClient) ListLinkedDatabasesCompleteMatchingPredicate(ctx context.Context, id SyncAgentId, predicate SyncAgentLinkedDatabaseOperationPredicate) (result ListLinkedDatabasesCompleteResult, err error) { + items := make([]SyncAgentLinkedDatabase, 0) + + resp, err := c.ListLinkedDatabases(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListLinkedDatabasesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncagents/model_syncagent.go b/resource-manager/sql/2023-08-01/syncagents/model_syncagent.go new file mode 100644 index 00000000000..084d1160f2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/model_syncagent.go @@ -0,0 +1,11 @@ +package syncagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncAgent struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SyncAgentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncagents/model_syncagentkeyproperties.go b/resource-manager/sql/2023-08-01/syncagents/model_syncagentkeyproperties.go new file mode 100644 index 00000000000..f38b92ae1b4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/model_syncagentkeyproperties.go @@ -0,0 +1,8 @@ +package syncagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncAgentKeyProperties struct { + SyncAgentKey *string `json:"syncAgentKey,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabase.go b/resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabase.go new file mode 100644 index 00000000000..1dbba8e053b --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabase.go @@ -0,0 +1,11 @@ +package syncagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncAgentLinkedDatabase struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SyncAgentLinkedDatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabaseproperties.go b/resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabaseproperties.go new file mode 100644 index 00000000000..fbb57a254c4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/model_syncagentlinkeddatabaseproperties.go @@ -0,0 +1,13 @@ +package syncagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncAgentLinkedDatabaseProperties struct { + DatabaseId *string `json:"databaseId,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + DatabaseType *SyncMemberDbType `json:"databaseType,omitempty"` + Description *string `json:"description,omitempty"` + ServerName *string `json:"serverName,omitempty"` + UserName *string `json:"userName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncagents/model_syncagentproperties.go b/resource-manager/sql/2023-08-01/syncagents/model_syncagentproperties.go new file mode 100644 index 00000000000..c012f6ac524 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/model_syncagentproperties.go @@ -0,0 +1,44 @@ +package syncagents + +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 SyncAgentProperties struct { + ExpiryTime *string `json:"expiryTime,omitempty"` + IsUpToDate *bool `json:"isUpToDate,omitempty"` + LastAliveTime *string `json:"lastAliveTime,omitempty"` + Name *string `json:"name,omitempty"` + State *SyncAgentState `json:"state,omitempty"` + SyncDatabaseId *string `json:"syncDatabaseId,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *SyncAgentProperties) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncAgentProperties) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *SyncAgentProperties) GetLastAliveTimeAsTime() (*time.Time, error) { + if o.LastAliveTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastAliveTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncAgentProperties) SetLastAliveTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastAliveTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/syncagents/predicates.go b/resource-manager/sql/2023-08-01/syncagents/predicates.go new file mode 100644 index 00000000000..962878c79f0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/predicates.go @@ -0,0 +1,50 @@ +package syncagents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncAgentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SyncAgentOperationPredicate) Matches(input SyncAgent) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type SyncAgentLinkedDatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SyncAgentLinkedDatabaseOperationPredicate) Matches(input SyncAgentLinkedDatabase) 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/sql/2023-08-01/syncagents/version.go b/resource-manager/sql/2023-08-01/syncagents/version.go new file mode 100644 index 00000000000..b71c04773a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncagents/version.go @@ -0,0 +1,10 @@ +package syncagents + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/syncagents/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/README.md b/resource-manager/sql/2023-08-01/syncgroups/README.md new file mode 100644 index 00000000000..41a32028491 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/README.md @@ -0,0 +1,195 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncgroups` Documentation + +The `syncgroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncgroups" +``` + + +### Client Initialization + +```go +client := syncgroups.NewSyncGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SyncGroupsClient.CancelSync` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +read, err := client.CancelSync(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SyncGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +payload := syncgroups.SyncGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncGroupsClient.Delete` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncGroupsClient.Get` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +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: `SyncGroupsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncGroupsClient.ListHubSchemas` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +// alternatively `client.ListHubSchemas(ctx, id)` can be used to do batched pagination +items, err := client.ListHubSchemasComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncGroupsClient.ListLogs` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +// alternatively `client.ListLogs(ctx, id, syncgroups.DefaultListLogsOperationOptions())` can be used to do batched pagination +items, err := client.ListLogsComplete(ctx, id, syncgroups.DefaultListLogsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncGroupsClient.ListSyncDatabaseIds` + +```go +ctx := context.TODO() +id := syncgroups.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.ListSyncDatabaseIds(ctx, id)` can be used to do batched pagination +items, err := client.ListSyncDatabaseIdsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncGroupsClient.RefreshHubSchema` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +if err := client.RefreshHubSchemaThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncGroupsClient.TriggerSync` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +read, err := client.TriggerSync(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SyncGroupsClient.Update` + +```go +ctx := context.TODO() +id := syncgroups.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +payload := syncgroups.SyncGroup{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/syncgroups/client.go b/resource-manager/sql/2023-08-01/syncgroups/client.go new file mode 100644 index 00000000000..5cd4df963fb --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/client.go @@ -0,0 +1,26 @@ +package syncgroups + +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 SyncGroupsClient struct { + Client *resourcemanager.Client +} + +func NewSyncGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*SyncGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "syncgroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SyncGroupsClient: %+v", err) + } + + return &SyncGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/constants.go b/resource-manager/sql/2023-08-01/syncgroups/constants.go new file mode 100644 index 00000000000..39dd55e47be --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/constants.go @@ -0,0 +1,195 @@ +package syncgroups + +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 SyncConflictResolutionPolicy string + +const ( + SyncConflictResolutionPolicyHubWin SyncConflictResolutionPolicy = "HubWin" + SyncConflictResolutionPolicyMemberWin SyncConflictResolutionPolicy = "MemberWin" +) + +func PossibleValuesForSyncConflictResolutionPolicy() []string { + return []string{ + string(SyncConflictResolutionPolicyHubWin), + string(SyncConflictResolutionPolicyMemberWin), + } +} + +func (s *SyncConflictResolutionPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncConflictResolutionPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncConflictResolutionPolicy(input string) (*SyncConflictResolutionPolicy, error) { + vals := map[string]SyncConflictResolutionPolicy{ + "hubwin": SyncConflictResolutionPolicyHubWin, + "memberwin": SyncConflictResolutionPolicyMemberWin, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncConflictResolutionPolicy(input) + return &out, nil +} + +type SyncGroupLogType string + +const ( + SyncGroupLogTypeAll SyncGroupLogType = "All" + SyncGroupLogTypeError SyncGroupLogType = "Error" + SyncGroupLogTypeSuccess SyncGroupLogType = "Success" + SyncGroupLogTypeWarning SyncGroupLogType = "Warning" +) + +func PossibleValuesForSyncGroupLogType() []string { + return []string{ + string(SyncGroupLogTypeAll), + string(SyncGroupLogTypeError), + string(SyncGroupLogTypeSuccess), + string(SyncGroupLogTypeWarning), + } +} + +func (s *SyncGroupLogType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncGroupLogType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncGroupLogType(input string) (*SyncGroupLogType, error) { + vals := map[string]SyncGroupLogType{ + "all": SyncGroupLogTypeAll, + "error": SyncGroupLogTypeError, + "success": SyncGroupLogTypeSuccess, + "warning": SyncGroupLogTypeWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncGroupLogType(input) + return &out, nil +} + +type SyncGroupState string + +const ( + SyncGroupStateError SyncGroupState = "Error" + SyncGroupStateGood SyncGroupState = "Good" + SyncGroupStateNotReady SyncGroupState = "NotReady" + SyncGroupStateProgressing SyncGroupState = "Progressing" + SyncGroupStateWarning SyncGroupState = "Warning" +) + +func PossibleValuesForSyncGroupState() []string { + return []string{ + string(SyncGroupStateError), + string(SyncGroupStateGood), + string(SyncGroupStateNotReady), + string(SyncGroupStateProgressing), + string(SyncGroupStateWarning), + } +} + +func (s *SyncGroupState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncGroupState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncGroupState(input string) (*SyncGroupState, error) { + vals := map[string]SyncGroupState{ + "error": SyncGroupStateError, + "good": SyncGroupStateGood, + "notready": SyncGroupStateNotReady, + "progressing": SyncGroupStateProgressing, + "warning": SyncGroupStateWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncGroupState(input) + return &out, nil +} + +type SyncGroupsType string + +const ( + SyncGroupsTypeAll SyncGroupsType = "All" + SyncGroupsTypeError SyncGroupsType = "Error" + SyncGroupsTypeSuccess SyncGroupsType = "Success" + SyncGroupsTypeWarning SyncGroupsType = "Warning" +) + +func PossibleValuesForSyncGroupsType() []string { + return []string{ + string(SyncGroupsTypeAll), + string(SyncGroupsTypeError), + string(SyncGroupsTypeSuccess), + string(SyncGroupsTypeWarning), + } +} + +func (s *SyncGroupsType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncGroupsType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncGroupsType(input string) (*SyncGroupsType, error) { + vals := map[string]SyncGroupsType{ + "all": SyncGroupsTypeAll, + "error": SyncGroupsTypeError, + "success": SyncGroupsTypeSuccess, + "warning": SyncGroupsTypeWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncGroupsType(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/id_location.go b/resource-manager/sql/2023-08-01/syncgroups/id_location.go new file mode 100644 index 00000000000..3657deb0c32 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/id_location.go @@ -0,0 +1,121 @@ +package syncgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/id_location_test.go b/resource-manager/sql/2023-08-01/syncgroups/id_location_test.go new file mode 100644 index 00000000000..2e90f0affbe --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/id_location_test.go @@ -0,0 +1,237 @@ +package syncgroups + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/syncgroups/id_syncgroup.go b/resource-manager/sql/2023-08-01/syncgroups/id_syncgroup.go new file mode 100644 index 00000000000..bd97e8f81fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/id_syncgroup.go @@ -0,0 +1,148 @@ +package syncgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SyncGroupId{}) +} + +var _ resourceids.ResourceId = &SyncGroupId{} + +// SyncGroupId is a struct representing the Resource ID for a Sync Group +type SyncGroupId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SyncGroupName string +} + +// NewSyncGroupID returns a new SyncGroupId struct +func NewSyncGroupID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, syncGroupName string) SyncGroupId { + return SyncGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SyncGroupName: syncGroupName, + } +} + +// ParseSyncGroupID parses 'input' into a SyncGroupId +func ParseSyncGroupID(input string) (*SyncGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSyncGroupIDInsensitively parses 'input' case-insensitively into a SyncGroupId +// note: this method should only be used for API response data and not user input +func ParseSyncGroupIDInsensitively(input string) (*SyncGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SyncGroupId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SyncGroupName, ok = input.Parsed["syncGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "syncGroupName", input) + } + + return nil +} + +// ValidateSyncGroupID checks that 'input' can be parsed as a Sync Group ID +func ValidateSyncGroupID(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 := ParseSyncGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sync Group ID +func (id SyncGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/syncGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SyncGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sync Group ID +func (id SyncGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSyncGroups", "syncGroups", "syncGroups"), + resourceids.UserSpecifiedSegment("syncGroupName", "syncGroupName"), + } +} + +// String returns a human-readable description of this Sync Group ID +func (id SyncGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Sync Group Name: %q", id.SyncGroupName), + } + return fmt.Sprintf("Sync Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/id_syncgroup_test.go b/resource-manager/sql/2023-08-01/syncgroups/id_syncgroup_test.go new file mode 100644 index 00000000000..ef21bfc7e09 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/id_syncgroup_test.go @@ -0,0 +1,372 @@ +package syncgroups + +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 = &SyncGroupId{} + +func TestNewSyncGroupID(t *testing.T) { + id := NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SyncGroupName != "syncGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'SyncGroupName'", id.SyncGroupName, "syncGroupName") + } +} + +func TestFormatSyncGroupID(t *testing.T) { + actual := NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSyncGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SyncGroupName: "syncGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncGroupID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SyncGroupName != v.Expected.SyncGroupName { + t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName) + } + + } +} + +func TestParseSyncGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SyncGroupName: "syncGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SyncGroupName: "sYnCgRoUpNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncGroupIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SyncGroupName != v.Expected.SyncGroupName { + t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName) + } + + } +} + +func TestSegmentsForSyncGroupId(t *testing.T) { + segments := SyncGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SyncGroupId 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/sql/2023-08-01/syncgroups/method_cancelsync.go b/resource-manager/sql/2023-08-01/syncgroups/method_cancelsync.go new file mode 100644 index 00000000000..5dbc9a23766 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_cancelsync.go @@ -0,0 +1,47 @@ +package syncgroups + +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 CancelSyncOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CancelSync ... +func (c SyncGroupsClient) CancelSync(ctx context.Context, id SyncGroupId) (result CancelSyncOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancelSync", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/syncgroups/method_createorupdate.go new file mode 100644 index 00000000000..f83483ccd42 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_createorupdate.go @@ -0,0 +1,76 @@ +package syncgroups + +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 *SyncGroup +} + +// CreateOrUpdate ... +func (c SyncGroupsClient) CreateOrUpdate(ctx context.Context, id SyncGroupId, input SyncGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 SyncGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id SyncGroupId, input SyncGroup) 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/sql/2023-08-01/syncgroups/method_delete.go b/resource-manager/sql/2023-08-01/syncgroups/method_delete.go new file mode 100644 index 00000000000..9e4a01f7a87 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_delete.go @@ -0,0 +1,71 @@ +package syncgroups + +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 SyncGroupsClient) Delete(ctx context.Context, id SyncGroupId) (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 SyncGroupsClient) DeleteThenPoll(ctx context.Context, id SyncGroupId) 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/sql/2023-08-01/syncgroups/method_get.go b/resource-manager/sql/2023-08-01/syncgroups/method_get.go new file mode 100644 index 00000000000..192ba337ba7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_get.go @@ -0,0 +1,53 @@ +package syncgroups + +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 *SyncGroup +} + +// Get ... +func (c SyncGroupsClient) Get(ctx context.Context, id SyncGroupId) (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 SyncGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_listbydatabase.go b/resource-manager/sql/2023-08-01/syncgroups/method_listbydatabase.go new file mode 100644 index 00000000000..1feba6cec91 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_listbydatabase.go @@ -0,0 +1,106 @@ +package syncgroups + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncGroup +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncGroup +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c SyncGroupsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/syncGroups", 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 *[]SyncGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c SyncGroupsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, SyncGroupOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncGroupsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate SyncGroupOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]SyncGroup, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_listhubschemas.go b/resource-manager/sql/2023-08-01/syncgroups/method_listhubschemas.go new file mode 100644 index 00000000000..8fe8c300344 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_listhubschemas.go @@ -0,0 +1,105 @@ +package syncgroups + +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 ListHubSchemasOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncFullSchemaProperties +} + +type ListHubSchemasCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncFullSchemaProperties +} + +type ListHubSchemasCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListHubSchemasCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListHubSchemas ... +func (c SyncGroupsClient) ListHubSchemas(ctx context.Context, id SyncGroupId) (result ListHubSchemasOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListHubSchemasCustomPager{}, + Path: fmt.Sprintf("%s/hubSchemas", 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 *[]SyncFullSchemaProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListHubSchemasComplete retrieves all the results into a single object +func (c SyncGroupsClient) ListHubSchemasComplete(ctx context.Context, id SyncGroupId) (ListHubSchemasCompleteResult, error) { + return c.ListHubSchemasCompleteMatchingPredicate(ctx, id, SyncFullSchemaPropertiesOperationPredicate{}) +} + +// ListHubSchemasCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncGroupsClient) ListHubSchemasCompleteMatchingPredicate(ctx context.Context, id SyncGroupId, predicate SyncFullSchemaPropertiesOperationPredicate) (result ListHubSchemasCompleteResult, err error) { + items := make([]SyncFullSchemaProperties, 0) + + resp, err := c.ListHubSchemas(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListHubSchemasCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_listlogs.go b/resource-manager/sql/2023-08-01/syncgroups/method_listlogs.go new file mode 100644 index 00000000000..0b12f7bb05e --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_listlogs.go @@ -0,0 +1,146 @@ +package syncgroups + +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 ListLogsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncGroupLogProperties +} + +type ListLogsCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncGroupLogProperties +} + +type ListLogsOperationOptions struct { + ContinuationToken *string + EndTime *string + StartTime *string + Type *SyncGroupsType +} + +func DefaultListLogsOperationOptions() ListLogsOperationOptions { + return ListLogsOperationOptions{} +} + +func (o ListLogsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListLogsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListLogsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ContinuationToken != nil { + out.Append("continuationToken", fmt.Sprintf("%v", *o.ContinuationToken)) + } + if o.EndTime != nil { + out.Append("endTime", fmt.Sprintf("%v", *o.EndTime)) + } + if o.StartTime != nil { + out.Append("startTime", fmt.Sprintf("%v", *o.StartTime)) + } + if o.Type != nil { + out.Append("type", fmt.Sprintf("%v", *o.Type)) + } + return &out +} + +type ListLogsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListLogsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListLogs ... +func (c SyncGroupsClient) ListLogs(ctx context.Context, id SyncGroupId, options ListLogsOperationOptions) (result ListLogsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListLogsCustomPager{}, + Path: fmt.Sprintf("%s/logs", 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 *[]SyncGroupLogProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListLogsComplete retrieves all the results into a single object +func (c SyncGroupsClient) ListLogsComplete(ctx context.Context, id SyncGroupId, options ListLogsOperationOptions) (ListLogsCompleteResult, error) { + return c.ListLogsCompleteMatchingPredicate(ctx, id, options, SyncGroupLogPropertiesOperationPredicate{}) +} + +// ListLogsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncGroupsClient) ListLogsCompleteMatchingPredicate(ctx context.Context, id SyncGroupId, options ListLogsOperationOptions, predicate SyncGroupLogPropertiesOperationPredicate) (result ListLogsCompleteResult, err error) { + items := make([]SyncGroupLogProperties, 0) + + resp, err := c.ListLogs(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListLogsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_listsyncdatabaseids.go b/resource-manager/sql/2023-08-01/syncgroups/method_listsyncdatabaseids.go new file mode 100644 index 00000000000..23a9db0fdcb --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_listsyncdatabaseids.go @@ -0,0 +1,105 @@ +package syncgroups + +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 ListSyncDatabaseIdsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncDatabaseIdProperties +} + +type ListSyncDatabaseIdsCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncDatabaseIdProperties +} + +type ListSyncDatabaseIdsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListSyncDatabaseIdsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListSyncDatabaseIds ... +func (c SyncGroupsClient) ListSyncDatabaseIds(ctx context.Context, id LocationId) (result ListSyncDatabaseIdsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListSyncDatabaseIdsCustomPager{}, + Path: fmt.Sprintf("%s/syncDatabaseIds", 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 *[]SyncDatabaseIdProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListSyncDatabaseIdsComplete retrieves all the results into a single object +func (c SyncGroupsClient) ListSyncDatabaseIdsComplete(ctx context.Context, id LocationId) (ListSyncDatabaseIdsCompleteResult, error) { + return c.ListSyncDatabaseIdsCompleteMatchingPredicate(ctx, id, SyncDatabaseIdPropertiesOperationPredicate{}) +} + +// ListSyncDatabaseIdsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncGroupsClient) ListSyncDatabaseIdsCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate SyncDatabaseIdPropertiesOperationPredicate) (result ListSyncDatabaseIdsCompleteResult, err error) { + items := make([]SyncDatabaseIdProperties, 0) + + resp, err := c.ListSyncDatabaseIds(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListSyncDatabaseIdsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_refreshhubschema.go b/resource-manager/sql/2023-08-01/syncgroups/method_refreshhubschema.go new file mode 100644 index 00000000000..41ff73ecafa --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_refreshhubschema.go @@ -0,0 +1,70 @@ +package syncgroups + +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 RefreshHubSchemaOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RefreshHubSchema ... +func (c SyncGroupsClient) RefreshHubSchema(ctx context.Context, id SyncGroupId) (result RefreshHubSchemaOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshHubSchema", 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 +} + +// RefreshHubSchemaThenPoll performs RefreshHubSchema then polls until it's completed +func (c SyncGroupsClient) RefreshHubSchemaThenPoll(ctx context.Context, id SyncGroupId) error { + result, err := c.RefreshHubSchema(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshHubSchema: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RefreshHubSchema: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_triggersync.go b/resource-manager/sql/2023-08-01/syncgroups/method_triggersync.go new file mode 100644 index 00000000000..804519d7957 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_triggersync.go @@ -0,0 +1,47 @@ +package syncgroups + +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 TriggerSyncOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// TriggerSync ... +func (c SyncGroupsClient) TriggerSync(ctx context.Context, id SyncGroupId) (result TriggerSyncOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/triggerSync", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/method_update.go b/resource-manager/sql/2023-08-01/syncgroups/method_update.go new file mode 100644 index 00000000000..a875a26673b --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/method_update.go @@ -0,0 +1,75 @@ +package syncgroups + +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 *SyncGroup +} + +// Update ... +func (c SyncGroupsClient) Update(ctx context.Context, id SyncGroupId, input SyncGroup) (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 SyncGroupsClient) UpdateThenPoll(ctx context.Context, id SyncGroupId, input SyncGroup) 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/sql/2023-08-01/syncgroups/model_sku.go b/resource-manager/sql/2023-08-01/syncgroups/model_sku.go new file mode 100644 index 00000000000..ec381bba1e8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_sku.go @@ -0,0 +1,12 @@ +package syncgroups + +// 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 { + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncdatabaseidproperties.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncdatabaseidproperties.go new file mode 100644 index 00000000000..b25fe255130 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncdatabaseidproperties.go @@ -0,0 +1,8 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncDatabaseIdProperties struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschemaproperties.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschemaproperties.go new file mode 100644 index 00000000000..38c493e005e --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschemaproperties.go @@ -0,0 +1,27 @@ +package syncgroups + +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 SyncFullSchemaProperties struct { + LastUpdateTime *string `json:"lastUpdateTime,omitempty"` + Tables *[]SyncFullSchemaTable `json:"tables,omitempty"` +} + +func (o *SyncFullSchemaProperties) GetLastUpdateTimeAsTime() (*time.Time, error) { + if o.LastUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncFullSchemaProperties) SetLastUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdateTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematable.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematable.go new file mode 100644 index 00000000000..2e870e1e53b --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematable.go @@ -0,0 +1,12 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncFullSchemaTable struct { + Columns *[]SyncFullSchemaTableColumn `json:"columns,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + HasError *bool `json:"hasError,omitempty"` + Name *string `json:"name,omitempty"` + QuotedName *string `json:"quotedName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematablecolumn.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematablecolumn.go new file mode 100644 index 00000000000..bb0249dad25 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncfullschematablecolumn.go @@ -0,0 +1,14 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncFullSchemaTableColumn struct { + DataSize *string `json:"dataSize,omitempty"` + DataType *string `json:"dataType,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + HasError *bool `json:"hasError,omitempty"` + IsPrimaryKey *bool `json:"isPrimaryKey,omitempty"` + Name *string `json:"name,omitempty"` + QuotedName *string `json:"quotedName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncgroup.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroup.go new file mode 100644 index 00000000000..f7fc84d67cb --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroup.go @@ -0,0 +1,12 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SyncGroupProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncgrouplogproperties.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncgrouplogproperties.go new file mode 100644 index 00000000000..4bfb9731c02 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncgrouplogproperties.go @@ -0,0 +1,31 @@ +package syncgroups + +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 SyncGroupLogProperties struct { + Details *string `json:"details,omitempty"` + OperationStatus *string `json:"operationStatus,omitempty"` + Source *string `json:"source,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + TracingId *string `json:"tracingId,omitempty"` + Type *SyncGroupLogType `json:"type,omitempty"` +} + +func (o *SyncGroupLogProperties) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncGroupLogProperties) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupproperties.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupproperties.go new file mode 100644 index 00000000000..6f6ef4c255b --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupproperties.go @@ -0,0 +1,37 @@ +package syncgroups + +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 SyncGroupProperties struct { + ConflictLoggingRetentionInDays *int64 `json:"conflictLoggingRetentionInDays,omitempty"` + ConflictResolutionPolicy *SyncConflictResolutionPolicy `json:"conflictResolutionPolicy,omitempty"` + EnableConflictLogging *bool `json:"enableConflictLogging,omitempty"` + HubDatabasePassword *string `json:"hubDatabasePassword,omitempty"` + HubDatabaseUserName *string `json:"hubDatabaseUserName,omitempty"` + Interval *int64 `json:"interval,omitempty"` + LastSyncTime *string `json:"lastSyncTime,omitempty"` + PrivateEndpointName *string `json:"privateEndpointName,omitempty"` + Schema *SyncGroupSchema `json:"schema,omitempty"` + SyncDatabaseId *string `json:"syncDatabaseId,omitempty"` + SyncState *SyncGroupState `json:"syncState,omitempty"` + UsePrivateLinkConnection *bool `json:"usePrivateLinkConnection,omitempty"` +} + +func (o *SyncGroupProperties) GetLastSyncTimeAsTime() (*time.Time, error) { + if o.LastSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncGroupProperties) SetLastSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschema.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschema.go new file mode 100644 index 00000000000..c420d3cef1c --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschema.go @@ -0,0 +1,9 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncGroupSchema struct { + MasterSyncMemberName *string `json:"masterSyncMemberName,omitempty"` + Tables *[]SyncGroupSchemaTable `json:"tables,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematable.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematable.go new file mode 100644 index 00000000000..c80bf2396f6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematable.go @@ -0,0 +1,9 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncGroupSchemaTable struct { + Columns *[]SyncGroupSchemaTableColumn `json:"columns,omitempty"` + QuotedName *string `json:"quotedName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematablecolumn.go b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematablecolumn.go new file mode 100644 index 00000000000..e35a8e52c12 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/model_syncgroupschematablecolumn.go @@ -0,0 +1,10 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncGroupSchemaTableColumn struct { + DataSize *string `json:"dataSize,omitempty"` + DataType *string `json:"dataType,omitempty"` + QuotedName *string `json:"quotedName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/predicates.go b/resource-manager/sql/2023-08-01/syncgroups/predicates.go new file mode 100644 index 00000000000..69e910a85ce --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/predicates.go @@ -0,0 +1,86 @@ +package syncgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncDatabaseIdPropertiesOperationPredicate struct { + Id *string +} + +func (p SyncDatabaseIdPropertiesOperationPredicate) Matches(input SyncDatabaseIdProperties) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + return true +} + +type SyncFullSchemaPropertiesOperationPredicate struct { + LastUpdateTime *string +} + +func (p SyncFullSchemaPropertiesOperationPredicate) Matches(input SyncFullSchemaProperties) bool { + + if p.LastUpdateTime != nil && (input.LastUpdateTime == nil || *p.LastUpdateTime != *input.LastUpdateTime) { + return false + } + + return true +} + +type SyncGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SyncGroupOperationPredicate) Matches(input SyncGroup) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type SyncGroupLogPropertiesOperationPredicate struct { + Details *string + OperationStatus *string + Source *string + Timestamp *string + TracingId *string +} + +func (p SyncGroupLogPropertiesOperationPredicate) Matches(input SyncGroupLogProperties) bool { + + if p.Details != nil && (input.Details == nil || *p.Details != *input.Details) { + return false + } + + if p.OperationStatus != nil && (input.OperationStatus == nil || *p.OperationStatus != *input.OperationStatus) { + return false + } + + if p.Source != nil && (input.Source == nil || *p.Source != *input.Source) { + return false + } + + if p.Timestamp != nil && (input.Timestamp == nil || *p.Timestamp != *input.Timestamp) { + return false + } + + if p.TracingId != nil && (input.TracingId == nil || *p.TracingId != *input.TracingId) { + return false + } + + return true +} diff --git a/resource-manager/sql/2023-08-01/syncgroups/version.go b/resource-manager/sql/2023-08-01/syncgroups/version.go new file mode 100644 index 00000000000..de7e394ed56 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncgroups/version.go @@ -0,0 +1,10 @@ +package syncgroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/syncgroups/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/README.md b/resource-manager/sql/2023-08-01/syncmembers/README.md new file mode 100644 index 00000000000..18241302a56 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/README.md @@ -0,0 +1,128 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncmembers` Documentation + +The `syncmembers` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/syncmembers" +``` + + +### Client Initialization + +```go +client := syncmembers.NewSyncMembersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SyncMembersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + +payload := syncmembers.SyncMember{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncMembersClient.Delete` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncMembersClient.Get` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + +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: `SyncMembersClient.ListBySyncGroup` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + +// alternatively `client.ListBySyncGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListBySyncGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncMembersClient.ListMemberSchemas` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + +// alternatively `client.ListMemberSchemas(ctx, id)` can be used to do batched pagination +items, err := client.ListMemberSchemasComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SyncMembersClient.RefreshMemberSchema` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + +if err := client.RefreshMemberSchemaThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SyncMembersClient.Update` + +```go +ctx := context.TODO() +id := syncmembers.NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + +payload := syncmembers.SyncMember{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/syncmembers/client.go b/resource-manager/sql/2023-08-01/syncmembers/client.go new file mode 100644 index 00000000000..002a3b5df66 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/client.go @@ -0,0 +1,26 @@ +package syncmembers + +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 SyncMembersClient struct { + Client *resourcemanager.Client +} + +func NewSyncMembersClientWithBaseURI(sdkApi sdkEnv.Api) (*SyncMembersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "syncmembers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SyncMembersClient: %+v", err) + } + + return &SyncMembersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/constants.go b/resource-manager/sql/2023-08-01/syncmembers/constants.go new file mode 100644 index 00000000000..023ff71f894 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/constants.go @@ -0,0 +1,184 @@ +package syncmembers + +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 SyncDirection string + +const ( + SyncDirectionBidirectional SyncDirection = "Bidirectional" + SyncDirectionOneWayHubToMember SyncDirection = "OneWayHubToMember" + SyncDirectionOneWayMemberToHub SyncDirection = "OneWayMemberToHub" +) + +func PossibleValuesForSyncDirection() []string { + return []string{ + string(SyncDirectionBidirectional), + string(SyncDirectionOneWayHubToMember), + string(SyncDirectionOneWayMemberToHub), + } +} + +func (s *SyncDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncDirection(input string) (*SyncDirection, error) { + vals := map[string]SyncDirection{ + "bidirectional": SyncDirectionBidirectional, + "onewayhubtomember": SyncDirectionOneWayHubToMember, + "onewaymembertohub": SyncDirectionOneWayMemberToHub, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncDirection(input) + return &out, nil +} + +type SyncMemberDbType string + +const ( + SyncMemberDbTypeAzureSqlDatabase SyncMemberDbType = "AzureSqlDatabase" + SyncMemberDbTypeSqlServerDatabase SyncMemberDbType = "SqlServerDatabase" +) + +func PossibleValuesForSyncMemberDbType() []string { + return []string{ + string(SyncMemberDbTypeAzureSqlDatabase), + string(SyncMemberDbTypeSqlServerDatabase), + } +} + +func (s *SyncMemberDbType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncMemberDbType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncMemberDbType(input string) (*SyncMemberDbType, error) { + vals := map[string]SyncMemberDbType{ + "azuresqldatabase": SyncMemberDbTypeAzureSqlDatabase, + "sqlserverdatabase": SyncMemberDbTypeSqlServerDatabase, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncMemberDbType(input) + return &out, nil +} + +type SyncMemberState string + +const ( + SyncMemberStateDeProvisionFailed SyncMemberState = "DeProvisionFailed" + SyncMemberStateDeProvisioned SyncMemberState = "DeProvisioned" + SyncMemberStateDeProvisioning SyncMemberState = "DeProvisioning" + SyncMemberStateDisabledBackupRestore SyncMemberState = "DisabledBackupRestore" + SyncMemberStateDisabledTombstoneCleanup SyncMemberState = "DisabledTombstoneCleanup" + SyncMemberStateProvisionFailed SyncMemberState = "ProvisionFailed" + SyncMemberStateProvisioned SyncMemberState = "Provisioned" + SyncMemberStateProvisioning SyncMemberState = "Provisioning" + SyncMemberStateReprovisionFailed SyncMemberState = "ReprovisionFailed" + SyncMemberStateReprovisioning SyncMemberState = "Reprovisioning" + SyncMemberStateSyncCancelled SyncMemberState = "SyncCancelled" + SyncMemberStateSyncCancelling SyncMemberState = "SyncCancelling" + SyncMemberStateSyncFailed SyncMemberState = "SyncFailed" + SyncMemberStateSyncInProgress SyncMemberState = "SyncInProgress" + SyncMemberStateSyncSucceeded SyncMemberState = "SyncSucceeded" + SyncMemberStateSyncSucceededWithWarnings SyncMemberState = "SyncSucceededWithWarnings" + SyncMemberStateUnProvisioned SyncMemberState = "UnProvisioned" + SyncMemberStateUnReprovisioned SyncMemberState = "UnReprovisioned" +) + +func PossibleValuesForSyncMemberState() []string { + return []string{ + string(SyncMemberStateDeProvisionFailed), + string(SyncMemberStateDeProvisioned), + string(SyncMemberStateDeProvisioning), + string(SyncMemberStateDisabledBackupRestore), + string(SyncMemberStateDisabledTombstoneCleanup), + string(SyncMemberStateProvisionFailed), + string(SyncMemberStateProvisioned), + string(SyncMemberStateProvisioning), + string(SyncMemberStateReprovisionFailed), + string(SyncMemberStateReprovisioning), + string(SyncMemberStateSyncCancelled), + string(SyncMemberStateSyncCancelling), + string(SyncMemberStateSyncFailed), + string(SyncMemberStateSyncInProgress), + string(SyncMemberStateSyncSucceeded), + string(SyncMemberStateSyncSucceededWithWarnings), + string(SyncMemberStateUnProvisioned), + string(SyncMemberStateUnReprovisioned), + } +} + +func (s *SyncMemberState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSyncMemberState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSyncMemberState(input string) (*SyncMemberState, error) { + vals := map[string]SyncMemberState{ + "deprovisionfailed": SyncMemberStateDeProvisionFailed, + "deprovisioned": SyncMemberStateDeProvisioned, + "deprovisioning": SyncMemberStateDeProvisioning, + "disabledbackuprestore": SyncMemberStateDisabledBackupRestore, + "disabledtombstonecleanup": SyncMemberStateDisabledTombstoneCleanup, + "provisionfailed": SyncMemberStateProvisionFailed, + "provisioned": SyncMemberStateProvisioned, + "provisioning": SyncMemberStateProvisioning, + "reprovisionfailed": SyncMemberStateReprovisionFailed, + "reprovisioning": SyncMemberStateReprovisioning, + "synccancelled": SyncMemberStateSyncCancelled, + "synccancelling": SyncMemberStateSyncCancelling, + "syncfailed": SyncMemberStateSyncFailed, + "syncinprogress": SyncMemberStateSyncInProgress, + "syncsucceeded": SyncMemberStateSyncSucceeded, + "syncsucceededwithwarnings": SyncMemberStateSyncSucceededWithWarnings, + "unprovisioned": SyncMemberStateUnProvisioned, + "unreprovisioned": SyncMemberStateUnReprovisioned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SyncMemberState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/id_syncgroup.go b/resource-manager/sql/2023-08-01/syncmembers/id_syncgroup.go new file mode 100644 index 00000000000..e1ad401f334 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/id_syncgroup.go @@ -0,0 +1,148 @@ +package syncmembers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SyncGroupId{}) +} + +var _ resourceids.ResourceId = &SyncGroupId{} + +// SyncGroupId is a struct representing the Resource ID for a Sync Group +type SyncGroupId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SyncGroupName string +} + +// NewSyncGroupID returns a new SyncGroupId struct +func NewSyncGroupID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, syncGroupName string) SyncGroupId { + return SyncGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SyncGroupName: syncGroupName, + } +} + +// ParseSyncGroupID parses 'input' into a SyncGroupId +func ParseSyncGroupID(input string) (*SyncGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSyncGroupIDInsensitively parses 'input' case-insensitively into a SyncGroupId +// note: this method should only be used for API response data and not user input +func ParseSyncGroupIDInsensitively(input string) (*SyncGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SyncGroupId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SyncGroupName, ok = input.Parsed["syncGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "syncGroupName", input) + } + + return nil +} + +// ValidateSyncGroupID checks that 'input' can be parsed as a Sync Group ID +func ValidateSyncGroupID(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 := ParseSyncGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sync Group ID +func (id SyncGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/syncGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SyncGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sync Group ID +func (id SyncGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSyncGroups", "syncGroups", "syncGroups"), + resourceids.UserSpecifiedSegment("syncGroupName", "syncGroupName"), + } +} + +// String returns a human-readable description of this Sync Group ID +func (id SyncGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Sync Group Name: %q", id.SyncGroupName), + } + return fmt.Sprintf("Sync Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/id_syncgroup_test.go b/resource-manager/sql/2023-08-01/syncmembers/id_syncgroup_test.go new file mode 100644 index 00000000000..8586cb4ef2a --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/id_syncgroup_test.go @@ -0,0 +1,372 @@ +package syncmembers + +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 = &SyncGroupId{} + +func TestNewSyncGroupID(t *testing.T) { + id := NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SyncGroupName != "syncGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'SyncGroupName'", id.SyncGroupName, "syncGroupName") + } +} + +func TestFormatSyncGroupID(t *testing.T) { + actual := NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSyncGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SyncGroupName: "syncGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncGroupID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SyncGroupName != v.Expected.SyncGroupName { + t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName) + } + + } +} + +func TestParseSyncGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SyncGroupName: "syncGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SyncGroupName: "sYnCgRoUpNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncGroupIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SyncGroupName != v.Expected.SyncGroupName { + t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName) + } + + } +} + +func TestSegmentsForSyncGroupId(t *testing.T) { + segments := SyncGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SyncGroupId 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/sql/2023-08-01/syncmembers/id_syncmember.go b/resource-manager/sql/2023-08-01/syncmembers/id_syncmember.go new file mode 100644 index 00000000000..f08b8a5b33e --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/id_syncmember.go @@ -0,0 +1,157 @@ +package syncmembers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SyncMemberId{}) +} + +var _ resourceids.ResourceId = &SyncMemberId{} + +// SyncMemberId is a struct representing the Resource ID for a Sync Member +type SyncMemberId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + SyncGroupName string + SyncMemberName string +} + +// NewSyncMemberID returns a new SyncMemberId struct +func NewSyncMemberID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, syncGroupName string, syncMemberName string) SyncMemberId { + return SyncMemberId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + SyncGroupName: syncGroupName, + SyncMemberName: syncMemberName, + } +} + +// ParseSyncMemberID parses 'input' into a SyncMemberId +func ParseSyncMemberID(input string) (*SyncMemberId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncMemberId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncMemberId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSyncMemberIDInsensitively parses 'input' case-insensitively into a SyncMemberId +// note: this method should only be used for API response data and not user input +func ParseSyncMemberIDInsensitively(input string) (*SyncMemberId, error) { + parser := resourceids.NewParserFromResourceIdType(&SyncMemberId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SyncMemberId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SyncMemberId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.SyncGroupName, ok = input.Parsed["syncGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "syncGroupName", input) + } + + if id.SyncMemberName, ok = input.Parsed["syncMemberName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "syncMemberName", input) + } + + return nil +} + +// ValidateSyncMemberID checks that 'input' can be parsed as a Sync Member ID +func ValidateSyncMemberID(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 := ParseSyncMemberID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sync Member ID +func (id SyncMemberId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/syncGroups/%s/syncMembers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.SyncGroupName, id.SyncMemberName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sync Member ID +func (id SyncMemberId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticSyncGroups", "syncGroups", "syncGroups"), + resourceids.UserSpecifiedSegment("syncGroupName", "syncGroupName"), + resourceids.StaticSegment("staticSyncMembers", "syncMembers", "syncMembers"), + resourceids.UserSpecifiedSegment("syncMemberName", "syncMemberName"), + } +} + +// String returns a human-readable description of this Sync Member ID +func (id SyncMemberId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Sync Group Name: %q", id.SyncGroupName), + fmt.Sprintf("Sync Member Name: %q", id.SyncMemberName), + } + return fmt.Sprintf("Sync Member (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/id_syncmember_test.go b/resource-manager/sql/2023-08-01/syncmembers/id_syncmember_test.go new file mode 100644 index 00000000000..6c8c16abe4e --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/id_syncmember_test.go @@ -0,0 +1,417 @@ +package syncmembers + +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 = &SyncMemberId{} + +func TestNewSyncMemberID(t *testing.T) { + id := NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.SyncGroupName != "syncGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'SyncGroupName'", id.SyncGroupName, "syncGroupName") + } + + if id.SyncMemberName != "syncMemberName" { + t.Fatalf("Expected %q but got %q for Segment 'SyncMemberName'", id.SyncMemberName, "syncMemberName") + } +} + +func TestFormatSyncMemberID(t *testing.T) { + actual := NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "syncGroupName", "syncMemberName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers/syncMemberName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSyncMemberID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncMemberId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers/syncMemberName", + Expected: &SyncMemberId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SyncGroupName: "syncGroupName", + SyncMemberName: "syncMemberName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers/syncMemberName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncMemberID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SyncGroupName != v.Expected.SyncGroupName { + t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName) + } + + if actual.SyncMemberName != v.Expected.SyncMemberName { + t.Fatalf("Expected %q but got %q for SyncMemberName", v.Expected.SyncMemberName, actual.SyncMemberName) + } + + } +} + +func TestParseSyncMemberIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SyncMemberId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe/sYnCmEmBeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers/syncMemberName", + Expected: &SyncMemberId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + SyncGroupName: "syncGroupName", + SyncMemberName: "syncMemberName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/syncGroups/syncGroupName/syncMembers/syncMemberName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe/sYnCmEmBeRs/sYnCmEmBeRnAmE", + Expected: &SyncMemberId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + SyncGroupName: "sYnCgRoUpNaMe", + SyncMemberName: "sYnCmEmBeRnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/sYnCgRoUpS/sYnCgRoUpNaMe/sYnCmEmBeRs/sYnCmEmBeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSyncMemberIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.SyncGroupName != v.Expected.SyncGroupName { + t.Fatalf("Expected %q but got %q for SyncGroupName", v.Expected.SyncGroupName, actual.SyncGroupName) + } + + if actual.SyncMemberName != v.Expected.SyncMemberName { + t.Fatalf("Expected %q but got %q for SyncMemberName", v.Expected.SyncMemberName, actual.SyncMemberName) + } + + } +} + +func TestSegmentsForSyncMemberId(t *testing.T) { + segments := SyncMemberId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SyncMemberId 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/sql/2023-08-01/syncmembers/method_createorupdate.go b/resource-manager/sql/2023-08-01/syncmembers/method_createorupdate.go new file mode 100644 index 00000000000..39df5cd32df --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_createorupdate.go @@ -0,0 +1,76 @@ +package syncmembers + +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 *SyncMember +} + +// CreateOrUpdate ... +func (c SyncMembersClient) CreateOrUpdate(ctx context.Context, id SyncMemberId, input SyncMember) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 SyncMembersClient) CreateOrUpdateThenPoll(ctx context.Context, id SyncMemberId, input SyncMember) 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/sql/2023-08-01/syncmembers/method_delete.go b/resource-manager/sql/2023-08-01/syncmembers/method_delete.go new file mode 100644 index 00000000000..f230da0b63f --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_delete.go @@ -0,0 +1,71 @@ +package syncmembers + +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 SyncMembersClient) Delete(ctx context.Context, id SyncMemberId) (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 SyncMembersClient) DeleteThenPoll(ctx context.Context, id SyncMemberId) 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/sql/2023-08-01/syncmembers/method_get.go b/resource-manager/sql/2023-08-01/syncmembers/method_get.go new file mode 100644 index 00000000000..34f5fca6a2c --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_get.go @@ -0,0 +1,53 @@ +package syncmembers + +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 *SyncMember +} + +// Get ... +func (c SyncMembersClient) Get(ctx context.Context, id SyncMemberId) (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 SyncMember + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/method_listbysyncgroup.go b/resource-manager/sql/2023-08-01/syncmembers/method_listbysyncgroup.go new file mode 100644 index 00000000000..ddd95153a82 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_listbysyncgroup.go @@ -0,0 +1,105 @@ +package syncmembers + +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 ListBySyncGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncMember +} + +type ListBySyncGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncMember +} + +type ListBySyncGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySyncGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySyncGroup ... +func (c SyncMembersClient) ListBySyncGroup(ctx context.Context, id SyncGroupId) (result ListBySyncGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySyncGroupCustomPager{}, + Path: fmt.Sprintf("%s/syncMembers", 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 *[]SyncMember `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySyncGroupComplete retrieves all the results into a single object +func (c SyncMembersClient) ListBySyncGroupComplete(ctx context.Context, id SyncGroupId) (ListBySyncGroupCompleteResult, error) { + return c.ListBySyncGroupCompleteMatchingPredicate(ctx, id, SyncMemberOperationPredicate{}) +} + +// ListBySyncGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncMembersClient) ListBySyncGroupCompleteMatchingPredicate(ctx context.Context, id SyncGroupId, predicate SyncMemberOperationPredicate) (result ListBySyncGroupCompleteResult, err error) { + items := make([]SyncMember, 0) + + resp, err := c.ListBySyncGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySyncGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/method_listmemberschemas.go b/resource-manager/sql/2023-08-01/syncmembers/method_listmemberschemas.go new file mode 100644 index 00000000000..859d739124f --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_listmemberschemas.go @@ -0,0 +1,105 @@ +package syncmembers + +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 ListMemberSchemasOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SyncFullSchemaProperties +} + +type ListMemberSchemasCompleteResult struct { + LatestHttpResponse *http.Response + Items []SyncFullSchemaProperties +} + +type ListMemberSchemasCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListMemberSchemasCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListMemberSchemas ... +func (c SyncMembersClient) ListMemberSchemas(ctx context.Context, id SyncMemberId) (result ListMemberSchemasOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListMemberSchemasCustomPager{}, + Path: fmt.Sprintf("%s/schemas", 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 *[]SyncFullSchemaProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListMemberSchemasComplete retrieves all the results into a single object +func (c SyncMembersClient) ListMemberSchemasComplete(ctx context.Context, id SyncMemberId) (ListMemberSchemasCompleteResult, error) { + return c.ListMemberSchemasCompleteMatchingPredicate(ctx, id, SyncFullSchemaPropertiesOperationPredicate{}) +} + +// ListMemberSchemasCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SyncMembersClient) ListMemberSchemasCompleteMatchingPredicate(ctx context.Context, id SyncMemberId, predicate SyncFullSchemaPropertiesOperationPredicate) (result ListMemberSchemasCompleteResult, err error) { + items := make([]SyncFullSchemaProperties, 0) + + resp, err := c.ListMemberSchemas(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListMemberSchemasCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/method_refreshmemberschema.go b/resource-manager/sql/2023-08-01/syncmembers/method_refreshmemberschema.go new file mode 100644 index 00000000000..b5f656b283c --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_refreshmemberschema.go @@ -0,0 +1,70 @@ +package syncmembers + +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 RefreshMemberSchemaOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RefreshMemberSchema ... +func (c SyncMembersClient) RefreshMemberSchema(ctx context.Context, id SyncMemberId) (result RefreshMemberSchemaOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshSchema", 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 +} + +// RefreshMemberSchemaThenPoll performs RefreshMemberSchema then polls until it's completed +func (c SyncMembersClient) RefreshMemberSchemaThenPoll(ctx context.Context, id SyncMemberId) error { + result, err := c.RefreshMemberSchema(ctx, id) + if err != nil { + return fmt.Errorf("performing RefreshMemberSchema: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RefreshMemberSchema: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/method_update.go b/resource-manager/sql/2023-08-01/syncmembers/method_update.go new file mode 100644 index 00000000000..5429926bd6d --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/method_update.go @@ -0,0 +1,75 @@ +package syncmembers + +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 *SyncMember +} + +// Update ... +func (c SyncMembersClient) Update(ctx context.Context, id SyncMemberId, input SyncMember) (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 SyncMembersClient) UpdateThenPoll(ctx context.Context, id SyncMemberId, input SyncMember) 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/sql/2023-08-01/syncmembers/model_syncfullschemaproperties.go b/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschemaproperties.go new file mode 100644 index 00000000000..fd586bc38e8 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschemaproperties.go @@ -0,0 +1,27 @@ +package syncmembers + +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 SyncFullSchemaProperties struct { + LastUpdateTime *string `json:"lastUpdateTime,omitempty"` + Tables *[]SyncFullSchemaTable `json:"tables,omitempty"` +} + +func (o *SyncFullSchemaProperties) GetLastUpdateTimeAsTime() (*time.Time, error) { + if o.LastUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncFullSchemaProperties) SetLastUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdateTime = &formatted +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematable.go b/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematable.go new file mode 100644 index 00000000000..17f3b8521d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematable.go @@ -0,0 +1,12 @@ +package syncmembers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncFullSchemaTable struct { + Columns *[]SyncFullSchemaTableColumn `json:"columns,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + HasError *bool `json:"hasError,omitempty"` + Name *string `json:"name,omitempty"` + QuotedName *string `json:"quotedName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematablecolumn.go b/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematablecolumn.go new file mode 100644 index 00000000000..e9802b6c83f --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/model_syncfullschematablecolumn.go @@ -0,0 +1,14 @@ +package syncmembers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncFullSchemaTableColumn struct { + DataSize *string `json:"dataSize,omitempty"` + DataType *string `json:"dataType,omitempty"` + ErrorId *string `json:"errorId,omitempty"` + HasError *bool `json:"hasError,omitempty"` + IsPrimaryKey *bool `json:"isPrimaryKey,omitempty"` + Name *string `json:"name,omitempty"` + QuotedName *string `json:"quotedName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/model_syncmember.go b/resource-manager/sql/2023-08-01/syncmembers/model_syncmember.go new file mode 100644 index 00000000000..97b8b572db3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/model_syncmember.go @@ -0,0 +1,11 @@ +package syncmembers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncMember struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SyncMemberProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/model_syncmemberproperties.go b/resource-manager/sql/2023-08-01/syncmembers/model_syncmemberproperties.go new file mode 100644 index 00000000000..ddb954fb68a --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/model_syncmemberproperties.go @@ -0,0 +1,19 @@ +package syncmembers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncMemberProperties struct { + DatabaseName *string `json:"databaseName,omitempty"` + DatabaseType *SyncMemberDbType `json:"databaseType,omitempty"` + Password *string `json:"password,omitempty"` + PrivateEndpointName *string `json:"privateEndpointName,omitempty"` + ServerName *string `json:"serverName,omitempty"` + SqlServerDatabaseId *string `json:"sqlServerDatabaseId,omitempty"` + SyncAgentId *string `json:"syncAgentId,omitempty"` + SyncDirection *SyncDirection `json:"syncDirection,omitempty"` + SyncMemberAzureDatabaseResourceId *string `json:"syncMemberAzureDatabaseResourceId,omitempty"` + SyncState *SyncMemberState `json:"syncState,omitempty"` + UsePrivateLinkConnection *bool `json:"usePrivateLinkConnection,omitempty"` + UserName *string `json:"userName,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/syncmembers/predicates.go b/resource-manager/sql/2023-08-01/syncmembers/predicates.go new file mode 100644 index 00000000000..72491a390dc --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/predicates.go @@ -0,0 +1,40 @@ +package syncmembers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncFullSchemaPropertiesOperationPredicate struct { + LastUpdateTime *string +} + +func (p SyncFullSchemaPropertiesOperationPredicate) Matches(input SyncFullSchemaProperties) bool { + + if p.LastUpdateTime != nil && (input.LastUpdateTime == nil || *p.LastUpdateTime != *input.LastUpdateTime) { + return false + } + + return true +} + +type SyncMemberOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SyncMemberOperationPredicate) Matches(input SyncMember) 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/sql/2023-08-01/syncmembers/version.go b/resource-manager/sql/2023-08-01/syncmembers/version.go new file mode 100644 index 00000000000..e06817fe935 --- /dev/null +++ b/resource-manager/sql/2023-08-01/syncmembers/version.go @@ -0,0 +1,10 @@ +package syncmembers + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/syncmembers/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/tdecertificates/README.md b/resource-manager/sql/2023-08-01/tdecertificates/README.md new file mode 100644 index 00000000000..3657e42b617 --- /dev/null +++ b/resource-manager/sql/2023-08-01/tdecertificates/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/tdecertificates` Documentation + +The `tdecertificates` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/tdecertificates" +``` + + +### Client Initialization + +```go +client := tdecertificates.NewTdeCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TdeCertificatesClient.Create` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +payload := tdecertificates.TdeCertificate{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/tdecertificates/client.go b/resource-manager/sql/2023-08-01/tdecertificates/client.go new file mode 100644 index 00000000000..7409af2c03e --- /dev/null +++ b/resource-manager/sql/2023-08-01/tdecertificates/client.go @@ -0,0 +1,26 @@ +package tdecertificates + +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 TdeCertificatesClient struct { + Client *resourcemanager.Client +} + +func NewTdeCertificatesClientWithBaseURI(sdkApi sdkEnv.Api) (*TdeCertificatesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "tdecertificates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TdeCertificatesClient: %+v", err) + } + + return &TdeCertificatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/tdecertificates/method_create.go b/resource-manager/sql/2023-08-01/tdecertificates/method_create.go new file mode 100644 index 00000000000..556a2b6adce --- /dev/null +++ b/resource-manager/sql/2023-08-01/tdecertificates/method_create.go @@ -0,0 +1,75 @@ +package tdecertificates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Create ... +func (c TdeCertificatesClient) Create(ctx context.Context, id commonids.SqlServerId, input TdeCertificate) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/tdeCertificates", 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 TdeCertificatesClient) CreateThenPoll(ctx context.Context, id commonids.SqlServerId, input TdeCertificate) 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/sql/2023-08-01/tdecertificates/model_tdecertificate.go b/resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificate.go new file mode 100644 index 00000000000..c3b01237a28 --- /dev/null +++ b/resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificate.go @@ -0,0 +1,11 @@ +package tdecertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TdeCertificate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TdeCertificateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificateproperties.go b/resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificateproperties.go new file mode 100644 index 00000000000..2448893f463 --- /dev/null +++ b/resource-manager/sql/2023-08-01/tdecertificates/model_tdecertificateproperties.go @@ -0,0 +1,9 @@ +package tdecertificates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TdeCertificateProperties struct { + CertPassword *string `json:"certPassword,omitempty"` + PrivateBlob string `json:"privateBlob"` +} diff --git a/resource-manager/sql/2023-08-01/tdecertificates/version.go b/resource-manager/sql/2023-08-01/tdecertificates/version.go new file mode 100644 index 00000000000..f5106818f1a --- /dev/null +++ b/resource-manager/sql/2023-08-01/tdecertificates/version.go @@ -0,0 +1,10 @@ +package tdecertificates + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/tdecertificates/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/timezones/README.md b/resource-manager/sql/2023-08-01/timezones/README.md new file mode 100644 index 00000000000..c00edadc73a --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/timezones` Documentation + +The `timezones` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/timezones" +``` + + +### Client Initialization + +```go +client := timezones.NewTimeZonesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TimeZonesClient.Get` + +```go +ctx := context.TODO() +id := timezones.NewTimeZoneID("12345678-1234-9876-4563-123456789012", "locationName", "timeZoneId") + +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: `TimeZonesClient.ListByLocation` + +```go +ctx := context.TODO() +id := timezones.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/timezones/client.go b/resource-manager/sql/2023-08-01/timezones/client.go new file mode 100644 index 00000000000..278433b66e0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/client.go @@ -0,0 +1,26 @@ +package timezones + +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 TimeZonesClient struct { + Client *resourcemanager.Client +} + +func NewTimeZonesClientWithBaseURI(sdkApi sdkEnv.Api) (*TimeZonesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "timezones", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TimeZonesClient: %+v", err) + } + + return &TimeZonesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/timezones/id_location.go b/resource-manager/sql/2023-08-01/timezones/id_location.go new file mode 100644 index 00000000000..234c0bd4919 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/id_location.go @@ -0,0 +1,121 @@ +package timezones + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LocationId{}) +} + +var _ resourceids.ResourceId = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/timezones/id_location_test.go b/resource-manager/sql/2023-08-01/timezones/id_location_test.go new file mode 100644 index 00000000000..6317d7fc86a --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/id_location_test.go @@ -0,0 +1,237 @@ +package timezones + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/sql/2023-08-01/timezones/id_timezone.go b/resource-manager/sql/2023-08-01/timezones/id_timezone.go new file mode 100644 index 00000000000..c6aebc031a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/id_timezone.go @@ -0,0 +1,130 @@ +package timezones + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TimeZoneId{}) +} + +var _ resourceids.ResourceId = &TimeZoneId{} + +// TimeZoneId is a struct representing the Resource ID for a Time Zone +type TimeZoneId struct { + SubscriptionId string + LocationName string + TimeZoneId string +} + +// NewTimeZoneID returns a new TimeZoneId struct +func NewTimeZoneID(subscriptionId string, locationName string, timeZoneId string) TimeZoneId { + return TimeZoneId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + TimeZoneId: timeZoneId, + } +} + +// ParseTimeZoneID parses 'input' into a TimeZoneId +func ParseTimeZoneID(input string) (*TimeZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&TimeZoneId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TimeZoneId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTimeZoneIDInsensitively parses 'input' case-insensitively into a TimeZoneId +// note: this method should only be used for API response data and not user input +func ParseTimeZoneIDInsensitively(input string) (*TimeZoneId, error) { + parser := resourceids.NewParserFromResourceIdType(&TimeZoneId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TimeZoneId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TimeZoneId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + if id.TimeZoneId, ok = input.Parsed["timeZoneId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "timeZoneId", input) + } + + return nil +} + +// ValidateTimeZoneID checks that 'input' can be parsed as a Time Zone ID +func ValidateTimeZoneID(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 := ParseTimeZoneID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Time Zone ID +func (id TimeZoneId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Sql/locations/%s/timeZones/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.TimeZoneId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Time Zone ID +func (id TimeZoneId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationName"), + resourceids.StaticSegment("staticTimeZones", "timeZones", "timeZones"), + resourceids.UserSpecifiedSegment("timeZoneId", "timeZoneId"), + } +} + +// String returns a human-readable description of this Time Zone ID +func (id TimeZoneId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Time Zone: %q", id.TimeZoneId), + } + return fmt.Sprintf("Time Zone (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/timezones/id_timezone_test.go b/resource-manager/sql/2023-08-01/timezones/id_timezone_test.go new file mode 100644 index 00000000000..b6e6c1da5dd --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/id_timezone_test.go @@ -0,0 +1,282 @@ +package timezones + +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 = &TimeZoneId{} + +func TestNewTimeZoneID(t *testing.T) { + id := NewTimeZoneID("12345678-1234-9876-4563-123456789012", "locationName", "timeZoneId") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.LocationName != "locationName" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationName") + } + + if id.TimeZoneId != "timeZoneId" { + t.Fatalf("Expected %q but got %q for Segment 'TimeZoneId'", id.TimeZoneId, "timeZoneId") + } +} + +func TestFormatTimeZoneID(t *testing.T) { + actual := NewTimeZoneID("12345678-1234-9876-4563-123456789012", "locationName", "timeZoneId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones/timeZoneId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTimeZoneID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TimeZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones/timeZoneId", + Expected: &TimeZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + TimeZoneId: "timeZoneId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones/timeZoneId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTimeZoneID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.TimeZoneId != v.Expected.TimeZoneId { + t.Fatalf("Expected %q but got %q for TimeZoneId", v.Expected.TimeZoneId, actual.TimeZoneId) + } + + } +} + +func TestParseTimeZoneIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TimeZoneId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/tImEzOnEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones/timeZoneId", + Expected: &TimeZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationName", + TimeZoneId: "timeZoneId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationName/timeZones/timeZoneId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/tImEzOnEs/tImEzOnEiD", + Expected: &TimeZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNnAmE", + TimeZoneId: "tImEzOnEiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNnAmE/tImEzOnEs/tImEzOnEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTimeZoneIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + if actual.TimeZoneId != v.Expected.TimeZoneId { + t.Fatalf("Expected %q but got %q for TimeZoneId", v.Expected.TimeZoneId, actual.TimeZoneId) + } + + } +} + +func TestSegmentsForTimeZoneId(t *testing.T) { + segments := TimeZoneId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TimeZoneId 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/sql/2023-08-01/timezones/method_get.go b/resource-manager/sql/2023-08-01/timezones/method_get.go new file mode 100644 index 00000000000..bf02c6ffb19 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/method_get.go @@ -0,0 +1,53 @@ +package timezones + +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 *TimeZone +} + +// Get ... +func (c TimeZonesClient) Get(ctx context.Context, id TimeZoneId) (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 TimeZone + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/timezones/method_listbylocation.go b/resource-manager/sql/2023-08-01/timezones/method_listbylocation.go new file mode 100644 index 00000000000..48bdb1d9392 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/method_listbylocation.go @@ -0,0 +1,105 @@ +package timezones + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TimeZone +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []TimeZone +} + +type ListByLocationCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByLocationCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByLocation ... +func (c TimeZonesClient) ListByLocation(ctx context.Context, id LocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByLocationCustomPager{}, + Path: fmt.Sprintf("%s/timeZones", 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 *[]TimeZone `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c TimeZonesClient) ListByLocationComplete(ctx context.Context, id LocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, TimeZoneOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TimeZonesClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate TimeZoneOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]TimeZone, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/timezones/model_timezone.go b/resource-manager/sql/2023-08-01/timezones/model_timezone.go new file mode 100644 index 00000000000..e21c5a64795 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/model_timezone.go @@ -0,0 +1,11 @@ +package timezones + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeZone struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TimeZoneProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/timezones/model_timezoneproperties.go b/resource-manager/sql/2023-08-01/timezones/model_timezoneproperties.go new file mode 100644 index 00000000000..94fd2faad65 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/model_timezoneproperties.go @@ -0,0 +1,9 @@ +package timezones + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeZoneProperties struct { + DisplayName *string `json:"displayName,omitempty"` + TimeZoneId *string `json:"timeZoneId,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/timezones/predicates.go b/resource-manager/sql/2023-08-01/timezones/predicates.go new file mode 100644 index 00000000000..7fcbdb82752 --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/predicates.go @@ -0,0 +1,27 @@ +package timezones + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeZoneOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TimeZoneOperationPredicate) Matches(input TimeZone) 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/sql/2023-08-01/timezones/version.go b/resource-manager/sql/2023-08-01/timezones/version.go new file mode 100644 index 00000000000..12d6debf9ed --- /dev/null +++ b/resource-manager/sql/2023-08-01/timezones/version.go @@ -0,0 +1,10 @@ +package timezones + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/timezones/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/README.md b/resource-manager/sql/2023-08-01/transparentdataencryptions/README.md new file mode 100644 index 00000000000..6ecdb4b36a4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/transparentdataencryptions` Documentation + +The `transparentdataencryptions` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/transparentdataencryptions" +``` + + +### Client Initialization + +```go +client := transparentdataencryptions.NewTransparentDataEncryptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TransparentDataEncryptionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +payload := transparentdataencryptions.LogicalDatabaseTransparentDataEncryption{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TransparentDataEncryptionsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +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: `TransparentDataEncryptionsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/client.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/client.go new file mode 100644 index 00000000000..023e8247a47 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/client.go @@ -0,0 +1,26 @@ +package transparentdataencryptions + +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 TransparentDataEncryptionsClient struct { + Client *resourcemanager.Client +} + +func NewTransparentDataEncryptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*TransparentDataEncryptionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "transparentdataencryptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TransparentDataEncryptionsClient: %+v", err) + } + + return &TransparentDataEncryptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/constants.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/constants.go new file mode 100644 index 00000000000..543adab6e0d --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/constants.go @@ -0,0 +1,51 @@ +package transparentdataencryptions + +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 TransparentDataEncryptionState string + +const ( + TransparentDataEncryptionStateDisabled TransparentDataEncryptionState = "Disabled" + TransparentDataEncryptionStateEnabled TransparentDataEncryptionState = "Enabled" +) + +func PossibleValuesForTransparentDataEncryptionState() []string { + return []string{ + string(TransparentDataEncryptionStateDisabled), + string(TransparentDataEncryptionStateEnabled), + } +} + +func (s *TransparentDataEncryptionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTransparentDataEncryptionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTransparentDataEncryptionState(input string) (*TransparentDataEncryptionState, error) { + vals := map[string]TransparentDataEncryptionState{ + "disabled": TransparentDataEncryptionStateDisabled, + "enabled": TransparentDataEncryptionStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TransparentDataEncryptionState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/method_createorupdate.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/method_createorupdate.go new file mode 100644 index 00000000000..050b0a9df87 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/method_createorupdate.go @@ -0,0 +1,77 @@ +package transparentdataencryptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *LogicalDatabaseTransparentDataEncryption +} + +// CreateOrUpdate ... +func (c TransparentDataEncryptionsClient) CreateOrUpdate(ctx context.Context, id commonids.SqlDatabaseId, input LogicalDatabaseTransparentDataEncryption) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/transparentDataEncryption/current", 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 TransparentDataEncryptionsClient) CreateOrUpdateThenPoll(ctx context.Context, id commonids.SqlDatabaseId, input LogicalDatabaseTransparentDataEncryption) 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/sql/2023-08-01/transparentdataencryptions/method_get.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/method_get.go new file mode 100644 index 00000000000..607b29fc4f0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/method_get.go @@ -0,0 +1,55 @@ +package transparentdataencryptions + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LogicalDatabaseTransparentDataEncryption +} + +// Get ... +func (c TransparentDataEncryptionsClient) Get(ctx context.Context, id commonids.SqlDatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/transparentDataEncryption/current", 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 LogicalDatabaseTransparentDataEncryption + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/method_listbydatabase.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/method_listbydatabase.go new file mode 100644 index 00000000000..d260e1ce2a7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/method_listbydatabase.go @@ -0,0 +1,106 @@ +package transparentdataencryptions + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LogicalDatabaseTransparentDataEncryption +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []LogicalDatabaseTransparentDataEncryption +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c TransparentDataEncryptionsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/transparentDataEncryption", 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 *[]LogicalDatabaseTransparentDataEncryption `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c TransparentDataEncryptionsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, LogicalDatabaseTransparentDataEncryptionOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TransparentDataEncryptionsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate LogicalDatabaseTransparentDataEncryptionOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]LogicalDatabaseTransparentDataEncryption, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go new file mode 100644 index 00000000000..e0e0e3b557b --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go @@ -0,0 +1,11 @@ +package transparentdataencryptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogicalDatabaseTransparentDataEncryption struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TransparentDataEncryptionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/model_transparentdataencryptionproperties.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/model_transparentdataencryptionproperties.go new file mode 100644 index 00000000000..f59076220e1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/model_transparentdataencryptionproperties.go @@ -0,0 +1,8 @@ +package transparentdataencryptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TransparentDataEncryptionProperties struct { + State TransparentDataEncryptionState `json:"state"` +} diff --git a/resource-manager/sql/2023-08-01/transparentdataencryptions/predicates.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/predicates.go new file mode 100644 index 00000000000..f312872d12a --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/predicates.go @@ -0,0 +1,27 @@ +package transparentdataencryptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogicalDatabaseTransparentDataEncryptionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LogicalDatabaseTransparentDataEncryptionOperationPredicate) Matches(input LogicalDatabaseTransparentDataEncryption) 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/sql/2023-08-01/transparentdataencryptions/version.go b/resource-manager/sql/2023-08-01/transparentdataencryptions/version.go new file mode 100644 index 00000000000..df0914972e9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/transparentdataencryptions/version.go @@ -0,0 +1,10 @@ +package transparentdataencryptions + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/transparentdataencryptions/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/usages/README.md b/resource-manager/sql/2023-08-01/usages/README.md new file mode 100644 index 00000000000..d7044afb0cb --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/usages` Documentation + +The `usages` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/usages" +``` + + +### Client Initialization + +```go +client := usages.NewUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsagesClient.ListByInstancePool` + +```go +ctx := context.TODO() +id := usages.NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + +// alternatively `client.ListByInstancePool(ctx, id, usages.DefaultListByInstancePoolOperationOptions())` can be used to do batched pagination +items, err := client.ListByInstancePoolComplete(ctx, id, usages.DefaultListByInstancePoolOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/usages/client.go b/resource-manager/sql/2023-08-01/usages/client.go new file mode 100644 index 00000000000..5b6ce18413b --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/client.go @@ -0,0 +1,26 @@ +package usages + +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 UsagesClient struct { + Client *resourcemanager.Client +} + +func NewUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*UsagesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "usages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UsagesClient: %+v", err) + } + + return &UsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/usages/id_instancepool.go b/resource-manager/sql/2023-08-01/usages/id_instancepool.go new file mode 100644 index 00000000000..6c0c7550e1c --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/id_instancepool.go @@ -0,0 +1,130 @@ +package usages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&InstancePoolId{}) +} + +var _ resourceids.ResourceId = &InstancePoolId{} + +// InstancePoolId is a struct representing the Resource ID for a Instance Pool +type InstancePoolId struct { + SubscriptionId string + ResourceGroupName string + InstancePoolName string +} + +// NewInstancePoolID returns a new InstancePoolId struct +func NewInstancePoolID(subscriptionId string, resourceGroupName string, instancePoolName string) InstancePoolId { + return InstancePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + InstancePoolName: instancePoolName, + } +} + +// ParseInstancePoolID parses 'input' into a InstancePoolId +func ParseInstancePoolID(input string) (*InstancePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstancePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstancePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseInstancePoolIDInsensitively parses 'input' case-insensitively into a InstancePoolId +// note: this method should only be used for API response data and not user input +func ParseInstancePoolIDInsensitively(input string) (*InstancePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&InstancePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InstancePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *InstancePoolId) 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.InstancePoolName, ok = input.Parsed["instancePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "instancePoolName", input) + } + + return nil +} + +// ValidateInstancePoolID checks that 'input' can be parsed as a Instance Pool ID +func ValidateInstancePoolID(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 := ParseInstancePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Instance Pool ID +func (id InstancePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/instancePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.InstancePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Instance Pool ID +func (id InstancePoolId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticInstancePools", "instancePools", "instancePools"), + resourceids.UserSpecifiedSegment("instancePoolName", "instancePoolName"), + } +} + +// String returns a human-readable description of this Instance Pool ID +func (id InstancePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Instance Pool Name: %q", id.InstancePoolName), + } + return fmt.Sprintf("Instance Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/usages/id_instancepool_test.go b/resource-manager/sql/2023-08-01/usages/id_instancepool_test.go new file mode 100644 index 00000000000..1bb826de2a9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/id_instancepool_test.go @@ -0,0 +1,282 @@ +package usages + +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 = &InstancePoolId{} + +func TestNewInstancePoolID(t *testing.T) { + id := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName") + + 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.InstancePoolName != "instancePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'InstancePoolName'", id.InstancePoolName, "instancePoolName") + } +} + +func TestFormatInstancePoolID(t *testing.T) { + actual := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseInstancePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstancePoolId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstancePoolID(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.InstancePoolName != v.Expected.InstancePoolName { + t.Fatalf("Expected %q but got %q for InstancePoolName", v.Expected.InstancePoolName, actual.InstancePoolName) + } + + } +} + +func TestParseInstancePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InstancePoolId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/iNsTaNcEpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/iNsTaNcEpOoLs/iNsTaNcEpOoLnAmE", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + InstancePoolName: "iNsTaNcEpOoLnAmE", + }, + }, + { + // 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.sQl/iNsTaNcEpOoLs/iNsTaNcEpOoLnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInstancePoolIDInsensitively(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.InstancePoolName != v.Expected.InstancePoolName { + t.Fatalf("Expected %q but got %q for InstancePoolName", v.Expected.InstancePoolName, actual.InstancePoolName) + } + + } +} + +func TestSegmentsForInstancePoolId(t *testing.T) { + segments := InstancePoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("InstancePoolId 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/sql/2023-08-01/usages/method_listbyinstancepool.go b/resource-manager/sql/2023-08-01/usages/method_listbyinstancepool.go new file mode 100644 index 00000000000..dfe481817a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/method_listbyinstancepool.go @@ -0,0 +1,134 @@ +package usages + +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 ListByInstancePoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListByInstancePoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListByInstancePoolOperationOptions struct { + ExpandChildren *bool +} + +func DefaultListByInstancePoolOperationOptions() ListByInstancePoolOperationOptions { + return ListByInstancePoolOperationOptions{} +} + +func (o ListByInstancePoolOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByInstancePoolOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByInstancePoolOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.ExpandChildren != nil { + out.Append("expandChildren", fmt.Sprintf("%v", *o.ExpandChildren)) + } + return &out +} + +type ListByInstancePoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByInstancePoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByInstancePool ... +func (c UsagesClient) ListByInstancePool(ctx context.Context, id InstancePoolId, options ListByInstancePoolOperationOptions) (result ListByInstancePoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByInstancePoolCustomPager{}, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByInstancePoolComplete retrieves all the results into a single object +func (c UsagesClient) ListByInstancePoolComplete(ctx context.Context, id InstancePoolId, options ListByInstancePoolOperationOptions) (ListByInstancePoolCompleteResult, error) { + return c.ListByInstancePoolCompleteMatchingPredicate(ctx, id, options, UsageOperationPredicate{}) +} + +// ListByInstancePoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UsagesClient) ListByInstancePoolCompleteMatchingPredicate(ctx context.Context, id InstancePoolId, options ListByInstancePoolOperationOptions, predicate UsageOperationPredicate) (result ListByInstancePoolCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ListByInstancePool(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByInstancePoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/usages/model_name.go b/resource-manager/sql/2023-08-01/usages/model_name.go new file mode 100644 index 00000000000..6e4f45a3ef6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/model_name.go @@ -0,0 +1,9 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Name struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/usages/model_usage.go b/resource-manager/sql/2023-08-01/usages/model_usage.go new file mode 100644 index 00000000000..4143a2dd3d7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/model_usage.go @@ -0,0 +1,14 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Id *string `json:"id,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *Name `json:"name,omitempty"` + RequestedLimit *int64 `json:"requestedLimit,omitempty"` + Type *string `json:"type,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/usages/predicates.go b/resource-manager/sql/2023-08-01/usages/predicates.go new file mode 100644 index 00000000000..38b0aa9b1f4 --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/predicates.go @@ -0,0 +1,42 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 + RequestedLimit *int64 + Type *string + Unit *string +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.RequestedLimit != nil && (input.RequestedLimit == nil || *p.RequestedLimit != *input.RequestedLimit) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + if p.Unit != nil && (input.Unit == nil || *p.Unit != *input.Unit) { + return false + } + + return true +} diff --git a/resource-manager/sql/2023-08-01/usages/version.go b/resource-manager/sql/2023-08-01/usages/version.go new file mode 100644 index 00000000000..1c1723389c2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/usages/version.go @@ -0,0 +1,10 @@ +package usages + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/usages/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/README.md b/resource-manager/sql/2023-08-01/virtualclusters/README.md new file mode 100644 index 00000000000..9d63e8badfe --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/README.md @@ -0,0 +1,112 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/virtualclusters` Documentation + +The `virtualclusters` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/virtualclusters" +``` + + +### Client Initialization + +```go +client := virtualclusters.NewVirtualClustersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `VirtualClustersClient.Delete` + +```go +ctx := context.TODO() +id := virtualclusters.NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `VirtualClustersClient.Get` + +```go +ctx := context.TODO() +id := virtualclusters.NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterName") + +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: `VirtualClustersClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// 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: `VirtualClustersClient.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: `VirtualClustersClient.Update` + +```go +ctx := context.TODO() +id := virtualclusters.NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterName") + +payload := virtualclusters.VirtualClusterUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `VirtualClustersClient.UpdateDnsServers` + +```go +ctx := context.TODO() +id := virtualclusters.NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterName") + +if err := client.UpdateDnsServersThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-08-01/virtualclusters/client.go b/resource-manager/sql/2023-08-01/virtualclusters/client.go new file mode 100644 index 00000000000..fcc501326a1 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/client.go @@ -0,0 +1,26 @@ +package virtualclusters + +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 VirtualClustersClient struct { + Client *resourcemanager.Client +} + +func NewVirtualClustersClientWithBaseURI(sdkApi sdkEnv.Api) (*VirtualClustersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "virtualclusters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating VirtualClustersClient: %+v", err) + } + + return &VirtualClustersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/constants.go b/resource-manager/sql/2023-08-01/virtualclusters/constants.go new file mode 100644 index 00000000000..f81119ebcc3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/constants.go @@ -0,0 +1,54 @@ +package virtualclusters + +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 DNSRefreshOperationStatus string + +const ( + DNSRefreshOperationStatusFailed DNSRefreshOperationStatus = "Failed" + DNSRefreshOperationStatusInProgress DNSRefreshOperationStatus = "InProgress" + DNSRefreshOperationStatusSucceeded DNSRefreshOperationStatus = "Succeeded" +) + +func PossibleValuesForDNSRefreshOperationStatus() []string { + return []string{ + string(DNSRefreshOperationStatusFailed), + string(DNSRefreshOperationStatusInProgress), + string(DNSRefreshOperationStatusSucceeded), + } +} + +func (s *DNSRefreshOperationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDNSRefreshOperationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDNSRefreshOperationStatus(input string) (*DNSRefreshOperationStatus, error) { + vals := map[string]DNSRefreshOperationStatus{ + "failed": DNSRefreshOperationStatusFailed, + "inprogress": DNSRefreshOperationStatusInProgress, + "succeeded": DNSRefreshOperationStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DNSRefreshOperationStatus(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster.go b/resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster.go new file mode 100644 index 00000000000..593212ff4db --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster.go @@ -0,0 +1,130 @@ +package virtualclusters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VirtualClusterId{}) +} + +var _ resourceids.ResourceId = &VirtualClusterId{} + +// VirtualClusterId is a struct representing the Resource ID for a Virtual Cluster +type VirtualClusterId struct { + SubscriptionId string + ResourceGroupName string + VirtualClusterName string +} + +// NewVirtualClusterID returns a new VirtualClusterId struct +func NewVirtualClusterID(subscriptionId string, resourceGroupName string, virtualClusterName string) VirtualClusterId { + return VirtualClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + VirtualClusterName: virtualClusterName, + } +} + +// ParseVirtualClusterID parses 'input' into a VirtualClusterId +func ParseVirtualClusterID(input string) (*VirtualClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&VirtualClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VirtualClusterId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVirtualClusterIDInsensitively parses 'input' case-insensitively into a VirtualClusterId +// note: this method should only be used for API response data and not user input +func ParseVirtualClusterIDInsensitively(input string) (*VirtualClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(&VirtualClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VirtualClusterId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VirtualClusterId) 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.VirtualClusterName, ok = input.Parsed["virtualClusterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "virtualClusterName", input) + } + + return nil +} + +// ValidateVirtualClusterID checks that 'input' can be parsed as a Virtual Cluster ID +func ValidateVirtualClusterID(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 := ParseVirtualClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Virtual Cluster ID +func (id VirtualClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/virtualClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.VirtualClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Virtual Cluster ID +func (id VirtualClusterId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticVirtualClusters", "virtualClusters", "virtualClusters"), + resourceids.UserSpecifiedSegment("virtualClusterName", "virtualClusterName"), + } +} + +// String returns a human-readable description of this Virtual Cluster ID +func (id VirtualClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Virtual Cluster Name: %q", id.VirtualClusterName), + } + return fmt.Sprintf("Virtual Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster_test.go b/resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster_test.go new file mode 100644 index 00000000000..d07986c9eb5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/id_virtualcluster_test.go @@ -0,0 +1,282 @@ +package virtualclusters + +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 = &VirtualClusterId{} + +func TestNewVirtualClusterID(t *testing.T) { + id := NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterName") + + 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.VirtualClusterName != "virtualClusterName" { + t.Fatalf("Expected %q but got %q for Segment 'VirtualClusterName'", id.VirtualClusterName, "virtualClusterName") + } +} + +func TestFormatVirtualClusterID(t *testing.T) { + actual := NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVirtualClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualClusterId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterName", + Expected: &VirtualClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VirtualClusterName: "virtualClusterName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualClusterID(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.VirtualClusterName != v.Expected.VirtualClusterName { + t.Fatalf("Expected %q but got %q for VirtualClusterName", v.Expected.VirtualClusterName, actual.VirtualClusterName) + } + + } +} + +func TestParseVirtualClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualClusterId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/vIrTuAlClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterName", + Expected: &VirtualClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VirtualClusterName: "virtualClusterName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/vIrTuAlClUsTeRs/vIrTuAlClUsTeRnAmE", + Expected: &VirtualClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VirtualClusterName: "vIrTuAlClUsTeRnAmE", + }, + }, + { + // 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.sQl/vIrTuAlClUsTeRs/vIrTuAlClUsTeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualClusterIDInsensitively(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.VirtualClusterName != v.Expected.VirtualClusterName { + t.Fatalf("Expected %q but got %q for VirtualClusterName", v.Expected.VirtualClusterName, actual.VirtualClusterName) + } + + } +} + +func TestSegmentsForVirtualClusterId(t *testing.T) { + segments := VirtualClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VirtualClusterId 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/sql/2023-08-01/virtualclusters/method_delete.go b/resource-manager/sql/2023-08-01/virtualclusters/method_delete.go new file mode 100644 index 00000000000..b0c4971e914 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/method_delete.go @@ -0,0 +1,71 @@ +package virtualclusters + +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 VirtualClustersClient) Delete(ctx context.Context, id VirtualClusterId) (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 VirtualClustersClient) DeleteThenPoll(ctx context.Context, id VirtualClusterId) 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/sql/2023-08-01/virtualclusters/method_get.go b/resource-manager/sql/2023-08-01/virtualclusters/method_get.go new file mode 100644 index 00000000000..3705c4dd85f --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/method_get.go @@ -0,0 +1,53 @@ +package virtualclusters + +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 *VirtualCluster +} + +// Get ... +func (c VirtualClustersClient) Get(ctx context.Context, id VirtualClusterId) (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 VirtualCluster + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/method_list.go b/resource-manager/sql/2023-08-01/virtualclusters/method_list.go new file mode 100644 index 00000000000..ae12b48da28 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/method_list.go @@ -0,0 +1,106 @@ +package virtualclusters + +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 *[]VirtualCluster +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []VirtualCluster +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c VirtualClustersClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/virtualClusters", 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 *[]VirtualCluster `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 VirtualClustersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, VirtualClusterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VirtualClustersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate VirtualClusterOperationPredicate) (result ListCompleteResult, err error) { + items := make([]VirtualCluster, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/method_listbyresourcegroup.go b/resource-manager/sql/2023-08-01/virtualclusters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..198ebcdf662 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package virtualclusters + +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 *[]VirtualCluster +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []VirtualCluster +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c VirtualClustersClient) 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, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/virtualClusters", 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 *[]VirtualCluster `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 VirtualClustersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, VirtualClusterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VirtualClustersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate VirtualClusterOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]VirtualCluster, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/method_update.go b/resource-manager/sql/2023-08-01/virtualclusters/method_update.go new file mode 100644 index 00000000000..3b471618c9a --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/method_update.go @@ -0,0 +1,75 @@ +package virtualclusters + +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 *VirtualCluster +} + +// Update ... +func (c VirtualClustersClient) Update(ctx context.Context, id VirtualClusterId, input VirtualClusterUpdate) (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 VirtualClustersClient) UpdateThenPoll(ctx context.Context, id VirtualClusterId, input VirtualClusterUpdate) 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/sql/2023-08-01/virtualclusters/method_updatednsservers.go b/resource-manager/sql/2023-08-01/virtualclusters/method_updatednsservers.go new file mode 100644 index 00000000000..23519a63967 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/method_updatednsservers.go @@ -0,0 +1,71 @@ +package virtualclusters + +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 UpdateDnsServersOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *UpdateVirtualClusterDnsServersOperation +} + +// UpdateDnsServers ... +func (c VirtualClustersClient) UpdateDnsServers(ctx context.Context, id VirtualClusterId) (result UpdateDnsServersOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/updateManagedInstanceDnsServers", 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 +} + +// UpdateDnsServersThenPoll performs UpdateDnsServers then polls until it's completed +func (c VirtualClustersClient) UpdateDnsServersThenPoll(ctx context.Context, id VirtualClusterId) error { + result, err := c.UpdateDnsServers(ctx, id) + if err != nil { + return fmt.Errorf("performing UpdateDnsServers: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after UpdateDnsServers: %+v", err) + } + + return nil +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/model_updatevirtualclusterdnsserversoperation.go b/resource-manager/sql/2023-08-01/virtualclusters/model_updatevirtualclusterdnsserversoperation.go new file mode 100644 index 00000000000..03f46b05da3 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/model_updatevirtualclusterdnsserversoperation.go @@ -0,0 +1,11 @@ +package virtualclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateVirtualClusterDnsServersOperation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VirtualClusterDnsServersProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/model_virtualcluster.go b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualcluster.go new file mode 100644 index 00000000000..e3f87d3221d --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualcluster.go @@ -0,0 +1,13 @@ +package virtualclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualCluster struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *VirtualClusterProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterdnsserversproperties.go b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterdnsserversproperties.go new file mode 100644 index 00000000000..88d2678487b --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterdnsserversproperties.go @@ -0,0 +1,8 @@ +package virtualclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualClusterDnsServersProperties struct { + Status *DNSRefreshOperationStatus `json:"status,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterproperties.go b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterproperties.go new file mode 100644 index 00000000000..3a2d2b366fa --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterproperties.go @@ -0,0 +1,10 @@ +package virtualclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualClusterProperties struct { + ChildResources *[]string `json:"childResources,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterupdate.go b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterupdate.go new file mode 100644 index 00000000000..734749ad962 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/model_virtualclusterupdate.go @@ -0,0 +1,9 @@ +package virtualclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualClusterUpdate struct { + Properties *VirtualClusterProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/virtualclusters/predicates.go b/resource-manager/sql/2023-08-01/virtualclusters/predicates.go new file mode 100644 index 00000000000..48542d3780f --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/predicates.go @@ -0,0 +1,32 @@ +package virtualclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualClusterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p VirtualClusterOperationPredicate) Matches(input VirtualCluster) 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/sql/2023-08-01/virtualclusters/version.go b/resource-manager/sql/2023-08-01/virtualclusters/version.go new file mode 100644 index 00000000000..093cb801f67 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualclusters/version.go @@ -0,0 +1,10 @@ +package virtualclusters + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/virtualclusters/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/README.md b/resource-manager/sql/2023-08-01/virtualnetworkrules/README.md new file mode 100644 index 00000000000..749a9d60d47 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/virtualnetworkrules` Documentation + +The `virtualnetworkrules` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/virtualnetworkrules" +``` + + +### Client Initialization + +```go +client := virtualnetworkrules.NewVirtualNetworkRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `VirtualNetworkRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := virtualnetworkrules.NewVirtualNetworkRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "virtualNetworkRuleName") + +payload := virtualnetworkrules.VirtualNetworkRule{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `VirtualNetworkRulesClient.Delete` + +```go +ctx := context.TODO() +id := virtualnetworkrules.NewVirtualNetworkRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "virtualNetworkRuleName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `VirtualNetworkRulesClient.Get` + +```go +ctx := context.TODO() +id := virtualnetworkrules.NewVirtualNetworkRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "virtualNetworkRuleName") + +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: `VirtualNetworkRulesClient.ListByServer` + +```go +ctx := context.TODO() +id := commonids.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName") + +// alternatively `client.ListByServer(ctx, id)` can be used to do batched pagination +items, err := client.ListByServerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/client.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/client.go new file mode 100644 index 00000000000..05336264e4f --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/client.go @@ -0,0 +1,26 @@ +package virtualnetworkrules + +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 VirtualNetworkRulesClient struct { + Client *resourcemanager.Client +} + +func NewVirtualNetworkRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*VirtualNetworkRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "virtualnetworkrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating VirtualNetworkRulesClient: %+v", err) + } + + return &VirtualNetworkRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/constants.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/constants.go new file mode 100644 index 00000000000..f6405438796 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/constants.go @@ -0,0 +1,63 @@ +package virtualnetworkrules + +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 VirtualNetworkRuleState string + +const ( + VirtualNetworkRuleStateDeleting VirtualNetworkRuleState = "Deleting" + VirtualNetworkRuleStateFailed VirtualNetworkRuleState = "Failed" + VirtualNetworkRuleStateInProgress VirtualNetworkRuleState = "InProgress" + VirtualNetworkRuleStateInitializing VirtualNetworkRuleState = "Initializing" + VirtualNetworkRuleStateReady VirtualNetworkRuleState = "Ready" + VirtualNetworkRuleStateUnknown VirtualNetworkRuleState = "Unknown" +) + +func PossibleValuesForVirtualNetworkRuleState() []string { + return []string{ + string(VirtualNetworkRuleStateDeleting), + string(VirtualNetworkRuleStateFailed), + string(VirtualNetworkRuleStateInProgress), + string(VirtualNetworkRuleStateInitializing), + string(VirtualNetworkRuleStateReady), + string(VirtualNetworkRuleStateUnknown), + } +} + +func (s *VirtualNetworkRuleState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualNetworkRuleState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualNetworkRuleState(input string) (*VirtualNetworkRuleState, error) { + vals := map[string]VirtualNetworkRuleState{ + "deleting": VirtualNetworkRuleStateDeleting, + "failed": VirtualNetworkRuleStateFailed, + "inprogress": VirtualNetworkRuleStateInProgress, + "initializing": VirtualNetworkRuleStateInitializing, + "ready": VirtualNetworkRuleStateReady, + "unknown": VirtualNetworkRuleStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualNetworkRuleState(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule.go new file mode 100644 index 00000000000..3202dec4325 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule.go @@ -0,0 +1,139 @@ +package virtualnetworkrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VirtualNetworkRuleId{}) +} + +var _ resourceids.ResourceId = &VirtualNetworkRuleId{} + +// VirtualNetworkRuleId is a struct representing the Resource ID for a Virtual Network Rule +type VirtualNetworkRuleId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + VirtualNetworkRuleName string +} + +// NewVirtualNetworkRuleID returns a new VirtualNetworkRuleId struct +func NewVirtualNetworkRuleID(subscriptionId string, resourceGroupName string, serverName string, virtualNetworkRuleName string) VirtualNetworkRuleId { + return VirtualNetworkRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + VirtualNetworkRuleName: virtualNetworkRuleName, + } +} + +// ParseVirtualNetworkRuleID parses 'input' into a VirtualNetworkRuleId +func ParseVirtualNetworkRuleID(input string) (*VirtualNetworkRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&VirtualNetworkRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VirtualNetworkRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVirtualNetworkRuleIDInsensitively parses 'input' case-insensitively into a VirtualNetworkRuleId +// note: this method should only be used for API response data and not user input +func ParseVirtualNetworkRuleIDInsensitively(input string) (*VirtualNetworkRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&VirtualNetworkRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VirtualNetworkRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VirtualNetworkRuleId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.VirtualNetworkRuleName, ok = input.Parsed["virtualNetworkRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "virtualNetworkRuleName", input) + } + + return nil +} + +// ValidateVirtualNetworkRuleID checks that 'input' can be parsed as a Virtual Network Rule ID +func ValidateVirtualNetworkRuleID(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 := ParseVirtualNetworkRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Virtual Network Rule ID +func (id VirtualNetworkRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/virtualNetworkRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.VirtualNetworkRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Virtual Network Rule ID +func (id VirtualNetworkRuleId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticVirtualNetworkRules", "virtualNetworkRules", "virtualNetworkRules"), + resourceids.UserSpecifiedSegment("virtualNetworkRuleName", "virtualNetworkRuleName"), + } +} + +// String returns a human-readable description of this Virtual Network Rule ID +func (id VirtualNetworkRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Virtual Network Rule Name: %q", id.VirtualNetworkRuleName), + } + return fmt.Sprintf("Virtual Network Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule_test.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule_test.go new file mode 100644 index 00000000000..e2fc8e77a3d --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/id_virtualnetworkrule_test.go @@ -0,0 +1,327 @@ +package virtualnetworkrules + +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 = &VirtualNetworkRuleId{} + +func TestNewVirtualNetworkRuleID(t *testing.T) { + id := NewVirtualNetworkRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "virtualNetworkRuleName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.VirtualNetworkRuleName != "virtualNetworkRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'VirtualNetworkRuleName'", id.VirtualNetworkRuleName, "virtualNetworkRuleName") + } +} + +func TestFormatVirtualNetworkRuleID(t *testing.T) { + actual := NewVirtualNetworkRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "virtualNetworkRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules/virtualNetworkRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVirtualNetworkRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualNetworkRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules/virtualNetworkRuleName", + Expected: &VirtualNetworkRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + VirtualNetworkRuleName: "virtualNetworkRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules/virtualNetworkRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualNetworkRuleID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.VirtualNetworkRuleName != v.Expected.VirtualNetworkRuleName { + t.Fatalf("Expected %q but got %q for VirtualNetworkRuleName", v.Expected.VirtualNetworkRuleName, actual.VirtualNetworkRuleName) + } + + } +} + +func TestParseVirtualNetworkRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualNetworkRuleId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/vIrTuAlNeTwOrKrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules/virtualNetworkRuleName", + Expected: &VirtualNetworkRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + VirtualNetworkRuleName: "virtualNetworkRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/virtualNetworkRules/virtualNetworkRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/vIrTuAlNeTwOrKrUlEs/vIrTuAlNeTwOrKrUlEnAmE", + Expected: &VirtualNetworkRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + VirtualNetworkRuleName: "vIrTuAlNeTwOrKrUlEnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/vIrTuAlNeTwOrKrUlEs/vIrTuAlNeTwOrKrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVirtualNetworkRuleIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.VirtualNetworkRuleName != v.Expected.VirtualNetworkRuleName { + t.Fatalf("Expected %q but got %q for VirtualNetworkRuleName", v.Expected.VirtualNetworkRuleName, actual.VirtualNetworkRuleName) + } + + } +} + +func TestSegmentsForVirtualNetworkRuleId(t *testing.T) { + segments := VirtualNetworkRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VirtualNetworkRuleId 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/sql/2023-08-01/virtualnetworkrules/method_createorupdate.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_createorupdate.go new file mode 100644 index 00000000000..6b112a10cf2 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_createorupdate.go @@ -0,0 +1,76 @@ +package virtualnetworkrules + +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 *VirtualNetworkRule +} + +// CreateOrUpdate ... +func (c VirtualNetworkRulesClient) CreateOrUpdate(ctx context.Context, id VirtualNetworkRuleId, input VirtualNetworkRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 VirtualNetworkRulesClient) CreateOrUpdateThenPoll(ctx context.Context, id VirtualNetworkRuleId, input VirtualNetworkRule) 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/sql/2023-08-01/virtualnetworkrules/method_delete.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_delete.go new file mode 100644 index 00000000000..bba879aa2de --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_delete.go @@ -0,0 +1,71 @@ +package virtualnetworkrules + +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 VirtualNetworkRulesClient) Delete(ctx context.Context, id VirtualNetworkRuleId) (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 VirtualNetworkRulesClient) DeleteThenPoll(ctx context.Context, id VirtualNetworkRuleId) 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/sql/2023-08-01/virtualnetworkrules/method_get.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_get.go new file mode 100644 index 00000000000..ffe91c54117 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_get.go @@ -0,0 +1,53 @@ +package virtualnetworkrules + +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 *VirtualNetworkRule +} + +// Get ... +func (c VirtualNetworkRulesClient) Get(ctx context.Context, id VirtualNetworkRuleId) (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 VirtualNetworkRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/method_listbyserver.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_listbyserver.go new file mode 100644 index 00000000000..fd0e442a021 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/method_listbyserver.go @@ -0,0 +1,106 @@ +package virtualnetworkrules + +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 ListByServerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VirtualNetworkRule +} + +type ListByServerCompleteResult struct { + LatestHttpResponse *http.Response + Items []VirtualNetworkRule +} + +type ListByServerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByServer ... +func (c VirtualNetworkRulesClient) ListByServer(ctx context.Context, id commonids.SqlServerId) (result ListByServerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByServerCustomPager{}, + Path: fmt.Sprintf("%s/virtualNetworkRules", 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 *[]VirtualNetworkRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServerComplete retrieves all the results into a single object +func (c VirtualNetworkRulesClient) ListByServerComplete(ctx context.Context, id commonids.SqlServerId) (ListByServerCompleteResult, error) { + return c.ListByServerCompleteMatchingPredicate(ctx, id, VirtualNetworkRuleOperationPredicate{}) +} + +// ListByServerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VirtualNetworkRulesClient) ListByServerCompleteMatchingPredicate(ctx context.Context, id commonids.SqlServerId, predicate VirtualNetworkRuleOperationPredicate) (result ListByServerCompleteResult, err error) { + items := make([]VirtualNetworkRule, 0) + + resp, err := c.ListByServer(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkrule.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkrule.go new file mode 100644 index 00000000000..16850c4e56f --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkrule.go @@ -0,0 +1,11 @@ +package virtualnetworkrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VirtualNetworkRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkruleproperties.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkruleproperties.go new file mode 100644 index 00000000000..40e8ec8d241 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/model_virtualnetworkruleproperties.go @@ -0,0 +1,10 @@ +package virtualnetworkrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkRuleProperties struct { + IgnoreMissingVnetServiceEndpoint *bool `json:"ignoreMissingVnetServiceEndpoint,omitempty"` + State *VirtualNetworkRuleState `json:"state,omitempty"` + VirtualNetworkSubnetId string `json:"virtualNetworkSubnetId"` +} diff --git a/resource-manager/sql/2023-08-01/virtualnetworkrules/predicates.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/predicates.go new file mode 100644 index 00000000000..9170201b8d5 --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/predicates.go @@ -0,0 +1,27 @@ +package virtualnetworkrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VirtualNetworkRuleOperationPredicate) Matches(input VirtualNetworkRule) 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/sql/2023-08-01/virtualnetworkrules/version.go b/resource-manager/sql/2023-08-01/virtualnetworkrules/version.go new file mode 100644 index 00000000000..184e0e7960f --- /dev/null +++ b/resource-manager/sql/2023-08-01/virtualnetworkrules/version.go @@ -0,0 +1,10 @@ +package virtualnetworkrules + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/virtualnetworkrules/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/README.md b/resource-manager/sql/2023-08-01/workloadclassifiers/README.md new file mode 100644 index 00000000000..036c378f59e --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/workloadclassifiers` Documentation + +The `workloadclassifiers` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/workloadclassifiers" +``` + + +### Client Initialization + +```go +client := workloadclassifiers.NewWorkloadClassifiersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkloadClassifiersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := workloadclassifiers.NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName", "workloadClassifierName") + +payload := workloadclassifiers.WorkloadClassifier{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkloadClassifiersClient.Delete` + +```go +ctx := context.TODO() +id := workloadclassifiers.NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName", "workloadClassifierName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkloadClassifiersClient.Get` + +```go +ctx := context.TODO() +id := workloadclassifiers.NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName", "workloadClassifierName") + +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: `WorkloadClassifiersClient.ListByWorkloadGroup` + +```go +ctx := context.TODO() +id := workloadclassifiers.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName") + +// alternatively `client.ListByWorkloadGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkloadGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/client.go b/resource-manager/sql/2023-08-01/workloadclassifiers/client.go new file mode 100644 index 00000000000..2817cd7d47d --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/client.go @@ -0,0 +1,26 @@ +package workloadclassifiers + +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 WorkloadClassifiersClient struct { + Client *resourcemanager.Client +} + +func NewWorkloadClassifiersClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkloadClassifiersClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "workloadclassifiers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkloadClassifiersClient: %+v", err) + } + + return &WorkloadClassifiersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier.go b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier.go new file mode 100644 index 00000000000..cacd3a5da36 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier.go @@ -0,0 +1,157 @@ +package workloadclassifiers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkloadClassifierId{}) +} + +var _ resourceids.ResourceId = &WorkloadClassifierId{} + +// WorkloadClassifierId is a struct representing the Resource ID for a Workload Classifier +type WorkloadClassifierId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + WorkloadGroupName string + WorkloadClassifierName string +} + +// NewWorkloadClassifierID returns a new WorkloadClassifierId struct +func NewWorkloadClassifierID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, workloadGroupName string, workloadClassifierName string) WorkloadClassifierId { + return WorkloadClassifierId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + WorkloadGroupName: workloadGroupName, + WorkloadClassifierName: workloadClassifierName, + } +} + +// ParseWorkloadClassifierID parses 'input' into a WorkloadClassifierId +func ParseWorkloadClassifierID(input string) (*WorkloadClassifierId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadClassifierId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadClassifierId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkloadClassifierIDInsensitively parses 'input' case-insensitively into a WorkloadClassifierId +// note: this method should only be used for API response data and not user input +func ParseWorkloadClassifierIDInsensitively(input string) (*WorkloadClassifierId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadClassifierId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadClassifierId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkloadClassifierId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.WorkloadGroupName, ok = input.Parsed["workloadGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadGroupName", input) + } + + if id.WorkloadClassifierName, ok = input.Parsed["workloadClassifierName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadClassifierName", input) + } + + return nil +} + +// ValidateWorkloadClassifierID checks that 'input' can be parsed as a Workload Classifier ID +func ValidateWorkloadClassifierID(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 := ParseWorkloadClassifierID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workload Classifier ID +func (id WorkloadClassifierId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/workloadGroups/%s/workloadClassifiers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.WorkloadGroupName, id.WorkloadClassifierName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workload Classifier ID +func (id WorkloadClassifierId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupName"), + resourceids.StaticSegment("staticWorkloadClassifiers", "workloadClassifiers", "workloadClassifiers"), + resourceids.UserSpecifiedSegment("workloadClassifierName", "workloadClassifierName"), + } +} + +// String returns a human-readable description of this Workload Classifier ID +func (id WorkloadClassifierId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Workload Group Name: %q", id.WorkloadGroupName), + fmt.Sprintf("Workload Classifier Name: %q", id.WorkloadClassifierName), + } + return fmt.Sprintf("Workload Classifier (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier_test.go b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier_test.go new file mode 100644 index 00000000000..b27c23dac94 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadclassifier_test.go @@ -0,0 +1,417 @@ +package workloadclassifiers + +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 = &WorkloadClassifierId{} + +func TestNewWorkloadClassifierID(t *testing.T) { + id := NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName", "workloadClassifierName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.WorkloadGroupName != "workloadGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupName") + } + + if id.WorkloadClassifierName != "workloadClassifierName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadClassifierName'", id.WorkloadClassifierName, "workloadClassifierName") + } +} + +func TestFormatWorkloadClassifierID(t *testing.T) { + actual := NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName", "workloadClassifierName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers/workloadClassifierName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkloadClassifierID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadClassifierId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers/workloadClassifierName", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + WorkloadGroupName: "workloadGroupName", + WorkloadClassifierName: "workloadClassifierName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers/workloadClassifierName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadClassifierID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + if actual.WorkloadClassifierName != v.Expected.WorkloadClassifierName { + t.Fatalf("Expected %q but got %q for WorkloadClassifierName", v.Expected.WorkloadClassifierName, actual.WorkloadClassifierName) + } + + } +} + +func TestParseWorkloadClassifierIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadClassifierId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe/wOrKlOaDcLaSsIfIeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers/workloadClassifierName", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + WorkloadGroupName: "workloadGroupName", + WorkloadClassifierName: "workloadClassifierName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/workloadClassifiers/workloadClassifierName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe/wOrKlOaDcLaSsIfIeRs/wOrKlOaDcLaSsIfIeRnAmE", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + WorkloadGroupName: "wOrKlOaDgRoUpNaMe", + WorkloadClassifierName: "wOrKlOaDcLaSsIfIeRnAmE", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe/wOrKlOaDcLaSsIfIeRs/wOrKlOaDcLaSsIfIeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadClassifierIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + if actual.WorkloadClassifierName != v.Expected.WorkloadClassifierName { + t.Fatalf("Expected %q but got %q for WorkloadClassifierName", v.Expected.WorkloadClassifierName, actual.WorkloadClassifierName) + } + + } +} + +func TestSegmentsForWorkloadClassifierId(t *testing.T) { + segments := WorkloadClassifierId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkloadClassifierId 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/sql/2023-08-01/workloadclassifiers/id_workloadgroup.go b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup.go new file mode 100644 index 00000000000..f5711e1ee35 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup.go @@ -0,0 +1,148 @@ +package workloadclassifiers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkloadGroupId{}) +} + +var _ resourceids.ResourceId = &WorkloadGroupId{} + +// WorkloadGroupId is a struct representing the Resource ID for a Workload Group +type WorkloadGroupId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + WorkloadGroupName string +} + +// NewWorkloadGroupID returns a new WorkloadGroupId struct +func NewWorkloadGroupID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, workloadGroupName string) WorkloadGroupId { + return WorkloadGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + WorkloadGroupName: workloadGroupName, + } +} + +// ParseWorkloadGroupID parses 'input' into a WorkloadGroupId +func ParseWorkloadGroupID(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkloadGroupIDInsensitively parses 'input' case-insensitively into a WorkloadGroupId +// note: this method should only be used for API response data and not user input +func ParseWorkloadGroupIDInsensitively(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkloadGroupId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.WorkloadGroupName, ok = input.Parsed["workloadGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadGroupName", input) + } + + return nil +} + +// ValidateWorkloadGroupID checks that 'input' can be parsed as a Workload Group ID +func ValidateWorkloadGroupID(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 := ParseWorkloadGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workload Group ID +func (id WorkloadGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/workloadGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.WorkloadGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workload Group ID +func (id WorkloadGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupName"), + } +} + +// String returns a human-readable description of this Workload Group ID +func (id WorkloadGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Workload Group Name: %q", id.WorkloadGroupName), + } + return fmt.Sprintf("Workload Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup_test.go b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup_test.go new file mode 100644 index 00000000000..4893d860f3d --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/id_workloadgroup_test.go @@ -0,0 +1,372 @@ +package workloadclassifiers + +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 = &WorkloadGroupId{} + +func TestNewWorkloadGroupID(t *testing.T) { + id := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.WorkloadGroupName != "workloadGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupName") + } +} + +func TestFormatWorkloadGroupID(t *testing.T) { + actual := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkloadGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + WorkloadGroupName: "workloadGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestParseWorkloadGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + WorkloadGroupName: "workloadGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + WorkloadGroupName: "wOrKlOaDgRoUpNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestSegmentsForWorkloadGroupId(t *testing.T) { + segments := WorkloadGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkloadGroupId 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/sql/2023-08-01/workloadclassifiers/method_createorupdate.go b/resource-manager/sql/2023-08-01/workloadclassifiers/method_createorupdate.go new file mode 100644 index 00000000000..7cd64bf2646 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/method_createorupdate.go @@ -0,0 +1,76 @@ +package workloadclassifiers + +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 *WorkloadClassifier +} + +// CreateOrUpdate ... +func (c WorkloadClassifiersClient) CreateOrUpdate(ctx context.Context, id WorkloadClassifierId, input WorkloadClassifier) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 WorkloadClassifiersClient) CreateOrUpdateThenPoll(ctx context.Context, id WorkloadClassifierId, input WorkloadClassifier) 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/sql/2023-08-01/workloadclassifiers/method_delete.go b/resource-manager/sql/2023-08-01/workloadclassifiers/method_delete.go new file mode 100644 index 00000000000..f3e2b5733ff --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/method_delete.go @@ -0,0 +1,71 @@ +package workloadclassifiers + +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 WorkloadClassifiersClient) Delete(ctx context.Context, id WorkloadClassifierId) (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 WorkloadClassifiersClient) DeleteThenPoll(ctx context.Context, id WorkloadClassifierId) 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/sql/2023-08-01/workloadclassifiers/method_get.go b/resource-manager/sql/2023-08-01/workloadclassifiers/method_get.go new file mode 100644 index 00000000000..b53892d20ec --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/method_get.go @@ -0,0 +1,53 @@ +package workloadclassifiers + +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 *WorkloadClassifier +} + +// Get ... +func (c WorkloadClassifiersClient) Get(ctx context.Context, id WorkloadClassifierId) (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 WorkloadClassifier + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/method_listbyworkloadgroup.go b/resource-manager/sql/2023-08-01/workloadclassifiers/method_listbyworkloadgroup.go new file mode 100644 index 00000000000..aded3abe903 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/method_listbyworkloadgroup.go @@ -0,0 +1,105 @@ +package workloadclassifiers + +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 ListByWorkloadGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WorkloadClassifier +} + +type ListByWorkloadGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []WorkloadClassifier +} + +type ListByWorkloadGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByWorkloadGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByWorkloadGroup ... +func (c WorkloadClassifiersClient) ListByWorkloadGroup(ctx context.Context, id WorkloadGroupId) (result ListByWorkloadGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByWorkloadGroupCustomPager{}, + Path: fmt.Sprintf("%s/workloadClassifiers", 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 *[]WorkloadClassifier `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkloadGroupComplete retrieves all the results into a single object +func (c WorkloadClassifiersClient) ListByWorkloadGroupComplete(ctx context.Context, id WorkloadGroupId) (ListByWorkloadGroupCompleteResult, error) { + return c.ListByWorkloadGroupCompleteMatchingPredicate(ctx, id, WorkloadClassifierOperationPredicate{}) +} + +// ListByWorkloadGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkloadClassifiersClient) ListByWorkloadGroupCompleteMatchingPredicate(ctx context.Context, id WorkloadGroupId, predicate WorkloadClassifierOperationPredicate) (result ListByWorkloadGroupCompleteResult, err error) { + items := make([]WorkloadClassifier, 0) + + resp, err := c.ListByWorkloadGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkloadGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifier.go b/resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifier.go new file mode 100644 index 00000000000..6e4288c24f9 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifier.go @@ -0,0 +1,11 @@ +package workloadclassifiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadClassifier struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkloadClassifierProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifierproperties.go b/resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifierproperties.go new file mode 100644 index 00000000000..71f34b8a247 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/model_workloadclassifierproperties.go @@ -0,0 +1,13 @@ +package workloadclassifiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadClassifierProperties struct { + Context *string `json:"context,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Importance *string `json:"importance,omitempty"` + Label *string `json:"label,omitempty"` + MemberName string `json:"memberName"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/workloadclassifiers/predicates.go b/resource-manager/sql/2023-08-01/workloadclassifiers/predicates.go new file mode 100644 index 00000000000..9058806d434 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/predicates.go @@ -0,0 +1,27 @@ +package workloadclassifiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadClassifierOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WorkloadClassifierOperationPredicate) Matches(input WorkloadClassifier) 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/sql/2023-08-01/workloadclassifiers/version.go b/resource-manager/sql/2023-08-01/workloadclassifiers/version.go new file mode 100644 index 00000000000..a65e5d6886f --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadclassifiers/version.go @@ -0,0 +1,10 @@ +package workloadclassifiers + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/workloadclassifiers/2023-08-01" +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/README.md b/resource-manager/sql/2023-08-01/workloadgroups/README.md new file mode 100644 index 00000000000..70d8c31d756 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/README.md @@ -0,0 +1,83 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/workloadgroups` Documentation + +The `workloadgroups` SDK allows for interaction with Azure Resource Manager `sql` (API Version `2023-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01/workloadgroups" +``` + + +### Client Initialization + +```go +client := workloadgroups.NewWorkloadGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkloadGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := workloadgroups.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName") + +payload := workloadgroups.WorkloadGroup{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkloadGroupsClient.Delete` + +```go +ctx := context.TODO() +id := workloadgroups.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkloadGroupsClient.Get` + +```go +ctx := context.TODO() +id := workloadgroups.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName") + +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: `WorkloadGroupsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := commonids.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName") + +// alternatively `client.ListByDatabase(ctx, id)` can be used to do batched pagination +items, err := client.ListByDatabaseComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/sql/2023-08-01/workloadgroups/client.go b/resource-manager/sql/2023-08-01/workloadgroups/client.go new file mode 100644 index 00000000000..6c31a01f6ab --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/client.go @@ -0,0 +1,26 @@ +package workloadgroups + +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 WorkloadGroupsClient struct { + Client *resourcemanager.Client +} + +func NewWorkloadGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkloadGroupsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "workloadgroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkloadGroupsClient: %+v", err) + } + + return &WorkloadGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup.go b/resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup.go new file mode 100644 index 00000000000..507862288f6 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup.go @@ -0,0 +1,148 @@ +package workloadgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkloadGroupId{}) +} + +var _ resourceids.ResourceId = &WorkloadGroupId{} + +// WorkloadGroupId is a struct representing the Resource ID for a Workload Group +type WorkloadGroupId struct { + SubscriptionId string + ResourceGroupName string + ServerName string + DatabaseName string + WorkloadGroupName string +} + +// NewWorkloadGroupID returns a new WorkloadGroupId struct +func NewWorkloadGroupID(subscriptionId string, resourceGroupName string, serverName string, databaseName string, workloadGroupName string) WorkloadGroupId { + return WorkloadGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServerName: serverName, + DatabaseName: databaseName, + WorkloadGroupName: workloadGroupName, + } +} + +// ParseWorkloadGroupID parses 'input' into a WorkloadGroupId +func ParseWorkloadGroupID(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkloadGroupIDInsensitively parses 'input' case-insensitively into a WorkloadGroupId +// note: this method should only be used for API response data and not user input +func ParseWorkloadGroupIDInsensitively(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkloadGroupId) 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.ServerName, ok = input.Parsed["serverName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serverName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + if id.WorkloadGroupName, ok = input.Parsed["workloadGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadGroupName", input) + } + + return nil +} + +// ValidateWorkloadGroupID checks that 'input' can be parsed as a Workload Group ID +func ValidateWorkloadGroupID(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 := ParseWorkloadGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workload Group ID +func (id WorkloadGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/databases/%s/workloadGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServerName, id.DatabaseName, id.WorkloadGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workload Group ID +func (id WorkloadGroupId) 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("staticMicrosoftSql", "Microsoft.Sql", "Microsoft.Sql"), + resourceids.StaticSegment("staticServers", "servers", "servers"), + resourceids.UserSpecifiedSegment("serverName", "serverName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupName"), + } +} + +// String returns a human-readable description of this Workload Group ID +func (id WorkloadGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Server Name: %q", id.ServerName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + fmt.Sprintf("Workload Group Name: %q", id.WorkloadGroupName), + } + return fmt.Sprintf("Workload Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup_test.go b/resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup_test.go new file mode 100644 index 00000000000..c30c1b87e40 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/id_workloadgroup_test.go @@ -0,0 +1,372 @@ +package workloadgroups + +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 = &WorkloadGroupId{} + +func TestNewWorkloadGroupID(t *testing.T) { + id := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName") + + 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.ServerName != "serverName" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } + + if id.WorkloadGroupName != "workloadGroupName" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupName") + } +} + +func TestFormatWorkloadGroupID(t *testing.T) { + actual := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverName", "databaseName", "workloadGroupName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkloadGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + WorkloadGroupName: "workloadGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupID(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestParseWorkloadGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // 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.Sql", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverName", + DatabaseName: "databaseName", + WorkloadGroupName: "workloadGroupName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverName/databases/databaseName/workloadGroups/workloadGroupName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRnAmE", + DatabaseName: "dAtAbAsEnAmE", + WorkloadGroupName: "wOrKlOaDgRoUpNaMe", + }, + }, + { + // 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.sQl/sErVeRs/sErVeRnAmE/dAtAbAsEs/dAtAbAsEnAmE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupIDInsensitively(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.ServerName != v.Expected.ServerName { + t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestSegmentsForWorkloadGroupId(t *testing.T) { + segments := WorkloadGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkloadGroupId 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/sql/2023-08-01/workloadgroups/method_createorupdate.go b/resource-manager/sql/2023-08-01/workloadgroups/method_createorupdate.go new file mode 100644 index 00000000000..5ac6672dc88 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/method_createorupdate.go @@ -0,0 +1,76 @@ +package workloadgroups + +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 *WorkloadGroup +} + +// CreateOrUpdate ... +func (c WorkloadGroupsClient) CreateOrUpdate(ctx context.Context, id WorkloadGroupId, input WorkloadGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 WorkloadGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id WorkloadGroupId, input WorkloadGroup) 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/sql/2023-08-01/workloadgroups/method_delete.go b/resource-manager/sql/2023-08-01/workloadgroups/method_delete.go new file mode 100644 index 00000000000..60cb271a118 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/method_delete.go @@ -0,0 +1,71 @@ +package workloadgroups + +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 WorkloadGroupsClient) Delete(ctx context.Context, id WorkloadGroupId) (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 WorkloadGroupsClient) DeleteThenPoll(ctx context.Context, id WorkloadGroupId) 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/sql/2023-08-01/workloadgroups/method_get.go b/resource-manager/sql/2023-08-01/workloadgroups/method_get.go new file mode 100644 index 00000000000..5b64cb7617a --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/method_get.go @@ -0,0 +1,53 @@ +package workloadgroups + +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 *WorkloadGroup +} + +// Get ... +func (c WorkloadGroupsClient) Get(ctx context.Context, id WorkloadGroupId) (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 WorkloadGroup + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/method_listbydatabase.go b/resource-manager/sql/2023-08-01/workloadgroups/method_listbydatabase.go new file mode 100644 index 00000000000..6d05174887c --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/method_listbydatabase.go @@ -0,0 +1,106 @@ +package workloadgroups + +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 ListByDatabaseOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WorkloadGroup +} + +type ListByDatabaseCompleteResult struct { + LatestHttpResponse *http.Response + Items []WorkloadGroup +} + +type ListByDatabaseCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByDatabaseCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByDatabase ... +func (c WorkloadGroupsClient) ListByDatabase(ctx context.Context, id commonids.SqlDatabaseId) (result ListByDatabaseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByDatabaseCustomPager{}, + Path: fmt.Sprintf("%s/workloadGroups", 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 *[]WorkloadGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDatabaseComplete retrieves all the results into a single object +func (c WorkloadGroupsClient) ListByDatabaseComplete(ctx context.Context, id commonids.SqlDatabaseId) (ListByDatabaseCompleteResult, error) { + return c.ListByDatabaseCompleteMatchingPredicate(ctx, id, WorkloadGroupOperationPredicate{}) +} + +// ListByDatabaseCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkloadGroupsClient) ListByDatabaseCompleteMatchingPredicate(ctx context.Context, id commonids.SqlDatabaseId, predicate WorkloadGroupOperationPredicate) (result ListByDatabaseCompleteResult, err error) { + items := make([]WorkloadGroup, 0) + + resp, err := c.ListByDatabase(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByDatabaseCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroup.go b/resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroup.go new file mode 100644 index 00000000000..59ec248f288 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroup.go @@ -0,0 +1,11 @@ +package workloadgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkloadGroupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroupproperties.go b/resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroupproperties.go new file mode 100644 index 00000000000..b52646aeab0 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/model_workloadgroupproperties.go @@ -0,0 +1,13 @@ +package workloadgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadGroupProperties struct { + Importance *string `json:"importance,omitempty"` + MaxResourcePercent int64 `json:"maxResourcePercent"` + MaxResourcePercentPerRequest *float64 `json:"maxResourcePercentPerRequest,omitempty"` + MinResourcePercent int64 `json:"minResourcePercent"` + MinResourcePercentPerRequest float64 `json:"minResourcePercentPerRequest"` + QueryExecutionTimeout *int64 `json:"queryExecutionTimeout,omitempty"` +} diff --git a/resource-manager/sql/2023-08-01/workloadgroups/predicates.go b/resource-manager/sql/2023-08-01/workloadgroups/predicates.go new file mode 100644 index 00000000000..3fa552a0da7 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/predicates.go @@ -0,0 +1,27 @@ +package workloadgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WorkloadGroupOperationPredicate) Matches(input WorkloadGroup) 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/sql/2023-08-01/workloadgroups/version.go b/resource-manager/sql/2023-08-01/workloadgroups/version.go new file mode 100644 index 00000000000..45fdb35e492 --- /dev/null +++ b/resource-manager/sql/2023-08-01/workloadgroups/version.go @@ -0,0 +1,10 @@ +package workloadgroups + +// 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" + +func userAgent() string { + return "hashicorp/go-azure-sdk/workloadgroups/2023-08-01" +} diff --git a/resource-manager/storage/2023-05-01/storagetaskassignments/constants.go b/resource-manager/storage/2023-05-01/storagetaskassignments/constants.go index b8180ddef9d..42b5343a7be 100644 --- a/resource-manager/storage/2023-05-01/storagetaskassignments/constants.go +++ b/resource-manager/storage/2023-05-01/storagetaskassignments/constants.go @@ -50,6 +50,7 @@ func parseIntervalUnit(input string) (*IntervalUnit, error) { type ProvisioningState string const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" ProvisioningStateCanceled ProvisioningState = "Canceled" ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" @@ -61,6 +62,7 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ + string(ProvisioningStateAccepted), string(ProvisioningStateCanceled), string(ProvisioningStateCreating), string(ProvisioningStateDeleting), @@ -86,6 +88,7 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, "canceled": ProvisioningStateCanceled, "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, diff --git a/resource-manager/storage/2024-01-01/storagetaskassignments/constants.go b/resource-manager/storage/2024-01-01/storagetaskassignments/constants.go index b8180ddef9d..42b5343a7be 100644 --- a/resource-manager/storage/2024-01-01/storagetaskassignments/constants.go +++ b/resource-manager/storage/2024-01-01/storagetaskassignments/constants.go @@ -50,6 +50,7 @@ func parseIntervalUnit(input string) (*IntervalUnit, error) { type ProvisioningState string const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" ProvisioningStateCanceled ProvisioningState = "Canceled" ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" @@ -61,6 +62,7 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ + string(ProvisioningStateAccepted), string(ProvisioningStateCanceled), string(ProvisioningStateCreating), string(ProvisioningStateDeleting), @@ -86,6 +88,7 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, "canceled": ProvisioningStateCanceled, "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting,